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