]>
Commit | Line | Data |
---|---|---|
30c8ee5c | 1 | /** @file\r |
2 | API implementation for instance of Report Status Code Library.\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30c8ee5c | 6 | \r |
7 | **/\r | |
8 | \r | |
4adf0008 | 9 | #include <Library/ReportStatusCodeLib.h>\r |
10 | #include <Library/BaseLib.h>\r | |
11 | #include <Library/DebugLib.h>\r | |
12 | #include <Library/UefiBootServicesTableLib.h>\r | |
13 | #include <Library/BaseMemoryLib.h>\r | |
14 | #include <Library/PcdLib.h>\r | |
15 | #include <Library/DevicePathLib.h>\r | |
16 | #include <Library/UefiRuntimeLib.h>\r | |
17 | \r | |
18 | #include <Protocol/StatusCode.h>\r | |
19 | \r | |
20 | #include <Guid/StatusCodeDataTypeId.h>\r | |
21 | #include <Guid/StatusCodeDataTypeDebug.h>\r | |
22 | #include <Guid/EventGroup.h>\r | |
23 | \r | |
e5c1acc5 SZ |
24 | //\r |
25 | // Define the maximum extended data size that is supported when a status code is reported.\r | |
26 | //\r | |
27 | #define MAX_EXTENDED_DATA_SIZE 0x200\r | |
28 | \r | |
4adf0008 | 29 | EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;\r |
30 | EFI_EVENT mReportStatusCodeLibVirtualAddressChangeEvent;\r | |
c05e7994 LG |
31 | EFI_EVENT mReportStatusCodeLibExitBootServicesEvent;\r |
32 | BOOLEAN mHaveExitedBootServices = FALSE;\r | |
4adf0008 | 33 | \r |
34 | /**\r | |
35 | Locate the report status code service.\r | |
36 | \r | |
37 | Retrieve ReportStatusCode() API of Report Status Code Protocol.\r | |
38 | \r | |
39 | **/\r | |
40 | VOID\r | |
41 | InternalGetReportStatusCode (\r | |
42 | VOID\r | |
43 | )\r | |
44 | {\r | |
45 | EFI_STATUS Status;\r | |
46 | \r | |
47 | if (mReportStatusCodeLibStatusCodeProtocol != NULL) {\r | |
48 | return;\r | |
49 | }\r | |
d1102dba | 50 | \r |
c05e7994 | 51 | if (mHaveExitedBootServices) {\r |
4adf0008 | 52 | return;\r |
53 | }\r | |
d1102dba | 54 | \r |
4adf0008 | 55 | //\r |
56 | // Check gBS just in case ReportStatusCode is called before gBS is initialized.\r | |
57 | //\r | |
1436aea4 MK |
58 | if ((gBS != NULL) && (gBS->LocateProtocol != NULL)) {\r |
59 | Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&mReportStatusCodeLibStatusCodeProtocol);\r | |
4adf0008 | 60 | if (EFI_ERROR (Status)) {\r |
61 | mReportStatusCodeLibStatusCodeProtocol = NULL;\r | |
62 | }\r | |
63 | }\r | |
64 | }\r | |
65 | \r | |
66 | /**\r | |
67 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
68 | \r | |
69 | @param Event Event whose notification function is being invoked.\r | |
70 | @param Context Pointer to the notification function's context\r | |
71 | \r | |
72 | **/\r | |
73 | VOID\r | |
74 | EFIAPI\r | |
75 | ReportStatusCodeLibVirtualAddressChange (\r | |
1436aea4 MK |
76 | IN EFI_EVENT Event,\r |
77 | IN VOID *Context\r | |
4adf0008 | 78 | )\r |
79 | {\r | |
80 | if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r | |
81 | return;\r | |
82 | }\r | |
1436aea4 MK |
83 | \r |
84 | EfiConvertPointer (0, (VOID **)&mReportStatusCodeLibStatusCodeProtocol);\r | |
4adf0008 | 85 | }\r |
86 | \r | |
c05e7994 LG |
87 | /**\r |
88 | Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.\r | |
89 | \r | |
90 | @param Event Event whose notification function is being invoked.\r | |
91 | @param Context Pointer to the notification function's context\r | |
92 | \r | |
93 | **/\r | |
94 | VOID\r | |
95 | EFIAPI\r | |
96 | ReportStatusCodeLibExitBootServices (\r | |
1436aea4 MK |
97 | IN EFI_EVENT Event,\r |
98 | IN VOID *Context\r | |
c05e7994 LG |
99 | )\r |
100 | {\r | |
101 | //\r | |
102 | // Locate the report status code service before enter runtime.\r | |
d1102dba | 103 | //\r |
c05e7994 | 104 | InternalGetReportStatusCode ();\r |
d1102dba | 105 | \r |
c05e7994 LG |
106 | mHaveExitedBootServices = TRUE;\r |
107 | }\r | |
108 | \r | |
4adf0008 | 109 | /**\r |
110 | The constructor function of Runtime DXE Report Status Code Lib.\r | |
111 | \r | |
112 | This function allocates memory for extended status code data, caches\r | |
113 | the report status code service, and registers events.\r | |
114 | \r | |
115 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
116 | @param SystemTable A pointer to the EFI System Table.\r | |
d1102dba | 117 | \r |
4adf0008 | 118 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r |
119 | \r | |
120 | **/\r | |
121 | EFI_STATUS\r | |
122 | EFIAPI\r | |
123 | ReportStatusCodeLibConstructor (\r | |
1436aea4 MK |
124 | IN EFI_HANDLE ImageHandle,\r |
125 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
4adf0008 | 126 | )\r |
127 | {\r | |
128 | EFI_STATUS Status;\r | |
129 | \r | |
130 | //\r | |
131 | // Cache the report status code service\r | |
d1102dba | 132 | //\r |
4adf0008 | 133 | InternalGetReportStatusCode ();\r |
134 | \r | |
135 | //\r | |
136 | // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r | |
d1102dba | 137 | //\r |
4adf0008 | 138 | Status = gBS->CreateEventEx (\r |
139 | EVT_NOTIFY_SIGNAL,\r | |
140 | TPL_NOTIFY,\r | |
141 | ReportStatusCodeLibVirtualAddressChange,\r | |
142 | NULL,\r | |
143 | &gEfiEventVirtualAddressChangeGuid,\r | |
144 | &mReportStatusCodeLibVirtualAddressChangeEvent\r | |
145 | );\r | |
146 | ASSERT_EFI_ERROR (Status);\r | |
147 | \r | |
c05e7994 LG |
148 | //\r |
149 | // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES\r | |
d1102dba | 150 | //\r |
c05e7994 LG |
151 | Status = gBS->CreateEventEx (\r |
152 | EVT_NOTIFY_SIGNAL,\r | |
153 | TPL_NOTIFY,\r | |
154 | ReportStatusCodeLibExitBootServices,\r | |
155 | NULL,\r | |
156 | &gEfiEventExitBootServicesGuid,\r | |
157 | &mReportStatusCodeLibExitBootServicesEvent\r | |
158 | );\r | |
159 | ASSERT_EFI_ERROR (Status);\r | |
160 | \r | |
4adf0008 | 161 | return EFI_SUCCESS;\r |
162 | }\r | |
163 | \r | |
164 | /**\r | |
165 | The destructor function of Runtime DXE Report Status Code Lib.\r | |
d1102dba | 166 | \r |
4adf0008 | 167 | The destructor function frees memory allocated by constructor, and closes related events.\r |
d1102dba | 168 | It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.\r |
4adf0008 | 169 | \r |
170 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
171 | @param SystemTable A pointer to the EFI System Table.\r | |
d1102dba | 172 | \r |
4adf0008 | 173 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r |
174 | \r | |
175 | **/\r | |
176 | EFI_STATUS\r | |
177 | EFIAPI\r | |
178 | ReportStatusCodeLibDestructor (\r | |
179 | IN EFI_HANDLE ImageHandle,\r | |
180 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
181 | )\r | |
182 | {\r | |
183 | EFI_STATUS Status;\r | |
184 | \r | |
185 | ASSERT (gBS != NULL);\r | |
186 | Status = gBS->CloseEvent (mReportStatusCodeLibVirtualAddressChangeEvent);\r | |
187 | ASSERT_EFI_ERROR (Status);\r | |
188 | \r | |
c05e7994 LG |
189 | Status = gBS->CloseEvent (mReportStatusCodeLibExitBootServicesEvent);\r |
190 | ASSERT_EFI_ERROR (Status);\r | |
191 | \r | |
4adf0008 | 192 | return EFI_SUCCESS;\r |
193 | }\r | |
194 | \r | |
195 | /**\r | |
196 | Internal worker function that reports a status code through the Report Status Code Protocol.\r | |
197 | \r | |
198 | If status code service is not cached, then this function checks if Report Status Code\r | |
199 | Protocol is available in system. If Report Status Code Protocol is not available, then\r | |
200 | EFI_UNSUPPORTED is returned. If Report Status Code Protocol is present, then it is\r | |
201 | cached in mReportStatusCodeLibStatusCodeProtocol. Finally this function reports status\r | |
202 | code through the Report Status Code Protocol.\r | |
203 | \r | |
204 | @param Type Status code type.\r | |
205 | @param Value Status code value.\r | |
206 | @param Instance Status code instance number.\r | |
207 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
208 | function. This is an optional parameter that may be\r | |
209 | NULL.\r | |
210 | @param Data Pointer to the extended data buffer. This is an\r | |
211 | optional parameter that may be NULL.\r | |
212 | \r | |
213 | @retval EFI_SUCCESS The status code was reported.\r | |
214 | @retval EFI_UNSUPPORTED Report Status Code Protocol is not available.\r | |
215 | @retval EFI_UNSUPPORTED Status code type is not supported.\r | |
216 | \r | |
217 | **/\r | |
218 | EFI_STATUS\r | |
219 | InternalReportStatusCode (\r | |
1436aea4 MK |
220 | IN EFI_STATUS_CODE_TYPE Type,\r |
221 | IN EFI_STATUS_CODE_VALUE Value,\r | |
222 | IN UINT32 Instance,\r | |
223 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
224 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
4adf0008 | 225 | )\r |
226 | {\r | |
1436aea4 MK |
227 | if ((ReportProgressCodeEnabled () && (((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE)) ||\r |
228 | (ReportErrorCodeEnabled () && (((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE)) ||\r | |
229 | (ReportDebugCodeEnabled () && (((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)))\r | |
230 | {\r | |
4adf0008 | 231 | //\r |
232 | // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.\r | |
233 | //\r | |
234 | InternalGetReportStatusCode ();\r | |
235 | if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r | |
236 | return EFI_UNSUPPORTED;\r | |
237 | }\r | |
238 | \r | |
239 | //\r | |
240 | // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.\r | |
241 | //\r | |
242 | return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r | |
243 | }\r | |
d1102dba | 244 | \r |
4adf0008 | 245 | return EFI_UNSUPPORTED;\r |
246 | }\r | |
247 | \r | |
30c8ee5c | 248 | /**\r |
249 | Converts a status code to an 8-bit POST code value.\r | |
250 | \r | |
251 | Converts the status code specified by CodeType and Value to an 8-bit POST code\r | |
252 | and returns the 8-bit POST code in PostCode. If CodeType is an\r | |
253 | EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode\r | |
254 | are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits\r | |
255 | 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.\r | |
256 | \r | |
257 | If PostCode is NULL, then ASSERT().\r | |
258 | \r | |
259 | @param CodeType The type of status code being converted.\r | |
260 | @param Value The status code value being converted.\r | |
261 | @param PostCode A pointer to the 8-bit POST code value to return.\r | |
262 | \r | |
263 | @retval TRUE The status code specified by CodeType and Value was converted\r | |
264 | to an 8-bit POST code and returned in PostCode.\r | |
265 | @retval FALSE The status code specified by CodeType and Value could not be\r | |
266 | converted to an 8-bit POST code value.\r | |
267 | \r | |
268 | **/\r | |
269 | BOOLEAN\r | |
270 | EFIAPI\r | |
271 | CodeTypeToPostCode (\r | |
272 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
273 | IN EFI_STATUS_CODE_VALUE Value,\r | |
274 | OUT UINT8 *PostCode\r | |
275 | )\r | |
276 | {\r | |
277 | //\r | |
278 | // If PostCode is NULL, then ASSERT()\r | |
279 | //\r | |
280 | ASSERT (PostCode != NULL);\r | |
281 | \r | |
282 | //\r | |
283 | // Convert Value to an 8 bit post code\r | |
284 | //\r | |
285 | if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r | |
1436aea4 MK |
286 | ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE))\r |
287 | {\r | |
288 | *PostCode = (UINT8)((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |\r | |
289 | (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));\r | |
30c8ee5c | 290 | return TRUE;\r |
291 | }\r | |
1436aea4 | 292 | \r |
30c8ee5c | 293 | return FALSE;\r |
294 | }\r | |
295 | \r | |
30c8ee5c | 296 | /**\r |
297 | Extracts ASSERT() information from a status code structure.\r | |
298 | \r | |
299 | Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r | |
300 | arguments specified by Filename, Description, and LineNumber. If CodeType is\r | |
301 | an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and\r | |
302 | Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract\r | |
303 | Filename, Description, and LineNumber from the optional data area of the\r | |
304 | status code buffer specified by Data. The optional data area of Data contains\r | |
305 | a Null-terminated ASCII string for the FileName, followed by a Null-terminated\r | |
306 | ASCII string for the Description, followed by a 32-bit LineNumber. If the\r | |
307 | ASSERT() information could be extracted from Data, then return TRUE.\r | |
308 | Otherwise, FALSE is returned.\r | |
309 | \r | |
310 | If Data is NULL, then ASSERT().\r | |
311 | If Filename is NULL, then ASSERT().\r | |
312 | If Description is NULL, then ASSERT().\r | |
313 | If LineNumber is NULL, then ASSERT().\r | |
314 | \r | |
315 | @param CodeType The type of status code being converted.\r | |
316 | @param Value The status code value being converted.\r | |
317 | @param Data Pointer to status code data buffer.\r | |
318 | @param Filename Pointer to the source file name that generated the ASSERT().\r | |
319 | @param Description Pointer to the description of the ASSERT().\r | |
320 | @param LineNumber Pointer to source line number that generated the ASSERT().\r | |
321 | \r | |
322 | @retval TRUE The status code specified by CodeType, Value, and Data was\r | |
323 | converted ASSERT() arguments specified by Filename, Description,\r | |
324 | and LineNumber.\r | |
325 | @retval FALSE The status code specified by CodeType, Value, and Data could\r | |
326 | not be converted to ASSERT() arguments.\r | |
327 | \r | |
328 | **/\r | |
329 | BOOLEAN\r | |
330 | EFIAPI\r | |
331 | ReportStatusCodeExtractAssertInfo (\r | |
332 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
333 | IN EFI_STATUS_CODE_VALUE Value,\r | |
334 | IN CONST EFI_STATUS_CODE_DATA *Data,\r | |
335 | OUT CHAR8 **Filename,\r | |
336 | OUT CHAR8 **Description,\r | |
337 | OUT UINT32 *LineNumber\r | |
338 | )\r | |
339 | {\r | |
340 | EFI_DEBUG_ASSERT_DATA *AssertData;\r | |
341 | \r | |
342 | ASSERT (Data != NULL);\r | |
343 | ASSERT (Filename != NULL);\r | |
344 | ASSERT (Description != NULL);\r | |
345 | ASSERT (LineNumber != NULL);\r | |
346 | \r | |
347 | if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r | |
348 | ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&\r | |
1436aea4 MK |
349 | ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE))\r |
350 | {\r | |
30c8ee5c | 351 | AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r |
352 | *Filename = (CHAR8 *)(AssertData + 1);\r | |
353 | *Description = *Filename + AsciiStrLen (*Filename) + 1;\r | |
354 | *LineNumber = AssertData->LineNumber;\r | |
355 | return TRUE;\r | |
356 | }\r | |
1436aea4 | 357 | \r |
30c8ee5c | 358 | return FALSE;\r |
359 | }\r | |
360 | \r | |
30c8ee5c | 361 | /**\r |
362 | Extracts DEBUG() information from a status code structure.\r | |
363 | \r | |
364 | Converts the status code specified by Data to the DEBUG() arguments specified\r | |
365 | by ErrorLevel, Marker, and Format. If type GUID in Data is\r | |
366 | EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and\r | |
367 | Format from the optional data area of the status code buffer specified by Data.\r | |
368 | The optional data area of Data contains a 32-bit ErrorLevel followed by Marker\r | |
369 | which is 12 UINTN parameters, followed by a Null-terminated ASCII string for\r | |
370 | the Format. If the DEBUG() information could be extracted from Data, then\r | |
371 | return TRUE. Otherwise, FALSE is returned.\r | |
372 | \r | |
373 | If Data is NULL, then ASSERT().\r | |
374 | If ErrorLevel is NULL, then ASSERT().\r | |
375 | If Marker is NULL, then ASSERT().\r | |
376 | If Format is NULL, then ASSERT().\r | |
377 | \r | |
378 | @param Data Pointer to status code data buffer.\r | |
379 | @param ErrorLevel Pointer to error level mask for a debug message.\r | |
380 | @param Marker Pointer to the variable argument list associated with Format.\r | |
381 | @param Format Pointer to a Null-terminated ASCII format string of a\r | |
382 | debug message.\r | |
383 | \r | |
384 | @retval TRUE The status code specified by Data was converted DEBUG() arguments\r | |
385 | specified by ErrorLevel, Marker, and Format.\r | |
386 | @retval FALSE The status code specified by Data could not be converted to\r | |
387 | DEBUG() arguments.\r | |
388 | \r | |
389 | **/\r | |
390 | BOOLEAN\r | |
391 | EFIAPI\r | |
392 | ReportStatusCodeExtractDebugInfo (\r | |
393 | IN CONST EFI_STATUS_CODE_DATA *Data,\r | |
394 | OUT UINT32 *ErrorLevel,\r | |
395 | OUT BASE_LIST *Marker,\r | |
396 | OUT CHAR8 **Format\r | |
397 | )\r | |
398 | {\r | |
399 | EFI_DEBUG_INFO *DebugInfo;\r | |
400 | \r | |
401 | ASSERT (Data != NULL);\r | |
402 | ASSERT (ErrorLevel != NULL);\r | |
403 | ASSERT (Marker != NULL);\r | |
404 | ASSERT (Format != NULL);\r | |
405 | \r | |
406 | //\r | |
407 | // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE\r | |
408 | //\r | |
409 | if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r | |
410 | return FALSE;\r | |
411 | }\r | |
412 | \r | |
413 | //\r | |
414 | // Retrieve the debug information from the status code record\r | |
415 | //\r | |
416 | DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r | |
417 | \r | |
418 | *ErrorLevel = DebugInfo->ErrorLevel;\r | |
419 | \r | |
420 | //\r | |
421 | // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r | |
422 | // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r | |
423 | // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r | |
424 | // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r | |
425 | // returned is 64-bit aligned.\r | |
426 | // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r | |
427 | // cause unalignment exception.\r | |
428 | //\r | |
1436aea4 | 429 | *Marker = (BASE_LIST)(DebugInfo + 1);\r |
30c8ee5c | 430 | *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r |
431 | \r | |
432 | return TRUE;\r | |
433 | }\r | |
434 | \r | |
30c8ee5c | 435 | /**\r |
436 | Reports a status code.\r | |
437 | \r | |
438 | Reports the status code specified by the parameters Type and Value. Status\r | |
439 | code also require an instance, caller ID, and extended data. This function\r | |
440 | passed in a zero instance, NULL extended data, and a caller ID of\r | |
441 | gEfiCallerIdGuid, which is the GUID for the module.\r | |
442 | \r | |
443 | ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()\r | |
444 | is called while processing another any other Report Status Code Library function,\r | |
445 | then ReportStatusCode() must return immediately.\r | |
446 | \r | |
447 | @param Type Status code type.\r | |
448 | @param Value Status code value.\r | |
449 | \r | |
450 | @retval EFI_SUCCESS The status code was reported.\r | |
451 | @retval EFI_DEVICE_ERROR There status code could not be reported due to a\r | |
452 | device error.\r | |
453 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
454 | \r | |
455 | **/\r | |
456 | EFI_STATUS\r | |
457 | EFIAPI\r | |
458 | ReportStatusCode (\r | |
459 | IN EFI_STATUS_CODE_TYPE Type,\r | |
460 | IN EFI_STATUS_CODE_VALUE Value\r | |
461 | )\r | |
462 | {\r | |
463 | return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);\r | |
464 | }\r | |
465 | \r | |
30c8ee5c | 466 | /**\r |
467 | Reports a status code with a Device Path Protocol as the extended data.\r | |
468 | \r | |
469 | Allocates and fills in the extended data section of a status code with the\r | |
470 | Device Path Protocol specified by DevicePath. This function is responsible\r | |
471 | for allocating a buffer large enough for the standard header and the device\r | |
472 | path. The standard header is filled in with a GUID of\r | |
473 | gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero\r | |
474 | instance and a caller ID of gEfiCallerIdGuid.\r | |
475 | \r | |
476 | ReportStatusCodeWithDevicePath()must actively prevent recursion. If\r | |
477 | ReportStatusCodeWithDevicePath() is called while processing another any other\r | |
478 | Report Status Code Library function, then ReportStatusCodeWithDevicePath()\r | |
479 | must return EFI_DEVICE_ERROR immediately.\r | |
480 | \r | |
481 | If DevicePath is NULL, then ASSERT().\r | |
482 | \r | |
483 | @param Type Status code type.\r | |
484 | @param Value Status code value.\r | |
485 | @param DevicePath Pointer to the Device Path Protocol to be reported.\r | |
486 | \r | |
487 | @retval EFI_SUCCESS The status code was reported with the extended\r | |
488 | data specified by DevicePath.\r | |
489 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r | |
490 | extended data section.\r | |
491 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
492 | \r | |
493 | **/\r | |
494 | EFI_STATUS\r | |
495 | EFIAPI\r | |
496 | ReportStatusCodeWithDevicePath (\r | |
497 | IN EFI_STATUS_CODE_TYPE Type,\r | |
498 | IN EFI_STATUS_CODE_VALUE Value,\r | |
499 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
500 | )\r | |
501 | {\r | |
502 | ASSERT (DevicePath != NULL);\r | |
503 | return ReportStatusCodeWithExtendedData (\r | |
504 | Type,\r | |
505 | Value,\r | |
506 | (VOID *)DevicePath,\r | |
507 | GetDevicePathSize (DevicePath)\r | |
508 | );\r | |
509 | }\r | |
510 | \r | |
30c8ee5c | 511 | /**\r |
512 | Reports a status code with an extended data buffer.\r | |
513 | \r | |
514 | Allocates and fills in the extended data section of a status code with the\r | |
515 | extended data specified by ExtendedData and ExtendedDataSize. ExtendedData\r | |
516 | is assumed to be one of the data structures specified in Related Definitions.\r | |
517 | These data structure do not have the standard header, so this function is\r | |
518 | responsible for allocating a buffer large enough for the standard header and\r | |
519 | the extended data passed into this function. The standard header is filled\r | |
520 | in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported\r | |
521 | with a zero instance and a caller ID of gEfiCallerIdGuid.\r | |
522 | \r | |
523 | ReportStatusCodeWithExtendedData()must actively prevent recursion. If\r | |
524 | ReportStatusCodeWithExtendedData() is called while processing another any other\r | |
525 | Report Status Code Library function, then ReportStatusCodeWithExtendedData()\r | |
526 | must return EFI_DEVICE_ERROR immediately.\r | |
527 | \r | |
528 | If ExtendedData is NULL, then ASSERT().\r | |
529 | If ExtendedDataSize is 0, then ASSERT().\r | |
530 | \r | |
531 | @param Type Status code type.\r | |
532 | @param Value Status code value.\r | |
533 | @param ExtendedData Pointer to the extended data buffer to be reported.\r | |
534 | @param ExtendedDataSize The size, in bytes, of the extended data buffer to\r | |
535 | be reported.\r | |
536 | \r | |
537 | @retval EFI_SUCCESS The status code was reported with the extended\r | |
538 | data specified by ExtendedData and ExtendedDataSize.\r | |
539 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r | |
540 | extended data section.\r | |
541 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
542 | \r | |
543 | **/\r | |
544 | EFI_STATUS\r | |
545 | EFIAPI\r | |
546 | ReportStatusCodeWithExtendedData (\r | |
547 | IN EFI_STATUS_CODE_TYPE Type,\r | |
548 | IN EFI_STATUS_CODE_VALUE Value,\r | |
549 | IN CONST VOID *ExtendedData,\r | |
550 | IN UINTN ExtendedDataSize\r | |
551 | )\r | |
552 | {\r | |
553 | ASSERT (ExtendedData != NULL);\r | |
554 | ASSERT (ExtendedDataSize != 0);\r | |
555 | return ReportStatusCodeEx (\r | |
556 | Type,\r | |
557 | Value,\r | |
558 | 0,\r | |
559 | NULL,\r | |
560 | NULL,\r | |
561 | ExtendedData,\r | |
562 | ExtendedDataSize\r | |
563 | );\r | |
564 | }\r | |
565 | \r | |
30c8ee5c | 566 | /**\r |
567 | Reports a status code with full parameters.\r | |
568 | \r | |
569 | The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r | |
570 | is 0, then an extended data buffer is not reported. If ExtendedData is not\r | |
571 | NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r | |
572 | ExtendedData is assumed not have the standard status code header, so this function\r | |
573 | is responsible for allocating a buffer large enough for the standard header and\r | |
574 | the extended data passed into this function. The standard header is filled in\r | |
575 | with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r | |
576 | GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with\r | |
577 | an instance specified by Instance and a caller ID specified by CallerId. If\r | |
578 | CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r | |
579 | \r | |
580 | ReportStatusCodeEx()must actively prevent recursion. If\r | |
581 | ReportStatusCodeEx() is called while processing another any\r | |
582 | other Report Status Code Library function, then\r | |
583 | ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r | |
584 | \r | |
585 | If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r | |
586 | If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r | |
587 | \r | |
588 | @param Type Status code type.\r | |
589 | @param Value Status code value.\r | |
590 | @param Instance Status code instance number.\r | |
591 | @param CallerId Pointer to a GUID that identifies the caller of this\r | |
592 | function. If this parameter is NULL, then a caller\r | |
593 | ID of gEfiCallerIdGuid is used.\r | |
594 | @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r | |
595 | If this parameter is NULL, then a the status code\r | |
596 | standard header is filled in with\r | |
597 | gEfiStatusCodeSpecificDataGuid.\r | |
598 | @param ExtendedData Pointer to the extended data buffer. This is an\r | |
599 | optional parameter that may be NULL.\r | |
600 | @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r | |
601 | \r | |
602 | @retval EFI_SUCCESS The status code was reported.\r | |
603 | @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r | |
604 | the extended data section if it was specified.\r | |
605 | @retval EFI_UNSUPPORTED Report status code is not supported\r | |
606 | \r | |
607 | **/\r | |
608 | EFI_STATUS\r | |
609 | EFIAPI\r | |
610 | ReportStatusCodeEx (\r | |
611 | IN EFI_STATUS_CODE_TYPE Type,\r | |
612 | IN EFI_STATUS_CODE_VALUE Value,\r | |
613 | IN UINT32 Instance,\r | |
614 | IN CONST EFI_GUID *CallerId OPTIONAL,\r | |
615 | IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r | |
616 | IN CONST VOID *ExtendedData OPTIONAL,\r | |
617 | IN UINTN ExtendedDataSize\r | |
618 | )\r | |
619 | {\r | |
620 | EFI_STATUS Status;\r | |
4adf0008 | 621 | EFI_STATUS_CODE_DATA *StatusCodeData;\r |
e5c1acc5 | 622 | UINT64 StatusCodeBuffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1];\r |
30c8ee5c | 623 | \r |
624 | ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r | |
625 | ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r | |
626 | \r | |
c22f52c5 MK |
627 | if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r |
628 | //\r | |
629 | // Use Buffer instead of allocating if possible.\r | |
630 | //\r | |
1436aea4 | 631 | StatusCodeData = (EFI_STATUS_CODE_DATA *)StatusCodeBuffer;\r |
c22f52c5 MK |
632 | } else {\r |
633 | if (mHaveExitedBootServices) {\r | |
4adf0008 | 634 | return EFI_OUT_OF_RESOURCES;\r |
635 | }\r | |
c22f52c5 | 636 | \r |
1436aea4 | 637 | if ((gBS == NULL) || (gBS->AllocatePool == NULL) || (gBS->FreePool == NULL)) {\r |
4adf0008 | 638 | return EFI_UNSUPPORTED;\r |
639 | }\r | |
d1102dba | 640 | \r |
4adf0008 | 641 | //\r |
642 | // Allocate space for the Status Code Header and its buffer\r | |
643 | //\r | |
644 | StatusCodeData = NULL;\r | |
645 | gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r | |
646 | if (StatusCodeData == NULL) {\r | |
647 | return EFI_OUT_OF_RESOURCES;\r | |
648 | }\r | |
30c8ee5c | 649 | }\r |
650 | \r | |
651 | //\r | |
652 | // Fill in the extended data header\r | |
653 | //\r | |
1436aea4 MK |
654 | StatusCodeData->HeaderSize = (UINT16)sizeof (EFI_STATUS_CODE_DATA);\r |
655 | StatusCodeData->Size = (UINT16)ExtendedDataSize;\r | |
30c8ee5c | 656 | if (ExtendedDataGuid == NULL) {\r |
657 | ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r | |
658 | }\r | |
1436aea4 | 659 | \r |
4adf0008 | 660 | CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r |
30c8ee5c | 661 | \r |
662 | //\r | |
663 | // Fill in the extended data buffer\r | |
664 | //\r | |
665 | if (ExtendedData != NULL) {\r | |
4adf0008 | 666 | CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r |
30c8ee5c | 667 | }\r |
668 | \r | |
669 | //\r | |
670 | // Report the status code\r | |
671 | //\r | |
672 | if (CallerId == NULL) {\r | |
673 | CallerId = &gEfiCallerIdGuid;\r | |
674 | }\r | |
1436aea4 | 675 | \r |
4adf0008 | 676 | Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r |
677 | \r | |
678 | //\r | |
679 | // Free the allocated buffer\r | |
680 | //\r | |
1436aea4 | 681 | if (StatusCodeData != (EFI_STATUS_CODE_DATA *)StatusCodeBuffer) {\r |
4adf0008 | 682 | gBS->FreePool (StatusCodeData);\r |
683 | }\r | |
30c8ee5c | 684 | \r |
685 | return Status;\r | |
686 | }\r | |
687 | \r | |
30c8ee5c | 688 | /**\r |
689 | Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled\r | |
690 | \r | |
691 | This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED\r | |
692 | bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r | |
693 | \r | |
694 | @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r | |
695 | PcdReportStatusCodeProperyMask is set.\r | |
696 | @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r | |
697 | PcdReportStatusCodeProperyMask is clear.\r | |
698 | \r | |
699 | **/\r | |
700 | BOOLEAN\r | |
701 | EFIAPI\r | |
702 | ReportProgressCodeEnabled (\r | |
703 | VOID\r | |
704 | )\r | |
705 | {\r | |
1436aea4 | 706 | return (BOOLEAN)((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r |
30c8ee5c | 707 | }\r |
708 | \r | |
30c8ee5c | 709 | /**\r |
710 | Returns TRUE if status codes of type EFI_ERROR_CODE are enabled\r | |
711 | \r | |
712 | This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED\r | |
713 | bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r | |
714 | \r | |
715 | @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r | |
716 | PcdReportStatusCodeProperyMask is set.\r | |
717 | @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r | |
718 | PcdReportStatusCodeProperyMask is clear.\r | |
719 | \r | |
720 | **/\r | |
721 | BOOLEAN\r | |
722 | EFIAPI\r | |
723 | ReportErrorCodeEnabled (\r | |
724 | VOID\r | |
725 | )\r | |
726 | {\r | |
1436aea4 | 727 | return (BOOLEAN)((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r |
30c8ee5c | 728 | }\r |
729 | \r | |
30c8ee5c | 730 | /**\r |
731 | Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled\r | |
732 | \r | |
733 | This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED\r | |
734 | bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r | |
735 | \r | |
736 | @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
737 | PcdReportStatusCodeProperyMask is set.\r | |
738 | @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
739 | PcdReportStatusCodeProperyMask is clear.\r | |
740 | \r | |
741 | **/\r | |
742 | BOOLEAN\r | |
743 | EFIAPI\r | |
744 | ReportDebugCodeEnabled (\r | |
745 | VOID\r | |
746 | )\r | |
747 | {\r | |
1436aea4 | 748 | return (BOOLEAN)((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r |
30c8ee5c | 749 | }\r |