]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/ResetSystemLib/ResetSystemLibMicrovm.c
OvmfPkg/ResetSystemLib: add driver for microvm
[mirror_edk2.git] / OvmfPkg / Library / ResetSystemLib / ResetSystemLibMicrovm.c
diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLibMicrovm.c b/OvmfPkg/Library/ResetSystemLib/ResetSystemLibMicrovm.c
new file mode 100644 (file)
index 0000000..5c714cf
--- /dev/null
@@ -0,0 +1,89 @@
+/** @file\r
+  Reset System Library functions for OVMF\r
+\r
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Base.h>                   // BIT1\r
+\r
+#include <Library/BaseLib.h>        // CpuDeadLoop()\r
+#include <Library/DebugLib.h>       // ASSERT()\r
+#include <Library/IoLib.h>          // IoWrite8()\r
+#include <Library/ResetSystemLib.h> // ResetCold()\r
+#include <Library/TimerLib.h>       // MicroSecondDelay()\r
+#include <Library/UefiRuntimeLib.h> // EfiGoneVirtual()\r
+#include <OvmfPlatforms.h>          // PIIX4_PMBA_VALUE\r
+\r
+static UINTN MicrovmGedBase (VOID)\r
+{\r
+  VOID *Address = (VOID*) MICROVM_GED_MMIO_BASE_REGS;\r
+\r
+  if (EfiGoneVirtual ()) {\r
+    EfiConvertPointer (0, &Address);\r
+    DEBUG ((DEBUG_INFO, "%a: virtual -> 0x%x\n", __FUNCTION__, Address));\r
+  } else {\r
+    DEBUG ((DEBUG_INFO, "%a: physical -> 0x%x\n", __FUNCTION__, Address));\r
+  }\r
+\r
+  return (UINTN) Address;\r
+}\r
+\r
+static VOID MicrovmReset (VOID)\r
+{\r
+  UINTN Address = MicrovmGedBase();\r
+\r
+  DEBUG ((DEBUG_INFO, "%a: microvm reset via ged\n", __FUNCTION__));\r
+  MmioWrite8 (Address + MICROVM_ACPI_GED_REG_RESET,\r
+              MICROVM_ACPI_GED_RESET_VALUE);\r
+  CpuDeadLoop ();\r
+}\r
+\r
+static VOID MicrovmShutdown (VOID)\r
+{\r
+  UINTN Address = MicrovmGedBase();\r
+\r
+  DEBUG ((DEBUG_INFO, "%a: microvm poweroff via ged\n", __FUNCTION__));\r
+  MmioWrite8 (Address + MICROVM_ACPI_GED_REG_SLEEP_CTL,\r
+              (1 << 5) /* enable bit */ |\r
+              (5 << 2) /* typ == S5  */);\r
+  CpuDeadLoop ();\r
+}\r
+\r
+VOID EFIAPI ResetCold (VOID)\r
+{\r
+  MicrovmReset();\r
+}\r
+\r
+VOID EFIAPI ResetWarm (VOID)\r
+{\r
+  MicrovmReset();\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ResetPlatformSpecific (\r
+  IN UINTN   DataSize,\r
+  IN VOID    *ResetData\r
+  )\r
+{\r
+  MicrovmReset();\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ResetSystem (\r
+  IN EFI_RESET_TYPE               ResetType,\r
+  IN EFI_STATUS                   ResetStatus,\r
+  IN UINTN                        DataSize,\r
+  IN VOID                         *ResetData OPTIONAL\r
+  )\r
+{\r
+  MicrovmReset();\r
+}\r
+\r
+VOID EFIAPI ResetShutdown (VOID)\r
+{\r
+  MicrovmShutdown();\r
+}\r