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