summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/Library/ResetSystemLib/ResetShutdown.c
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2020-04-17 17:37:49 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-04-22 19:42:32 +0000
commitb6d542e927a3fa0ff4fd7278917f25b0494c07ba (patch)
tree3ca51f9c64993194f664e13d5b3a2e58604b4beb /OvmfPkg/Library/ResetSystemLib/ResetShutdown.c
parent92958abf7a0c87c6be3854bc1a5df2dfa35b876c (diff)
downloadedk2-b6d542e927a3fa0ff4fd7278917f25b0494c07ba.tar.gz
edk2-b6d542e927a3fa0ff4fd7278917f25b0494c07ba.tar.bz2
edk2-b6d542e927a3fa0ff4fd7278917f25b0494c07ba.zip
OvmfPkg/ResetSystemLib: factor out ResetShutdown()
Move the ResetShutdown() definition to its own file. This will help us introduce: - a new library instance that is not broken in runtime modules (the current library instance is broken in runtime modules), - another new library instance for bhyve support. While at it, squash AcpiPmControl() into ResetShutdown(), open-coding SuspendType=0. This is justified because we've had no other callers for AcpiPmControl() since commit 2d9950a2bff8 ("OvmfPkg: remove EnterS3WithImmediateWake () from ResetSystemLib", 2020-01-10). Tested with the "reset -s" UEFI shell command, on both i440fx and q35. Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Cc: Rebecca Cran <rebecca@bsdio.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2675 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20200417153751.7110-5-lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com> Reviewed-by: Rebecca Cran <rebecca@bsdio.com>
Diffstat (limited to 'OvmfPkg/Library/ResetSystemLib/ResetShutdown.c')
-rw-r--r--OvmfPkg/Library/ResetSystemLib/ResetShutdown.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/OvmfPkg/Library/ResetSystemLib/ResetShutdown.c b/OvmfPkg/Library/ResetSystemLib/ResetShutdown.c
new file mode 100644
index 0000000000..971d94fa57
--- /dev/null
+++ b/OvmfPkg/Library/ResetSystemLib/ResetShutdown.c
@@ -0,0 +1,51 @@
+/** @file
+ Reset System Library Shutdown API implementation for OVMF.
+
+ Copyright (C) 2020, Red Hat, Inc.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h> // BIT13
+
+#include <Library/BaseLib.h> // CpuDeadLoop()
+#include <Library/DebugLib.h> // ASSERT()
+#include <Library/IoLib.h> // IoOr16()
+#include <Library/PciLib.h> // PciRead16()
+#include <Library/ResetSystemLib.h> // ResetShutdown()
+#include <OvmfPlatforms.h> // OVMF_HOSTBRIDGE_DID
+
+/**
+ Calling this function causes the system to enter a power state equivalent
+ to the ACPI G2/S5 or G3 states.
+
+ System shutdown should not return, if it returns, it means the system does
+ not support shut down reset.
+**/
+VOID
+EFIAPI
+ResetShutdown (
+ VOID
+ )
+{
+ UINT16 AcpiPmBaseAddress;
+ UINT16 HostBridgeDevId;
+
+ AcpiPmBaseAddress = 0;
+ HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
+ switch (HostBridgeDevId) {
+ case INTEL_82441_DEVICE_ID:
+ AcpiPmBaseAddress = PIIX4_PMBA_VALUE;
+ break;
+ case INTEL_Q35_MCH_DEVICE_ID:
+ AcpiPmBaseAddress = ICH9_PMBASE_VALUE;
+ break;
+ default:
+ ASSERT (FALSE);
+ CpuDeadLoop ();
+ }
+
+ IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, 0);
+ IoOr16 (AcpiPmBaseAddress + 4, BIT13);
+ CpuDeadLoop ();
+}