]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.c
MdeModulePkg/SdMmcPciHcDxe: Add retries for sync commands
[mirror_edk2.git] / MdeModulePkg / Library / RuntimeResetSystemLib / RuntimeResetSystemLib.c
CommitLineData
d6de6452
ZG
1/** @file\r
2 DXE Reset System Library instance that calls gRT->ResetSystem().\r
3\r
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
d6de6452
ZG
6\r
7**/\r
8\r
9#include <PiDxe.h>\r
10#include <Library/ResetSystemLib.h>\r
11#include <Library/UefiRuntimeServicesTableLib.h>\r
12#include <Library/UefiBootServicesTableLib.h>\r
13#include <Library/DebugLib.h>\r
14\r
15EFI_EVENT mRuntimeResetSystemLibVirtualAddressChangeEvent;\r
16EFI_RUNTIME_SERVICES *mInternalRT;\r
17\r
18/**\r
19 This function causes a system-wide reset (cold reset), in which\r
20 all circuitry within the system returns to its initial state. This type of reset\r
21 is asynchronous to system operation and operates without regard to\r
22 cycle boundaries.\r
23\r
24 If this function returns, it means that the system does not support cold reset.\r
25**/\r
26VOID\r
27EFIAPI\r
28ResetCold (\r
29 VOID\r
30 )\r
31{\r
32 mInternalRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
33}\r
34\r
35/**\r
36 This function causes a system-wide initialization (warm reset), in which all processors\r
37 are set to their initial state. Pending cycles are not corrupted.\r
38\r
39 If this function returns, it means that the system does not support warm reset.\r
40**/\r
41VOID\r
42EFIAPI\r
43ResetWarm (\r
44 VOID\r
45 )\r
46{\r
47 mInternalRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
48}\r
49\r
50/**\r
51 This function causes the system to enter a power state equivalent\r
52 to the ACPI G2/S5 or G3 states.\r
53\r
54 If this function returns, it means that the system does not support shut down reset.\r
55**/\r
56VOID\r
57EFIAPI\r
58ResetShutdown (\r
59 VOID\r
60 )\r
61{\r
62 mInternalRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);\r
63}\r
64\r
d6de6452
ZG
65/**\r
66 This function causes a systemwide reset. The exact type of the reset is\r
67 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
68 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
69 the platform must pick a supported reset type to perform.The platform may\r
70 optionally log the parameters from any non-normal reset that occurs.\r
71\r
72 @param[in] DataSize The size, in bytes, of ResetData.\r
73 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
74 followed by the EFI_GUID.\r
75**/\r
76VOID\r
77EFIAPI\r
78ResetPlatformSpecific (\r
79 IN UINTN DataSize,\r
80 IN VOID *ResetData\r
81 )\r
82{\r
83 mInternalRT->ResetSystem (EfiResetPlatformSpecific, EFI_SUCCESS, DataSize, ResetData);\r
84}\r
85\r
86/**\r
87 The ResetSystem function resets the entire platform.\r
88\r
89 @param[in] ResetType The type of reset to perform.\r
90 @param[in] ResetStatus The status code for the reset.\r
91 @param[in] DataSize The size, in bytes, of ResetData.\r
92 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r
93 the data buffer starts with a Null-terminated string, optionally\r
94 followed by additional binary data. The string is a description\r
95 that the caller may use to further indicate the reason for the\r
32f55538 96 system reset.\r
d6de6452
ZG
97**/\r
98VOID\r
99EFIAPI\r
100ResetSystem (\r
101 IN EFI_RESET_TYPE ResetType,\r
102 IN EFI_STATUS ResetStatus,\r
103 IN UINTN DataSize,\r
104 IN VOID *ResetData OPTIONAL\r
105 )\r
106{\r
107 mInternalRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
108}\r
109\r
110/**\r
111 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
112\r
113 @param Event Event whose notification function is being invoked.\r
114 @param Context Pointer to the notification function's context\r
115\r
116**/\r
117VOID\r
118EFIAPI\r
119RuntimeResetSystemLibVirtualAddressChange (\r
120 IN EFI_EVENT Event,\r
121 IN VOID *Context\r
122 )\r
123{\r
124 mInternalRT->ConvertPointer (0, (VOID **) &mInternalRT);\r
125}\r
126\r
127/**\r
128 The constructor function of Runtime Reset System Lib.\r
129\r
130 This function allocates memory for extended status code data, caches\r
131 the report status code service, and registers events.\r
132\r
133 @param ImageHandle The firmware allocated handle for the EFI image.\r
134 @param SystemTable A pointer to the EFI System Table.\r
135\r
136 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
137\r
138**/\r
139EFI_STATUS\r
140EFIAPI\r
141RuntimeResetSystemLibConstruct (\r
142 IN EFI_HANDLE ImageHandle,\r
143 IN EFI_SYSTEM_TABLE *SystemTable\r
144 )\r
145{\r
146 EFI_STATUS Status;\r
147\r
148 //\r
149 // Library should not use the gRT directly, for it may be converted by other library instance.\r
150 //\r
151 mInternalRT = gRT;\r
152\r
153 //\r
154 // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r
155 //\r
156 Status = gBS->CreateEventEx (\r
157 EVT_NOTIFY_SIGNAL,\r
158 TPL_NOTIFY,\r
159 RuntimeResetSystemLibVirtualAddressChange,\r
160 NULL,\r
161 &gEfiEventVirtualAddressChangeGuid,\r
162 &mRuntimeResetSystemLibVirtualAddressChangeEvent\r
163 );\r
164 ASSERT_EFI_ERROR (Status);\r
165\r
166 return EFI_SUCCESS;\r
167}\r
168\r
169/**\r
170 The Deconstructor function of Runtime Reset System Lib.\r
171\r
172 The destructor function frees memory allocated by constructor, and closes related events.\r
173 It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.\r
174\r
175 @param ImageHandle The firmware allocated handle for the EFI image.\r
176 @param SystemTable A pointer to the EFI System Table.\r
177\r
178 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
179\r
180**/\r
181EFI_STATUS\r
182EFIAPI\r
183RuntimeResetSystemLibDeconstruct (\r
184 IN EFI_HANDLE ImageHandle,\r
185 IN EFI_SYSTEM_TABLE *SystemTable\r
186 )\r
187{\r
188 EFI_STATUS Status;\r
189\r
190 ASSERT (gBS != NULL);\r
191 Status = gBS->CloseEvent (mRuntimeResetSystemLibVirtualAddressChangeEvent);\r
192 ASSERT_EFI_ERROR (Status);\r
193\r
194 return EFI_SUCCESS;\r
195}\r