--- /dev/null
+/** @file\r
+ Base Reset System Library Shutdown API implementation for OVMF.\r
+\r
+ Copyright (C) 2020, Red Hat, Inc.\r
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2022, Citrix Systems, Inc.\r
+\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Base.h> // BIT13\r
+\r
+#include <Library/BaseLib.h> // CpuDeadLoop()\r
+#include <Library/DebugLib.h> // ASSERT()\r
+#include <Library/IoLib.h> // IoOr16()\r
+#include <Library/PciLib.h> // PciRead16()\r
+#include <Library/ResetSystemLib.h> // ResetShutdown()\r
+#include <Library/XenHypercallLib.h>\r
+#include <OvmfPlatforms.h> // OVMF_HOSTBRIDGE_DID\r
+\r
+/**\r
+ Calling this function causes the system to enter a power state equivalent\r
+ to the ACPI G2/S5 or G3 states.\r
+\r
+ System shutdown should not return, if it returns, it means the system does\r
+ not support shut down reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetShutdown (\r
+ VOID\r
+ )\r
+{\r
+ UINT16 AcpiPmBaseAddress;\r
+ UINT16 HostBridgeDevId;\r
+\r
+ AcpiPmBaseAddress = 0;\r
+ HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
+ switch (HostBridgeDevId) {\r
+ case INTEL_82441_DEVICE_ID:\r
+ AcpiPmBaseAddress = PIIX4_PMBA_VALUE;\r
+ break;\r
+ case INTEL_Q35_MCH_DEVICE_ID:\r
+ AcpiPmBaseAddress = ICH9_PMBASE_VALUE;\r
+ break;\r
+ default:\r
+ {\r
+ //\r
+ // Fallback to using hypercall.\r
+ // Necessary for PVH guest, but should work for HVM guest.\r
+ //\r
+ INTN ReturnCode;\r
+ XEN_SCHED_SHUTDOWN ShutdownOp = {\r
+ .Reason = XEN_SHED_SHUTDOWN_POWEROFF,\r
+ };\r
+ ReturnCode = XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, ShutdownOp);\r
+ ASSERT (ReturnCode == 0);\r
+ CpuDeadLoop ();\r
+ }\r
+ }\r
+\r
+ IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, 0);\r
+ IoOr16 (AcpiPmBaseAddress + 4, BIT13);\r
+ CpuDeadLoop ();\r
+}\r
--- /dev/null
+## @file\r
+# Base library instance for ResetSystem library class for Xen\r
+#\r
+# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2022, Citrix Systems, Inc.\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = BaseResetSystemLib\r
+ FILE_GUID = 9ef32aa1-9e82-4fb1-9c49-0eff538601f8\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
+ BaseResetShutdownXen.c\r
+ ResetSystemLib.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
+ PciLib\r
+ TimerLib\r
+ XenHypercallLib\r
--- /dev/null
+/** @file\r
+ DXE Reset System Library Shutdown API implementation for OVMF.\r
+\r
+ Copyright (C) 2020, Red Hat, Inc.\r
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Base.h> // BIT13\r
+\r
+#include <IndustryStandard/Xen/sched.h>\r
+#include <Library/BaseLib.h> // CpuDeadLoop()\r
+#include <Library/DebugLib.h> // ASSERT()\r
+#include <Library/IoLib.h> // IoOr16()\r
+#include <Library/PcdLib.h> // PcdGet16()\r
+#include <Library/ResetSystemLib.h> // ResetShutdown()\r
+#include <Library/XenHypercallLib.h>\r
+#include <OvmfPlatforms.h> // PIIX4_PMBA_VALUE\r
+\r
+STATIC UINT16 mAcpiPmBaseAddress;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DxeResetInit (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ UINT16 HostBridgeDevId;\r
+\r
+ HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);\r
+ switch (HostBridgeDevId) {\r
+ case INTEL_82441_DEVICE_ID:\r
+ mAcpiPmBaseAddress = PIIX4_PMBA_VALUE;\r
+ break;\r
+ case INTEL_Q35_MCH_DEVICE_ID:\r
+ mAcpiPmBaseAddress = ICH9_PMBASE_VALUE;\r
+ break;\r
+ default:\r
+ //\r
+ // Fallback to using hypercall.\r
+ // Necessary for PVH guest, but should work for HVM guest.\r
+ //\r
+ mAcpiPmBaseAddress = 0xffff;\r
+ break;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Calling this function causes the system to enter a power state equivalent\r
+ to the ACPI G2/S5 or G3 states.\r
+\r
+ System shutdown should not return, if it returns, it means the system does\r
+ not support shut down reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetShutdown (\r
+ VOID\r
+ )\r
+{\r
+ if (mAcpiPmBaseAddress != 0xffff) {\r
+ IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0);\r
+ IoOr16 (mAcpiPmBaseAddress + 4, BIT13);\r
+ } else {\r
+ INTN ReturnCode;\r
+ XEN_SCHED_SHUTDOWN ShutdownOp = {\r
+ .Reason = XEN_SHED_SHUTDOWN_POWEROFF,\r
+ };\r
+ ReturnCode = XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, &ShutdownOp);\r
+ ASSERT (ReturnCode == 0);\r
+ }\r
+\r
+ CpuDeadLoop ();\r
+}\r
--- /dev/null
+## @file\r
+# DXE library instance for ResetSystem library class for Xen\r
+#\r
+# Copyright (C) 2020, Red Hat, Inc.\r
+# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2022, Citrix Systems, Inc.\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 1.29\r
+ BASE_NAME = DxeResetSystemLibXen\r
+ FILE_GUID = a5ac25e6-4dc5-4fd9-92cd-74e46bd2e72a\r
+ MODULE_TYPE = DXE_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 = DxeResetInit\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
+ DxeResetShutdownXen.c\r
+ ResetSystemLib.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
+ PcdLib\r
+ TimerLib\r
+ XenHypercallLib\r
+\r
+[Pcd]\r
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES\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/BaseResetSystemLibXen.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/DxeResetSystemLibXen.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/DxeResetSystemLibXen.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/DxeResetSystemLibXen.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/DxeResetSystemLibXen.inf\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf\r