TianoCore EDK2 master
Loading...
Searching...
No Matches
ResetUtility.c
Go to the documentation of this file.
1
10#include <Uefi.h>
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
15
16#pragma pack(1)
17typedef struct {
18 CHAR16 NullTerminator;
19 GUID ResetSubtype;
21#pragma pack()
22
25 "sizeof (RESET_UTILITY_GUID_SPECIFIC_RESET_DATA) is expected to be 18 bytes"
26 );
27
45VOID
46EFIAPI
48 IN EFI_RESET_TYPE ResetType,
49 IN CONST GUID *ResetSubtype
50 )
51{
53
54 ResetData.NullTerminator = CHAR_NULL;
55 CopyGuid (
56 (GUID *)((UINT8 *)&ResetData + OFFSET_OF (RESET_UTILITY_GUID_SPECIFIC_RESET_DATA, ResetSubtype)),
57 ResetSubtype
58 );
59
60 ResetSystem (ResetType, EFI_SUCCESS, sizeof (ResetData), &ResetData);
61}
62
79VOID
80EFIAPI
82 IN CONST GUID *ResetSubtype
83 )
84{
86}
87
106GUID *
107EFIAPI
109 IN UINTN DataSize,
110 IN CONST VOID *ResetData
111 )
112{
113 UINTN ResetDataStringSize;
114 GUID *ResetSubtypeGuid;
115
116 //
117 // Make sure parameters are valid
118 //
119 if ((ResetData == NULL) || (DataSize < sizeof (GUID))) {
120 return NULL;
121 }
122
123 //
124 // Determine the number of bytes in the Null-terminated Unicode string
125 // at the beginning of ResetData including the Null terminator.
126 //
127 ResetDataStringSize = StrnSizeS (ResetData, (DataSize / sizeof (CHAR16)));
128
129 //
130 // Now, assuming that we have enough data for a GUID after the string, the
131 // GUID should be immediately after the string itself.
132 //
133 if ((ResetDataStringSize < DataSize) && ((DataSize - ResetDataStringSize) >= sizeof (GUID))) {
134 ResetSubtypeGuid = (GUID *)((UINT8 *)ResetData + ResetDataStringSize);
135 DEBUG ((DEBUG_VERBOSE, "%a - Detected reset subtype %g...\n", __func__, ResetSubtypeGuid));
136 return ResetSubtypeGuid;
137 }
138
139 return NULL;
140}
141
175RETURN_STATUS
176EFIAPI
178 IN OUT UINTN *ResetDataSize,
179 IN OUT VOID *ResetData,
180 IN CONST GUID *ResetSubtype OPTIONAL,
181 IN CONST CHAR16 *ResetString OPTIONAL,
182 IN UINTN ExtraDataSize OPTIONAL,
183 IN CONST VOID *ExtraData OPTIONAL
184 )
185{
186 UINTN ResetStringSize;
187 UINTN ResetDataBufferSize;
188 UINT8 *Data;
189
190 //
191 // If the size return pointer is NULL.
192 //
193 if (ResetDataSize == NULL) {
195 }
196
197 //
198 // If extra data is indicated, but pointer is NULL.
199 //
200 if ((ExtraDataSize > 0) && (ExtraData == NULL)) {
202 }
203
204 //
205 // If extra data is indicated, but no subtype GUID is supplied.
206 //
207 if ((ResetSubtype == NULL) && (ExtraDataSize > 0)) {
209 }
210
211 //
212 // Determine the final string.
213 //
214 if (ResetString == NULL) {
215 ResetString = L""; // Use an empty string.
216 }
217
218 //
219 // Calculate the total buffer required for ResetData.
220 //
221 ResetStringSize = StrnSizeS (ResetString, MAX_UINT16);
222 ResetDataBufferSize = ResetStringSize + ExtraDataSize;
223 if (ResetSubtype != NULL) {
224 ResetDataBufferSize += sizeof (GUID);
225 }
226
227 //
228 // At this point, if the buffer isn't large enough (or if
229 // the buffer is NULL) we cannot proceed.
230 //
231 if (*ResetDataSize < ResetDataBufferSize) {
232 *ResetDataSize = ResetDataBufferSize;
234 }
235
236 *ResetDataSize = ResetDataBufferSize;
237 if (ResetData == NULL) {
239 }
240
241 //
242 // Fill in ResetData with ResetString, the ResetSubtype GUID, and extra data
243 //
244 Data = (UINT8 *)ResetData;
245 CopyMem (Data, ResetString, ResetStringSize);
246 Data += ResetStringSize;
247 if (ResetSubtype != NULL) {
248 CopyMem (Data, ResetSubtype, sizeof (GUID));
249 Data += sizeof (GUID);
250 }
251
252 if (ExtraDataSize > 0) {
253 CopyMem (Data, ExtraData, ExtraDataSize);
254 }
255
256 return RETURN_SUCCESS;
257}
UINT64 UINTN
VOID EFIAPI ResetSystem(IN EFI_RESET_TYPE ResetType, IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN VOID *ResetData OPTIONAL)
UINTN EFIAPI StrnSizeS(IN CONST CHAR16 *String, IN UINTN MaxSize)
Definition: SafeString.c:176
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_BUFFER_TOO_SMALL
Definition: Base.h:1093
#define RETURN_SUCCESS
Definition: Base.h:1066
#define STATIC_ASSERT
Definition: Base.h:808
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFIAPI BuildResetData(IN OUT UINTN *ResetDataSize, IN OUT VOID *ResetData, IN CONST GUID *ResetSubtype OPTIONAL, IN CONST CHAR16 *ResetString OPTIONAL, IN UINTN ExtraDataSize OPTIONAL, IN CONST VOID *ExtraData OPTIONAL)
Definition: ResetUtility.c:177
VOID EFIAPI ResetPlatformSpecificGuid(IN CONST GUID *ResetSubtype)
Definition: ResetUtility.c:81
VOID EFIAPI ResetSystemWithSubtype(IN EFI_RESET_TYPE ResetType, IN CONST GUID *ResetSubtype)
Definition: ResetUtility.c:47
GUID *EFIAPI GetResetPlatformSpecificGuid(IN UINTN DataSize, IN CONST VOID *ResetData)
Definition: ResetUtility.c:108
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_RESET_TYPE
@ EfiResetPlatformSpecific
Definition: Base.h:213