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>
\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
#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
--- /dev/null
+## @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
--- /dev/null
+/** @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
--- /dev/null
+## @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
--- /dev/null
+/** @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
[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
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