]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / RuntimeDxeReportStatusCodeLib / ReportStatusCodeLib.c
CommitLineData
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//\r
26// Define the maximum extended data size that is supported when a status code is reported.\r
27//\r
28#define MAX_EXTENDED_DATA_SIZE 0x200\r
29\r
4adf0008 30EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;\r
31EFI_EVENT mReportStatusCodeLibVirtualAddressChangeEvent;\r
c05e7994
LG
32EFI_EVENT mReportStatusCodeLibExitBootServicesEvent;\r
33BOOLEAN mHaveExitedBootServices = FALSE;\r
4adf0008 34\r
35/**\r
36 Locate the report status code service.\r
37\r
38 Retrieve ReportStatusCode() API of Report Status Code Protocol.\r
39\r
40**/\r
41VOID\r
42InternalGetReportStatusCode (\r
43 VOID\r
44 )\r
45{\r
46 EFI_STATUS Status;\r
47\r
48 if (mReportStatusCodeLibStatusCodeProtocol != NULL) {\r
49 return;\r
50 }\r
d1102dba 51\r
c05e7994 52 if (mHaveExitedBootServices) {\r
4adf0008 53 return;\r
54 }\r
d1102dba 55\r
4adf0008 56 //\r
57 // Check gBS just in case ReportStatusCode is called before gBS is initialized.\r
58 //\r
59 if (gBS != NULL && gBS->LocateProtocol != NULL) {\r
60 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &mReportStatusCodeLibStatusCodeProtocol);\r
61 if (EFI_ERROR (Status)) {\r
62 mReportStatusCodeLibStatusCodeProtocol = NULL;\r
63 }\r
64 }\r
65}\r
66\r
67/**\r
68 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
69\r
70 @param Event Event whose notification function is being invoked.\r
71 @param Context Pointer to the notification function's context\r
72\r
73**/\r
74VOID\r
75EFIAPI\r
76ReportStatusCodeLibVirtualAddressChange (\r
77 IN EFI_EVENT Event,\r
78 IN VOID *Context\r
79 )\r
80{\r
81 if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r
82 return;\r
83 }\r
84 EfiConvertPointer (0, (VOID **) &mReportStatusCodeLibStatusCodeProtocol);\r
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
94VOID\r
95EFIAPI\r
96ReportStatusCodeLibExitBootServices (\r
97 IN EFI_EVENT Event,\r
98 IN VOID *Context\r
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
121EFI_STATUS\r
122EFIAPI\r
123ReportStatusCodeLibConstructor (\r
124 IN EFI_HANDLE ImageHandle,\r
125 IN EFI_SYSTEM_TABLE *SystemTable\r
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
176EFI_STATUS\r
177EFIAPI\r
178ReportStatusCodeLibDestructor (\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
218EFI_STATUS\r
219InternalReportStatusCode (\r
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
225 )\r
226{\r
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
231 // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.\r
232 //\r
233 InternalGetReportStatusCode ();\r
234 if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r
235 return EFI_UNSUPPORTED;\r
236 }\r
237\r
238 //\r
239 // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.\r
240 //\r
241 return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
242 }\r
d1102dba 243\r
4adf0008 244 return EFI_UNSUPPORTED;\r
245}\r
246\r
30c8ee5c 247\r
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
269BOOLEAN\r
270EFIAPI\r
271CodeTypeToPostCode (\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
286 ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ) {\r
287 *PostCode = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |\r
288 (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));\r
289 return TRUE;\r
290 }\r
291 return FALSE;\r
292}\r
293\r
294\r
295/**\r
296 Extracts ASSERT() information from a status code structure.\r
297\r
298 Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r
299 arguments specified by Filename, Description, and LineNumber. If CodeType is\r
300 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and\r
301 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract\r
302 Filename, Description, and LineNumber from the optional data area of the\r
303 status code buffer specified by Data. The optional data area of Data contains\r
304 a Null-terminated ASCII string for the FileName, followed by a Null-terminated\r
305 ASCII string for the Description, followed by a 32-bit LineNumber. If the\r
306 ASSERT() information could be extracted from Data, then return TRUE.\r
307 Otherwise, FALSE is returned.\r
308\r
309 If Data is NULL, then ASSERT().\r
310 If Filename is NULL, then ASSERT().\r
311 If Description is NULL, then ASSERT().\r
312 If LineNumber is NULL, then ASSERT().\r
313\r
314 @param CodeType The type of status code being converted.\r
315 @param Value The status code value being converted.\r
316 @param Data Pointer to status code data buffer.\r
317 @param Filename Pointer to the source file name that generated the ASSERT().\r
318 @param Description Pointer to the description of the ASSERT().\r
319 @param LineNumber Pointer to source line number that generated the ASSERT().\r
320\r
321 @retval TRUE The status code specified by CodeType, Value, and Data was\r
322 converted ASSERT() arguments specified by Filename, Description,\r
323 and LineNumber.\r
324 @retval FALSE The status code specified by CodeType, Value, and Data could\r
325 not be converted to ASSERT() arguments.\r
326\r
327**/\r
328BOOLEAN\r
329EFIAPI\r
330ReportStatusCodeExtractAssertInfo (\r
331 IN EFI_STATUS_CODE_TYPE CodeType,\r
332 IN EFI_STATUS_CODE_VALUE Value,\r
333 IN CONST EFI_STATUS_CODE_DATA *Data,\r
334 OUT CHAR8 **Filename,\r
335 OUT CHAR8 **Description,\r
336 OUT UINT32 *LineNumber\r
337 )\r
338{\r
339 EFI_DEBUG_ASSERT_DATA *AssertData;\r
340\r
341 ASSERT (Data != NULL);\r
342 ASSERT (Filename != NULL);\r
343 ASSERT (Description != NULL);\r
344 ASSERT (LineNumber != NULL);\r
345\r
346 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r
347 ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&\r
348 ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r
349 AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
350 *Filename = (CHAR8 *)(AssertData + 1);\r
351 *Description = *Filename + AsciiStrLen (*Filename) + 1;\r
352 *LineNumber = AssertData->LineNumber;\r
353 return TRUE;\r
354 }\r
355 return FALSE;\r
356}\r
357\r
358\r
359/**\r
360 Extracts DEBUG() information from a status code structure.\r
361\r
362 Converts the status code specified by Data to the DEBUG() arguments specified\r
363 by ErrorLevel, Marker, and Format. If type GUID in Data is\r
364 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and\r
365 Format from the optional data area of the status code buffer specified by Data.\r
366 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker\r
367 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for\r
368 the Format. If the DEBUG() information could be extracted from Data, then\r
369 return TRUE. Otherwise, FALSE is returned.\r
370\r
371 If Data is NULL, then ASSERT().\r
372 If ErrorLevel is NULL, then ASSERT().\r
373 If Marker is NULL, then ASSERT().\r
374 If Format is NULL, then ASSERT().\r
375\r
376 @param Data Pointer to status code data buffer.\r
377 @param ErrorLevel Pointer to error level mask for a debug message.\r
378 @param Marker Pointer to the variable argument list associated with Format.\r
379 @param Format Pointer to a Null-terminated ASCII format string of a\r
380 debug message.\r
381\r
382 @retval TRUE The status code specified by Data was converted DEBUG() arguments\r
383 specified by ErrorLevel, Marker, and Format.\r
384 @retval FALSE The status code specified by Data could not be converted to\r
385 DEBUG() arguments.\r
386\r
387**/\r
388BOOLEAN\r
389EFIAPI\r
390ReportStatusCodeExtractDebugInfo (\r
391 IN CONST EFI_STATUS_CODE_DATA *Data,\r
392 OUT UINT32 *ErrorLevel,\r
393 OUT BASE_LIST *Marker,\r
394 OUT CHAR8 **Format\r
395 )\r
396{\r
397 EFI_DEBUG_INFO *DebugInfo;\r
398\r
399 ASSERT (Data != NULL);\r
400 ASSERT (ErrorLevel != NULL);\r
401 ASSERT (Marker != NULL);\r
402 ASSERT (Format != NULL);\r
403\r
404 //\r
405 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE\r
406 //\r
407 if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r
408 return FALSE;\r
409 }\r
410\r
411 //\r
412 // Retrieve the debug information from the status code record\r
413 //\r
414 DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r
415\r
416 *ErrorLevel = DebugInfo->ErrorLevel;\r
417\r
418 //\r
419 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
420 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r
421 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r
422 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r
423 // returned is 64-bit aligned.\r
424 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r
425 // cause unalignment exception.\r
426 //\r
427 *Marker = (BASE_LIST) (DebugInfo + 1);\r
428 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
429\r
430 return TRUE;\r
431}\r
432\r
433\r
434/**\r
435 Reports a status code.\r
436\r
437 Reports the status code specified by the parameters Type and Value. Status\r
438 code also require an instance, caller ID, and extended data. This function\r
439 passed in a zero instance, NULL extended data, and a caller ID of\r
440 gEfiCallerIdGuid, which is the GUID for the module.\r
441\r
442 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()\r
443 is called while processing another any other Report Status Code Library function,\r
444 then ReportStatusCode() must return immediately.\r
445\r
446 @param Type Status code type.\r
447 @param Value Status code value.\r
448\r
449 @retval EFI_SUCCESS The status code was reported.\r
450 @retval EFI_DEVICE_ERROR There status code could not be reported due to a\r
451 device error.\r
452 @retval EFI_UNSUPPORTED Report status code is not supported\r
453\r
454**/\r
455EFI_STATUS\r
456EFIAPI\r
457ReportStatusCode (\r
458 IN EFI_STATUS_CODE_TYPE Type,\r
459 IN EFI_STATUS_CODE_VALUE Value\r
460 )\r
461{\r
462 return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);\r
463}\r
464\r
465\r
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
494EFI_STATUS\r
495EFIAPI\r
496ReportStatusCodeWithDevicePath (\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
511\r
512/**\r
513 Reports a status code with an extended data buffer.\r
514\r
515 Allocates and fills in the extended data section of a status code with the\r
516 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData\r
517 is assumed to be one of the data structures specified in Related Definitions.\r
518 These data structure do not have the standard header, so this function is\r
519 responsible for allocating a buffer large enough for the standard header and\r
520 the extended data passed into this function. The standard header is filled\r
521 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported\r
522 with a zero instance and a caller ID of gEfiCallerIdGuid.\r
523\r
524 ReportStatusCodeWithExtendedData()must actively prevent recursion. If\r
525 ReportStatusCodeWithExtendedData() is called while processing another any other\r
526 Report Status Code Library function, then ReportStatusCodeWithExtendedData()\r
527 must return EFI_DEVICE_ERROR immediately.\r
528\r
529 If ExtendedData is NULL, then ASSERT().\r
530 If ExtendedDataSize is 0, then ASSERT().\r
531\r
532 @param Type Status code type.\r
533 @param Value Status code value.\r
534 @param ExtendedData Pointer to the extended data buffer to be reported.\r
535 @param ExtendedDataSize The size, in bytes, of the extended data buffer to\r
536 be reported.\r
537\r
538 @retval EFI_SUCCESS The status code was reported with the extended\r
539 data specified by ExtendedData and ExtendedDataSize.\r
540 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r
541 extended data section.\r
542 @retval EFI_UNSUPPORTED Report status code is not supported\r
543\r
544**/\r
545EFI_STATUS\r
546EFIAPI\r
547ReportStatusCodeWithExtendedData (\r
548 IN EFI_STATUS_CODE_TYPE Type,\r
549 IN EFI_STATUS_CODE_VALUE Value,\r
550 IN CONST VOID *ExtendedData,\r
551 IN UINTN ExtendedDataSize\r
552 )\r
553{\r
554 ASSERT (ExtendedData != NULL);\r
555 ASSERT (ExtendedDataSize != 0);\r
556 return ReportStatusCodeEx (\r
557 Type,\r
558 Value,\r
559 0,\r
560 NULL,\r
561 NULL,\r
562 ExtendedData,\r
563 ExtendedDataSize\r
564 );\r
565}\r
566\r
567\r
568/**\r
569 Reports a status code with full parameters.\r
570\r
571 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
572 is 0, then an extended data buffer is not reported. If ExtendedData is not\r
573 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
574 ExtendedData is assumed not have the standard status code header, so this function\r
575 is responsible for allocating a buffer large enough for the standard header and\r
576 the extended data passed into this function. The standard header is filled in\r
577 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
578 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with\r
579 an instance specified by Instance and a caller ID specified by CallerId. If\r
580 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
581\r
582 ReportStatusCodeEx()must actively prevent recursion. If\r
583 ReportStatusCodeEx() is called while processing another any\r
584 other Report Status Code Library function, then\r
585 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
586\r
587 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
588 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
589\r
590 @param Type Status code type.\r
591 @param Value Status code value.\r
592 @param Instance Status code instance number.\r
593 @param CallerId Pointer to a GUID that identifies the caller of this\r
594 function. If this parameter is NULL, then a caller\r
595 ID of gEfiCallerIdGuid is used.\r
596 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
597 If this parameter is NULL, then a the status code\r
598 standard header is filled in with\r
599 gEfiStatusCodeSpecificDataGuid.\r
600 @param ExtendedData Pointer to the extended data buffer. This is an\r
601 optional parameter that may be NULL.\r
602 @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
603\r
604 @retval EFI_SUCCESS The status code was reported.\r
605 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
606 the extended data section if it was specified.\r
607 @retval EFI_UNSUPPORTED Report status code is not supported\r
608\r
609**/\r
610EFI_STATUS\r
611EFIAPI\r
612ReportStatusCodeEx (\r
613 IN EFI_STATUS_CODE_TYPE Type,\r
614 IN EFI_STATUS_CODE_VALUE Value,\r
615 IN UINT32 Instance,\r
616 IN CONST EFI_GUID *CallerId OPTIONAL,\r
617 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
618 IN CONST VOID *ExtendedData OPTIONAL,\r
619 IN UINTN ExtendedDataSize\r
620 )\r
621{\r
622 EFI_STATUS Status;\r
4adf0008 623 EFI_STATUS_CODE_DATA *StatusCodeData;\r
e5c1acc5 624 UINT64 StatusCodeBuffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1];\r
30c8ee5c 625\r
626 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
627 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
628\r
c22f52c5
MK
629 if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
630 //\r
631 // Use Buffer instead of allocating if possible.\r
632 //\r
633 StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;\r
634 } else {\r
635 if (mHaveExitedBootServices) {\r
4adf0008 636 return EFI_OUT_OF_RESOURCES;\r
637 }\r
c22f52c5 638\r
4adf0008 639 if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
640 return EFI_UNSUPPORTED;\r
641 }\r
d1102dba 642\r
4adf0008 643 //\r
644 // Allocate space for the Status Code Header and its buffer\r
645 //\r
646 StatusCodeData = NULL;\r
647 gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
648 if (StatusCodeData == NULL) {\r
649 return EFI_OUT_OF_RESOURCES;\r
650 }\r
30c8ee5c 651 }\r
652\r
653 //\r
654 // Fill in the extended data header\r
655 //\r
c9325700
ED
656 StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r
657 StatusCodeData->Size = (UINT16) ExtendedDataSize;\r
30c8ee5c 658 if (ExtendedDataGuid == NULL) {\r
659 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
660 }\r
4adf0008 661 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r
30c8ee5c 662\r
663 //\r
664 // Fill in the extended data buffer\r
665 //\r
666 if (ExtendedData != NULL) {\r
4adf0008 667 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
30c8ee5c 668 }\r
669\r
670 //\r
671 // Report the status code\r
672 //\r
673 if (CallerId == NULL) {\r
674 CallerId = &gEfiCallerIdGuid;\r
675 }\r
4adf0008 676 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r
677\r
678 //\r
679 // Free the allocated buffer\r
680 //\r
c22f52c5 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
688\r
689/**\r
690 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled\r
691\r
692 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED\r
693 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
694\r
695 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r
696 PcdReportStatusCodeProperyMask is set.\r
697 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r
698 PcdReportStatusCodeProperyMask is clear.\r
699\r
700**/\r
701BOOLEAN\r
702EFIAPI\r
703ReportProgressCodeEnabled (\r
704 VOID\r
705 )\r
706{\r
707 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
708}\r
709\r
710\r
711/**\r
712 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled\r
713\r
714 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED\r
715 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
716\r
717 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r
718 PcdReportStatusCodeProperyMask is set.\r
719 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r
720 PcdReportStatusCodeProperyMask is clear.\r
721\r
722**/\r
723BOOLEAN\r
724EFIAPI\r
725ReportErrorCodeEnabled (\r
726 VOID\r
727 )\r
728{\r
729 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
730}\r
731\r
732\r
733/**\r
734 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled\r
735\r
736 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED\r
737 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
738\r
739 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r
740 PcdReportStatusCodeProperyMask is set.\r
741 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r
742 PcdReportStatusCodeProperyMask is clear.\r
743\r
744**/\r
745BOOLEAN\r
746EFIAPI\r
747ReportDebugCodeEnabled (\r
748 VOID\r
749 )\r
750{\r
751 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
752}\r