From: Anthony PERARD <anthony.per...@citrix.com> When booting OvmfXen, the ACPI interface for shutdown/reset might not be available, instead use the hypercall interface.
While it's probably possible to use the hypercall in all cases, we keep using the same interface while it still possible. That is ACPI on HVM guest, and fallback to hypercall on PVH guest. Signed-off-by: Anthony PERARD <anthony.per...@citrix.com> --- OvmfPkg/OvmfXen.dsc | 10 +++---- ...ystemLib.inf => BaseResetSystemLibXen.inf} | 9 ++++--- ...SystemLib.inf => DxeResetSystemLibXen.inf} | 11 +++++--- ...ResetShutdown.c => BaseResetShutdownXen.c} | 19 +++++++++++--- ...eResetShutdown.c => DxeResetShutdownXen.c} | 26 ++++++++++++------- 5 files changed, 49 insertions(+), 26 deletions(-) copy OvmfPkg/Library/ResetSystemLib/{BaseResetSystemLib.inf => BaseResetSystemLibXen.inf} (73%) copy OvmfPkg/Library/ResetSystemLib/{DxeResetSystemLib.inf => DxeResetSystemLibXen.inf} (73%) copy OvmfPkg/Library/ResetSystemLib/{BaseResetShutdown.c => BaseResetShutdownXen.c} (72%) copy OvmfPkg/Library/ResetSystemLib/{DxeResetShutdown.c => DxeResetShutdownXen.c} (72%) diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 8df173a0ee84..18f7c0d76643 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -118,7 +118,7 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf @@ -302,7 +302,7 @@ [LibraryClasses.common.DXE_CORE] [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf @@ -316,7 +316,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf @@ -326,7 +326,7 @@ [LibraryClasses.common.UEFI_DRIVER] [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf @@ -345,7 +345,7 @@ [LibraryClasses.common.DXE_DRIVER] [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf similarity index 73% copy from OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf copy to OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf index 35d317f1e0b3..8d75dd565365 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf @@ -1,7 +1,9 @@ ## @file -# Base library instance for ResetSystem library class for OVMF +# Base library instance for ResetSystem library class for Xen # # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2022, Citrix Systems, Inc. +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -9,7 +11,7 @@ [Defines] INF_VERSION = 0x00010005 BASE_NAME = BaseResetSystemLib - FILE_GUID = 66564872-21d4-4d2a-a68b-1e844f980820 + FILE_GUID = 9ef32aa1-9e82-4fb1-9c49-0eff538601f8 MODULE_TYPE = BASE VERSION_STRING = 1.0 LIBRARY_CLASS = ResetSystemLib|SEC PEI_CORE PEIM DXE_CORE @@ -22,7 +24,7 @@ [Defines] # [Sources] - BaseResetShutdown.c + BaseResetShutdownXen.c ResetSystemLib.c [Packages] @@ -36,3 +38,4 @@ [LibraryClasses] IoLib PciLib TimerLib + XenHypercallLib diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf similarity index 73% copy from OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf copy to OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf index a9b4ce90000a..ccee69e6e1fa 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf @@ -1,16 +1,18 @@ ## @file -# DXE library instance for ResetSystem library class for OVMF +# DXE library instance for ResetSystem library class for Xen # # Copyright (C) 2020, Red Hat, Inc. # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2022, Citrix Systems, Inc. +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## [Defines] INF_VERSION = 1.29 - BASE_NAME = DxeResetSystemLib - FILE_GUID = bc7835ea-4094-41fe-b770-bad9e6c479b2 + BASE_NAME = DxeResetSystemLibXen + FILE_GUID = a5ac25e6-4dc5-4fd9-92cd-74e46bd2e72a MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 LIBRARY_CLASS = ResetSystemLib|DXE_DRIVER DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION @@ -24,7 +26,7 @@ [Defines] # [Sources] - DxeResetShutdown.c + DxeResetShutdownXen.c ResetSystemLib.c [Packages] @@ -38,6 +40,7 @@ [LibraryClasses] IoLib PcdLib TimerLib + XenHypercallLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c b/OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c similarity index 72% copy from OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c copy to OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c index c21d3c89cf95..f45d9125feb4 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c @@ -3,6 +3,8 @@ Copyright (C) 2020, Red Hat, Inc. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2022, Citrix Systems, Inc. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -13,6 +15,7 @@ #include <Library/IoLib.h> // IoOr16() #include <Library/PciLib.h> // PciRead16() #include <Library/ResetSystemLib.h> // ResetShutdown() +#include <Library/XenHypercallLib.h> #include <OvmfPlatforms.h> // OVMF_HOSTBRIDGE_DID /** @@ -40,12 +43,20 @@ ResetShutdown ( case INTEL_Q35_MCH_DEVICE_ID: AcpiPmBaseAddress = ICH9_PMBASE_VALUE; break; - case CLOUDHV_DEVICE_ID: - IoWrite8 (CLOUDHV_ACPI_SHUTDOWN_IO_ADDRESS, 5 << 2 | 1 << 5); - CpuDeadLoop (); default: - ASSERT (FALSE); + { + // + // Fallback to using hypercall. + // Necessary for PVH guest, but should work for HVM guest. + // + INTN ReturnCode; + XEN_SCHED_SHUTDOWN ShutdownOp = { + .Reason = XEN_SHED_SHUTDOWN_POWEROFF, + }; + ReturnCode = XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, ShutdownOp); + ASSERT (ReturnCode == 0); CpuDeadLoop (); + } } IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, 0); diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c b/OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c similarity index 72% copy from OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c copy to OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c index 31f01b82e4ee..f7f32765cfc9 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c @@ -8,15 +8,16 @@ #include <Base.h> // BIT13 +#include <IndustryStandard/Xen/sched.h> #include <Library/BaseLib.h> // CpuDeadLoop() #include <Library/DebugLib.h> // ASSERT() #include <Library/IoLib.h> // IoOr16() #include <Library/PcdLib.h> // PcdGet16() #include <Library/ResetSystemLib.h> // ResetShutdown() +#include <Library/XenHypercallLib.h> #include <OvmfPlatforms.h> // PIIX4_PMBA_VALUE STATIC UINT16 mAcpiPmBaseAddress; -STATIC UINT16 mAcpiHwReducedSleepCtl; EFI_STATUS EFIAPI @@ -35,13 +36,13 @@ DxeResetInit ( case INTEL_Q35_MCH_DEVICE_ID: mAcpiPmBaseAddress = ICH9_PMBASE_VALUE; break; - case CLOUDHV_DEVICE_ID: - mAcpiHwReducedSleepCtl = CLOUDHV_ACPI_SHUTDOWN_IO_ADDRESS; - break; default: - ASSERT (FALSE); - CpuDeadLoop (); - return EFI_UNSUPPORTED; + // + // Fallback to using hypercall. + // Necessary for PVH guest, but should work for HVM guest. + // + mAcpiPmBaseAddress = 0xffff; + break; } return EFI_SUCCESS; @@ -60,11 +61,16 @@ ResetShutdown ( VOID ) { - if (mAcpiHwReducedSleepCtl) { - IoWrite8 (mAcpiHwReducedSleepCtl, 5 << 2 | 1 << 5); - } else { + if (mAcpiPmBaseAddress != 0xffff) { IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0); IoOr16 (mAcpiPmBaseAddress + 4, BIT13); + } else { + INTN ReturnCode; + XEN_SCHED_SHUTDOWN ShutdownOp = { + .Reason = XEN_SHED_SHUTDOWN_POWEROFF, + }; + ReturnCode = XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, &ShutdownOp); + ASSERT (ReturnCode == 0); } CpuDeadLoop (); -- Anthony PERARD -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96305): https://edk2.groups.io/g/devel/message/96305 Mute This Topic: https://groups.io/mt/94960819/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-