]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
OvmfPkg: remove EnterS3WithImmediateWake () from ResetSystemLib
[mirror_edk2.git] / OvmfPkg / Library / ResetSystemLib / ResetSystemLib.c
1 /** @file
2 Reset System Library functions for OVMF
3
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Base.h>
10
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/IoLib.h>
14 #include <Library/PciLib.h>
15 #include <Library/TimerLib.h>
16 #include <OvmfPlatforms.h>
17
18 VOID
19 AcpiPmControl (
20 UINTN SuspendType
21 )
22 {
23 UINT16 AcpiPmBaseAddress;
24 UINT16 HostBridgeDevId;
25
26 ASSERT (SuspendType < 6);
27
28 AcpiPmBaseAddress = 0;
29 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
30 switch (HostBridgeDevId) {
31 case INTEL_82441_DEVICE_ID:
32 AcpiPmBaseAddress = PIIX4_PMBA_VALUE;
33 break;
34 case INTEL_Q35_MCH_DEVICE_ID:
35 AcpiPmBaseAddress = ICH9_PMBASE_VALUE;
36 break;
37 default:
38 ASSERT (FALSE);
39 CpuDeadLoop ();
40 }
41
42 IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, (UINT16) SuspendType);
43 IoOr16 (AcpiPmBaseAddress + 4, BIT13);
44 CpuDeadLoop ();
45 }
46
47 /**
48 Calling this function causes a system-wide reset. This sets
49 all circuitry within the system to its initial state. This type of reset
50 is asynchronous to system operation and operates without regard to
51 cycle boundaries.
52
53 System reset should not return, if it returns, it means the system does
54 not support cold reset.
55 **/
56 VOID
57 EFIAPI
58 ResetCold (
59 VOID
60 )
61 {
62 IoWrite8 (0xCF9, BIT2 | BIT1); // 1st choice: PIIX3 RCR, RCPU|SRST
63 MicroSecondDelay (50);
64
65 IoWrite8 (0x64, 0xfe); // 2nd choice: keyboard controller
66 CpuDeadLoop ();
67 }
68
69 /**
70 Calling this function causes a system-wide initialization. The processors
71 are set to their initial state, and pending cycles are not corrupted.
72
73 System reset should not return, if it returns, it means the system does
74 not support warm reset.
75 **/
76 VOID
77 EFIAPI
78 ResetWarm (
79 VOID
80 )
81 {
82 IoWrite8 (0x64, 0xfe);
83 CpuDeadLoop ();
84 }
85
86 /**
87 Calling this function causes the system to enter a power state equivalent
88 to the ACPI G2/S5 or G3 states.
89
90 System shutdown should not return, if it returns, it means the system does
91 not support shut down reset.
92 **/
93 VOID
94 EFIAPI
95 ResetShutdown (
96 VOID
97 )
98 {
99 AcpiPmControl (0);
100 ASSERT (FALSE);
101 }
102
103
104 /**
105 This function causes a systemwide reset. The exact type of the reset is
106 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
107 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
108 the platform must pick a supported reset type to perform.The platform may
109 optionally log the parameters from any non-normal reset that occurs.
110
111 @param[in] DataSize The size, in bytes, of ResetData.
112 @param[in] ResetData The data buffer starts with a Null-terminated string,
113 followed by the EFI_GUID.
114 **/
115 VOID
116 EFIAPI
117 ResetPlatformSpecific (
118 IN UINTN DataSize,
119 IN VOID *ResetData
120 )
121 {
122 ResetCold ();
123 }
124
125 /**
126 The ResetSystem function resets the entire platform.
127
128 @param[in] ResetType The type of reset to perform.
129 @param[in] ResetStatus The status code for the reset.
130 @param[in] DataSize The size, in bytes, of ResetData.
131 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
132 the data buffer starts with a Null-terminated string, optionally
133 followed by additional binary data. The string is a description
134 that the caller may use to further indicate the reason for the
135 system reset.
136 **/
137 VOID
138 EFIAPI
139 ResetSystem (
140 IN EFI_RESET_TYPE ResetType,
141 IN EFI_STATUS ResetStatus,
142 IN UINTN DataSize,
143 IN VOID *ResetData OPTIONAL
144 )
145 {
146 switch (ResetType) {
147 case EfiResetWarm:
148 ResetWarm ();
149 break;
150
151 case EfiResetCold:
152 ResetCold ();
153 break;
154
155 case EfiResetShutdown:
156 ResetShutdown ();
157 return;
158
159 case EfiResetPlatformSpecific:
160 ResetPlatformSpecific (DataSize, ResetData);
161 return;
162
163 default:
164 return;
165 }
166 }