]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/ResetSystemLib: add driver for microvm
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 8 Sep 2021 09:01:14 +0000 (11:01 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 5 Oct 2021 10:55:39 +0000 (10:55 +0000)
Uses the generic event device to reset and poweroff.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3599
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
OvmfPkg/Include/IndustryStandard/Microvm.h
OvmfPkg/Include/OvmfPlatforms.h
OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf [new file with mode: 0644]
OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c [new file with mode: 0644]
OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf [new file with mode: 0644]
OvmfPkg/Library/ResetSystemLib/ResetSystemLibMicrovm.c [new file with mode: 0644]
OvmfPkg/Microvm/MicrovmX64.dsc
OvmfPkg/PlatformPei/Platform.c

index c56547c4f2a4b4733982ec9b744cae7e4d3863a2..ae0c2e53117b32bf86c9e84b6d4c881fb2e21698 100644 (file)
@@ -9,4 +9,11 @@
 \r
 #define MICROVM_PSEUDO_DEVICE_ID 0xfff1\r
 \r
+/* generic event device */\r
+#define MICROVM_GED_MMIO_BASE         0xfea00000\r
+#define MICROVM_GED_MMIO_BASE_REGS    (MICROVM_GED_MMIO_BASE + 0x200)\r
+#define MICROVM_ACPI_GED_REG_SLEEP_CTL     0x00\r
+#define MICROVM_ACPI_GED_REG_RESET         0x02\r
+#define MICROVM_ACPI_GED_RESET_VALUE       0x42\r
+\r
 #endif // __MICROVM_H__\r
index 77dd818e300229a4d2f3476ae61ffcc055d49f88..3b85593b70634dd57409f2912298080923bc76e7 100644 (file)
@@ -15,6 +15,7 @@
 #include <IndustryStandard/Q35MchIch9.h>\r
 #include <IndustryStandard/I440FxPiix4.h>\r
 #include <IndustryStandard/Bhyve.h>\r
+#include <IndustryStandard/Microvm.h>\r
 \r
 //\r
 // OVMF Host Bridge DID Address\r
diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf
new file mode 100644 (file)
index 0000000..564b1d3
--- /dev/null
@@ -0,0 +1,37 @@
+## @file\r
+#  DXE library instance for ResetSystem library class for OVMF\r
+#\r
+#  Copyright (C) 2020, Red Hat, Inc.\r
+#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 1.29\r
+  BASE_NAME                      = ResetSystemLibMicrovm\r
+  FILE_GUID                      = 7cd630bb-f581-4d1a-97ca-9dbc900e26a4\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ResetSystemLib|SEC PEI_CORE PEIM DXE_CORE\r
+\r
+#\r
+# The following information is for reference only and not required by the build\r
+# tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  ResetSystemLibMicrovm.c\r
+\r
+[Packages]\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  IoLib\r
+  TimerLib\r
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c
new file mode 100644 (file)
index 0000000..0de8b39
--- /dev/null
@@ -0,0 +1,49 @@
+/** @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
+#include <PiDxe.h>\r
+\r
+#include <Library/BaseLib.h>        // CpuDeadLoop()\r
+#include <Library/DebugLib.h>       // ASSERT()\r
+#include <Library/DxeServicesTableLib.h>\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
+EFI_STATUS\r
+EFIAPI\r
+DxeResetSystemLibMicrovmConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  UINTN                            Address = MICROVM_GED_MMIO_BASE;\r
+  EFI_STATUS                       Status;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  Descriptor;\r
+\r
+  DEBUG ((DEBUG_INFO, "%a: start\n", __FUNCTION__));\r
+\r
+  Status = gDS->GetMemorySpaceDescriptor (Address, &Descriptor);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_INFO, "%a: GetMemorySpaceDescriptor failed\n", __FUNCTION__));\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (Address, SIZE_4KB,\r
+                                          Descriptor.Attributes | EFI_MEMORY_RUNTIME);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_INFO, "%a: SetMemorySpaceAttributes failed\n", __FUNCTION__));\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  DEBUG ((DEBUG_INFO, "%a: done\n", __FUNCTION__));\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
new file mode 100644 (file)
index 0000000..ac9c259
--- /dev/null
@@ -0,0 +1,40 @@
+## @file\r
+#  DXE library instance for ResetSystem library class for OVMF\r
+#\r
+#  Copyright (C) 2020, Red Hat, Inc.\r
+#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 1.29\r
+  BASE_NAME                      = ResetSystemLibMicrovm\r
+  FILE_GUID                      = 3d6faf60-804a-4ca9-a36a-1a92416919d0\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ResetSystemLib|DXE_DRIVER DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION\r
+  CONSTRUCTOR                    = DxeResetSystemLibMicrovmConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build\r
+# tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  ResetSystemLibMicrovm.c\r
+  DxeResetSystemLibMicrovm.c\r
+\r
+[Packages]\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  DxeServicesTableLib\r
+  IoLib\r
+  TimerLib\r
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
index 019b50de7d8f267d66072973c68698f139d16604..3cc951f0d9859d68aa98a9b421cbbbd697dfecc6 100644 (file)
 [LibraryClasses]\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
   TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf\r
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf\r
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
 \r
 [LibraryClasses.common.UEFI_DRIVER]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
 \r
 [LibraryClasses.common.UEFI_APPLICATION]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
 \r
 [LibraryClasses.common.DXE_SMM_DRIVER]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf\r
   MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf\r
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
 \r
 [LibraryClasses.common.SMM_CORE]\r
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
-  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf\r
+  ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf\r
   SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf\r
   MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf\r
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r
index aeb39595aa28653843e7225fa955fa3e54891bb8..df2d9ad015aae7a01afdb55db816c29a889013c3 100644 (file)
@@ -161,6 +161,7 @@ MemMapInitialization (
   AddIoMemoryRangeHob (0x0A0000, BASE_1MB);\r
 \r
   if (mHostBridgeDevId == 0xffff /* microvm */) {\r
+    AddIoMemoryBaseSizeHob (MICROVM_GED_MMIO_BASE, SIZE_4KB);\r
     AddIoMemoryBaseSizeHob (0xFEC00000, SIZE_4KB); /* ioapic #1 */\r
     AddIoMemoryBaseSizeHob (0xFEC10000, SIZE_4KB); /* ioapic #2 */\r
     return;\r