]> git.proxmox.com Git - mirror_edk2.git/blob - CorebootPayloadPkg/Library/ResetSystemLib/ResetSystemLib.c
2a6abaf6ba86ff27a25d8948ed507ad7d6f439b2
[mirror_edk2.git] / CorebootPayloadPkg / Library / ResetSystemLib / ResetSystemLib.c
1 /** @file
2 Reset System Library functions for coreboot
3
4 Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiDxe.h>
10 #include <Library/BaseLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/IoLib.h>
13 #include <Library/HobLib.h>
14
15 #include <Guid/AcpiBoardInfoGuid.h>
16
17 VOID
18 AcpiPmControl (
19 UINTN SuspendType
20 )
21 {
22 EFI_HOB_GUID_TYPE *GuidHob;
23 ACPI_BOARD_INFO *pAcpiBoardInfo;
24 UINTN PmCtrlReg = 0;
25
26 ASSERT (SuspendType <= 7);
27 //
28 // Find the acpi board information guid hob
29 //
30 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
31 ASSERT (GuidHob != NULL);
32 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
33
34 PmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;
35 IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (SuspendType << 10));
36 IoOr16 (PmCtrlReg, BIT13);
37 CpuDeadLoop ();
38 }
39
40 /**
41 Calling this function causes a system-wide reset. This sets
42 all circuitry within the system to its initial state. This type of reset
43 is asynchronous to system operation and operates without regard to
44 cycle boundaries.
45
46 System reset should not return, if it returns, it means the system does
47 not support cold reset.
48 **/
49 VOID
50 EFIAPI
51 ResetCold (
52 VOID
53 )
54 {
55 EFI_HOB_GUID_TYPE *GuidHob;
56 ACPI_BOARD_INFO *pAcpiBoardInfo;
57
58 //
59 // Find the acpi board information guid hob
60 //
61 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
62 ASSERT (GuidHob != NULL);
63 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
64
65 IoWrite8 ((UINTN)pAcpiBoardInfo->ResetRegAddress, pAcpiBoardInfo->ResetValue);
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 EFI_HOB_GUID_TYPE *GuidHob;
83 ACPI_BOARD_INFO *pAcpiBoardInfo;
84
85 //
86 // Find the acpi board information guid hob
87 //
88 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
89 ASSERT (GuidHob != NULL);
90 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
91
92 IoWrite8 ((UINTN)pAcpiBoardInfo->ResetRegAddress, pAcpiBoardInfo->ResetValue);
93 CpuDeadLoop ();
94 }
95
96 /**
97 Calling this function causes the system to enter a power state equivalent
98 to the ACPI G2/S5 or G3 states.
99
100 System shutdown should not return, if it returns, it means the system does
101 not support shut down reset.
102 **/
103 VOID
104 EFIAPI
105 ResetShutdown (
106 VOID
107 )
108 {
109 EFI_HOB_GUID_TYPE *GuidHob;
110 ACPI_BOARD_INFO *pAcpiBoardInfo;
111 UINTN PmCtrlReg;
112
113 //
114 // Find the acpi board information guid hob
115 //
116 GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
117 ASSERT (GuidHob != NULL);
118 pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
119
120 //
121 // GPE0_EN should be disabled to avoid any GPI waking up the system from S5
122 //
123 IoWrite16 ((UINTN)pAcpiBoardInfo->PmGpeEnBase, 0);
124
125 //
126 // Clear Power Button Status
127 //
128 IoWrite16((UINTN) pAcpiBoardInfo->PmEvtBase, BIT8);
129
130 //
131 // Transform system into S5 sleep state
132 //
133 PmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;
134 IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (7 << 10));
135 IoOr16 (PmCtrlReg, BIT13);
136 CpuDeadLoop ();
137
138 ASSERT (FALSE);
139 }
140
141 /**
142 Calling this function causes the system to enter a power state for capsule
143 update.
144
145 Reset update should not return, if it returns, it means the system does
146 not support capsule update.
147
148 **/
149 VOID
150 EFIAPI
151 EnterS3WithImmediateWake (
152 VOID
153 )
154 {
155 AcpiPmControl (5);
156 ASSERT (FALSE);
157 }
158
159 /**
160 This function causes a systemwide reset. The exact type of the reset is
161 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
162 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
163 the platform must pick a supported reset type to perform.The platform may
164 optionally log the parameters from any non-normal reset that occurs.
165
166 @param[in] DataSize The size, in bytes, of ResetData.
167 @param[in] ResetData The data buffer starts with a Null-terminated string,
168 followed by the EFI_GUID.
169 **/
170 VOID
171 EFIAPI
172 ResetPlatformSpecific (
173 IN UINTN DataSize,
174 IN VOID *ResetData
175 )
176 {
177 ResetCold ();
178 }
179
180 /**
181 The ResetSystem function resets the entire platform.
182
183 @param[in] ResetType The type of reset to perform.
184 @param[in] ResetStatus The status code for the reset.
185 @param[in] DataSize The size, in bytes, of ResetData.
186 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
187 the data buffer starts with a Null-terminated string, optionally
188 followed by additional binary data. The string is a description
189 that the caller may use to further indicate the reason for the
190 system reset.
191 **/
192 VOID
193 EFIAPI
194 ResetSystem (
195 IN EFI_RESET_TYPE ResetType,
196 IN EFI_STATUS ResetStatus,
197 IN UINTN DataSize,
198 IN VOID *ResetData OPTIONAL
199 )
200 {
201 switch (ResetType) {
202 case EfiResetWarm:
203 ResetWarm ();
204 break;
205
206 case EfiResetCold:
207 ResetCold ();
208 break;
209
210 case EfiResetShutdown:
211 ResetShutdown ();
212 return;
213
214 case EfiResetPlatformSpecific:
215 ResetPlatformSpecific (DataSize, ResetData);
216 return;
217
218 default:
219 return;
220 }
221 }