]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.c
NetworkPkg: Move Network library and drivers from MdeModulePkg to NetworkPkg
[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
65/**\r
66 This function causes the system to enter S3 and then wake up immediately.\r
67\r
68 If this function returns, it means that the system does not support S3 feature.\r
69**/\r
70VOID\r
71EFIAPI\r
72EnterS3WithImmediateWake (\r
73 VOID\r
74 )\r
75{\r
76}\r
77\r
78/**\r
79 This function causes a systemwide reset. The exact type of the reset is\r
80 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
81 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
82 the platform must pick a supported reset type to perform.The platform may\r
83 optionally log the parameters from any non-normal reset that occurs.\r
84\r
85 @param[in] DataSize The size, in bytes, of ResetData.\r
86 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
87 followed by the EFI_GUID.\r
88**/\r
89VOID\r
90EFIAPI\r
91ResetPlatformSpecific (\r
92 IN UINTN DataSize,\r
93 IN VOID *ResetData\r
94 )\r
95{\r
96 mInternalRT->ResetSystem (EfiResetPlatformSpecific, EFI_SUCCESS, DataSize, ResetData);\r
97}\r
98\r
99/**\r
100 The ResetSystem function resets the entire platform.\r
101\r
102 @param[in] ResetType The type of reset to perform.\r
103 @param[in] ResetStatus The status code for the reset.\r
104 @param[in] DataSize The size, in bytes, of ResetData.\r
105 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r
106 the data buffer starts with a Null-terminated string, optionally\r
107 followed by additional binary data. The string is a description\r
108 that the caller may use to further indicate the reason for the\r
32f55538 109 system reset.\r
d6de6452
ZG
110**/\r
111VOID\r
112EFIAPI\r
113ResetSystem (\r
114 IN EFI_RESET_TYPE ResetType,\r
115 IN EFI_STATUS ResetStatus,\r
116 IN UINTN DataSize,\r
117 IN VOID *ResetData OPTIONAL\r
118 )\r
119{\r
120 mInternalRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
121}\r
122\r
123/**\r
124 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
125\r
126 @param Event Event whose notification function is being invoked.\r
127 @param Context Pointer to the notification function's context\r
128\r
129**/\r
130VOID\r
131EFIAPI\r
132RuntimeResetSystemLibVirtualAddressChange (\r
133 IN EFI_EVENT Event,\r
134 IN VOID *Context\r
135 )\r
136{\r
137 mInternalRT->ConvertPointer (0, (VOID **) &mInternalRT);\r
138}\r
139\r
140/**\r
141 The constructor function of Runtime Reset System Lib.\r
142\r
143 This function allocates memory for extended status code data, caches\r
144 the report status code service, and registers events.\r
145\r
146 @param ImageHandle The firmware allocated handle for the EFI image.\r
147 @param SystemTable A pointer to the EFI System Table.\r
148\r
149 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
150\r
151**/\r
152EFI_STATUS\r
153EFIAPI\r
154RuntimeResetSystemLibConstruct (\r
155 IN EFI_HANDLE ImageHandle,\r
156 IN EFI_SYSTEM_TABLE *SystemTable\r
157 )\r
158{\r
159 EFI_STATUS Status;\r
160\r
161 //\r
162 // Library should not use the gRT directly, for it may be converted by other library instance.\r
163 //\r
164 mInternalRT = gRT;\r
165\r
166 //\r
167 // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r
168 //\r
169 Status = gBS->CreateEventEx (\r
170 EVT_NOTIFY_SIGNAL,\r
171 TPL_NOTIFY,\r
172 RuntimeResetSystemLibVirtualAddressChange,\r
173 NULL,\r
174 &gEfiEventVirtualAddressChangeGuid,\r
175 &mRuntimeResetSystemLibVirtualAddressChangeEvent\r
176 );\r
177 ASSERT_EFI_ERROR (Status);\r
178\r
179 return EFI_SUCCESS;\r
180}\r
181\r
182/**\r
183 The Deconstructor function of Runtime Reset System Lib.\r
184\r
185 The destructor function frees memory allocated by constructor, and closes related events.\r
186 It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.\r
187\r
188 @param ImageHandle The firmware allocated handle for the EFI image.\r
189 @param SystemTable A pointer to the EFI System Table.\r
190\r
191 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
192\r
193**/\r
194EFI_STATUS\r
195EFIAPI\r
196RuntimeResetSystemLibDeconstruct (\r
197 IN EFI_HANDLE ImageHandle,\r
198 IN EFI_SYSTEM_TABLE *SystemTable\r
199 )\r
200{\r
201 EFI_STATUS Status;\r
202\r
203 ASSERT (gBS != NULL);\r
204 Status = gBS->CloseEvent (mRuntimeResetSystemLibVirtualAddressChangeEvent);\r
205 ASSERT_EFI_ERROR (Status);\r
206\r
207 return EFI_SUCCESS;\r
208}\r