1 | /** @file
|
---|
2 | DXE Reset System Library Shutdown API implementation for OVMF.
|
---|
3 |
|
---|
4 | Copyright (C) 2020, Red Hat, Inc.
|
---|
5 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include <Base.h> // BIT13
|
---|
10 |
|
---|
11 | #include <IndustryStandard/Xen/sched.h>
|
---|
12 | #include <Library/BaseLib.h> // CpuDeadLoop()
|
---|
13 | #include <Library/DebugLib.h> // ASSERT()
|
---|
14 | #include <Library/IoLib.h> // IoOr16()
|
---|
15 | #include <Library/PcdLib.h> // PcdGet16()
|
---|
16 | #include <Library/ResetSystemLib.h> // ResetShutdown()
|
---|
17 | #include <Library/XenHypercallLib.h>
|
---|
18 | #include <OvmfPlatforms.h> // PIIX4_PMBA_VALUE
|
---|
19 |
|
---|
20 | STATIC UINT16 mAcpiPmBaseAddress;
|
---|
21 |
|
---|
22 | EFI_STATUS
|
---|
23 | EFIAPI
|
---|
24 | DxeResetInit (
|
---|
25 | IN EFI_HANDLE ImageHandle,
|
---|
26 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
27 | )
|
---|
28 | {
|
---|
29 | UINT16 HostBridgeDevId;
|
---|
30 |
|
---|
31 | HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
|
---|
32 | switch (HostBridgeDevId) {
|
---|
33 | case INTEL_82441_DEVICE_ID:
|
---|
34 | mAcpiPmBaseAddress = PIIX4_PMBA_VALUE;
|
---|
35 | break;
|
---|
36 | case INTEL_Q35_MCH_DEVICE_ID:
|
---|
37 | mAcpiPmBaseAddress = ICH9_PMBASE_VALUE;
|
---|
38 | break;
|
---|
39 | default:
|
---|
40 | //
|
---|
41 | // Fallback to using hypercall.
|
---|
42 | // Necessary for PVH guest, but should work for HVM guest.
|
---|
43 | //
|
---|
44 | mAcpiPmBaseAddress = 0xffff;
|
---|
45 | break;
|
---|
46 | }
|
---|
47 |
|
---|
48 | return EFI_SUCCESS;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | Calling this function causes the system to enter a power state equivalent
|
---|
53 | to the ACPI G2/S5 or G3 states.
|
---|
54 |
|
---|
55 | System shutdown should not return, if it returns, it means the system does
|
---|
56 | not support shut down reset.
|
---|
57 | **/
|
---|
58 | VOID
|
---|
59 | EFIAPI
|
---|
60 | ResetShutdown (
|
---|
61 | VOID
|
---|
62 | )
|
---|
63 | {
|
---|
64 | if (mAcpiPmBaseAddress != 0xffff) {
|
---|
65 | IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0);
|
---|
66 | IoOr16 (mAcpiPmBaseAddress + 4, BIT13);
|
---|
67 | } else {
|
---|
68 | INTN ReturnCode;
|
---|
69 | XEN_SCHED_SHUTDOWN ShutdownOp = {
|
---|
70 | .Reason = XEN_SHED_SHUTDOWN_POWEROFF,
|
---|
71 | };
|
---|
72 | ReturnCode = XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, &ShutdownOp);
|
---|
73 | ASSERT (ReturnCode == 0);
|
---|
74 | }
|
---|
75 |
|
---|
76 | CpuDeadLoop ();
|
---|
77 | }
|
---|