]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
Prevent infinite recursion when ASSERT(), DEBUG(), or any other use of ReportStatusCo...
[mirror_edk2.git] / MdeModulePkg / Library / DxeReportStatusCodeLib / ReportStatusCodeLib.c
CommitLineData
75dea6bd 1/** @file\r
2 Report Status Code Library for DXE Phase.\r
3\r
cd5ebaa0
HT
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
75dea6bd 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Library/ReportStatusCodeLib.h>\r
4adf0008 16#include <Library/BaseLib.h>\r
75dea6bd 17#include <Library/DebugLib.h>\r
18#include <Library/UefiBootServicesTableLib.h>\r
75dea6bd 19#include <Library/BaseMemoryLib.h>\r
75dea6bd 20#include <Library/PcdLib.h>\r
75dea6bd 21#include <Library/DevicePathLib.h>\r
22\r
4adf0008 23#include <Protocol/StatusCode.h>\r
24\r
75dea6bd 25#include <Guid/StatusCodeDataTypeId.h>\r
26#include <Guid/StatusCodeDataTypeDebug.h>\r
75dea6bd 27\r
c5e0de87 28//\r
29// Define the maximum extended data size that is supported when a status code is \r
30// reported at TPL_HIGH_LEVEL.\r
31//\r
32#define MAX_EXTENDED_DATA_SIZE 0x200\r
33\r
4adf0008 34EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;\r
75dea6bd 35\r
36/**\r
37 Locate the report status code service.\r
38\r
4adf0008 39 Retrieve ReportStatusCode() API of Report Status Code Protocol.\r
75dea6bd 40\r
41**/\r
4adf0008 42VOID\r
75dea6bd 43InternalGetReportStatusCode (\r
44 VOID\r
45 )\r
46{\r
4adf0008 47 EFI_STATUS Status;\r
75dea6bd 48\r
4adf0008 49 if (mReportStatusCodeLibStatusCodeProtocol != NULL) {\r
50 return;\r
51 }\r
52\r
53 //\r
54 // Check gBS just in case ReportStatusCode is called before gBS is initialized.\r
55 //\r
75dea6bd 56 if (gBS != NULL && gBS->LocateProtocol != NULL) {\r
4adf0008 57 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &mReportStatusCodeLibStatusCodeProtocol);\r
58 if (EFI_ERROR (Status)) {\r
59 mReportStatusCodeLibStatusCodeProtocol = NULL;\r
75dea6bd 60 }\r
61 }\r
75dea6bd 62}\r
63\r
64/**\r
4adf0008 65 Internal worker function that reports a status code through the Report Status Code Protocol.\r
75dea6bd 66\r
4adf0008 67 If status code service is not cached, then this function checks if Report Status Code\r
68 Protocol is available in system. If Report Status Code Protocol is not available, then\r
69 EFI_UNSUPPORTED is returned. If Report Status Code Protocol is present, then it is\r
70 cached in mReportStatusCodeLibStatusCodeProtocol. Finally this function reports status\r
71 code through the Report Status Code Protocol.\r
75dea6bd 72\r
73 @param Type Status code type.\r
74 @param Value Status code value.\r
75 @param Instance Status code instance number.\r
76 @param CallerId Pointer to a GUID that identifies the caller of this\r
77 function. This is an optional parameter that may be\r
78 NULL.\r
79 @param Data Pointer to the extended data buffer. This is an\r
80 optional parameter that may be NULL.\r
81\r
82 @retval EFI_SUCCESS The status code was reported.\r
4adf0008 83 @retval EFI_UNSUPPORTED Report Status Code Protocol is not available.\r
75dea6bd 84 @retval EFI_UNSUPPORTED Status code type is not supported.\r
85\r
86**/\r
87EFI_STATUS\r
88InternalReportStatusCode (\r
89 IN EFI_STATUS_CODE_TYPE Type,\r
90 IN EFI_STATUS_CODE_VALUE Value,\r
91 IN UINT32 Instance,\r
92 IN CONST EFI_GUID *CallerId OPTIONAL,\r
93 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
94 )\r
95{\r
96 if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
97 (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r
98 (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r
99 //\r
4adf0008 100 // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.\r
75dea6bd 101 //\r
4adf0008 102 InternalGetReportStatusCode ();\r
103 if (mReportStatusCodeLibStatusCodeProtocol == NULL) {\r
104 return EFI_UNSUPPORTED;\r
75dea6bd 105 }\r
4adf0008 106\r
75dea6bd 107 //\r
4adf0008 108 // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.\r
75dea6bd 109 //\r
4adf0008 110 return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
75dea6bd 111 }\r
112 \r
113 return EFI_UNSUPPORTED;\r
114}\r
115\r
116\r
117/**\r
118 Converts a status code to an 8-bit POST code value.\r
119\r
120 Converts the status code specified by CodeType and Value to an 8-bit POST code\r
121 and returns the 8-bit POST code in PostCode. If CodeType is an\r
122 EFI_PROGRESS_CODE or CodeType is an EFI_ERROR_CODE, then bits 0..4 of PostCode\r
123 are set to bits 16..20 of Value, and bits 5..7 of PostCode are set to bits\r
124 24..26 of Value., and TRUE is returned. Otherwise, FALSE is returned.\r
125\r
126 If PostCode is NULL, then ASSERT().\r
127\r
128 @param CodeType The type of status code being converted.\r
129 @param Value The status code value being converted.\r
130 @param PostCode A pointer to the 8-bit POST code value to return.\r
131\r
132 @retval TRUE The status code specified by CodeType and Value was converted\r
133 to an 8-bit POST code and returned in PostCode.\r
134 @retval FALSE The status code specified by CodeType and Value could not be\r
135 converted to an 8-bit POST code value.\r
136\r
137**/\r
138BOOLEAN\r
139EFIAPI\r
140CodeTypeToPostCode (\r
141 IN EFI_STATUS_CODE_TYPE CodeType,\r
142 IN EFI_STATUS_CODE_VALUE Value,\r
143 OUT UINT8 *PostCode\r
144 )\r
145{\r
146 //\r
147 // If PostCode is NULL, then ASSERT()\r
148 //\r
149 ASSERT (PostCode != NULL);\r
150\r
151 //\r
152 // Convert Value to an 8 bit post code\r
153 //\r
154 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
155 ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ) {\r
156 *PostCode = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |\r
157 (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));\r
158 return TRUE;\r
159 }\r
160 return FALSE;\r
161}\r
162\r
163\r
164/**\r
165 Extracts ASSERT() information from a status code structure.\r
166\r
167 Converts the status code specified by CodeType, Value, and Data to the ASSERT()\r
168 arguments specified by Filename, Description, and LineNumber. If CodeType is\r
169 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and\r
170 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract\r
171 Filename, Description, and LineNumber from the optional data area of the\r
172 status code buffer specified by Data. The optional data area of Data contains\r
173 a Null-terminated ASCII string for the FileName, followed by a Null-terminated\r
174 ASCII string for the Description, followed by a 32-bit LineNumber. If the\r
175 ASSERT() information could be extracted from Data, then return TRUE.\r
176 Otherwise, FALSE is returned.\r
177\r
178 If Data is NULL, then ASSERT().\r
179 If Filename is NULL, then ASSERT().\r
180 If Description is NULL, then ASSERT().\r
181 If LineNumber is NULL, then ASSERT().\r
182\r
183 @param CodeType The type of status code being converted.\r
184 @param Value The status code value being converted.\r
185 @param Data Pointer to status code data buffer.\r
186 @param Filename Pointer to the source file name that generated the ASSERT().\r
187 @param Description Pointer to the description of the ASSERT().\r
188 @param LineNumber Pointer to source line number that generated the ASSERT().\r
189\r
190 @retval TRUE The status code specified by CodeType, Value, and Data was\r
191 converted ASSERT() arguments specified by Filename, Description,\r
192 and LineNumber.\r
193 @retval FALSE The status code specified by CodeType, Value, and Data could\r
194 not be converted to ASSERT() arguments.\r
195\r
196**/\r
197BOOLEAN\r
198EFIAPI\r
199ReportStatusCodeExtractAssertInfo (\r
200 IN EFI_STATUS_CODE_TYPE CodeType,\r
201 IN EFI_STATUS_CODE_VALUE Value,\r
202 IN CONST EFI_STATUS_CODE_DATA *Data,\r
203 OUT CHAR8 **Filename,\r
204 OUT CHAR8 **Description,\r
205 OUT UINT32 *LineNumber\r
206 )\r
207{\r
208 EFI_DEBUG_ASSERT_DATA *AssertData;\r
209\r
210 ASSERT (Data != NULL);\r
211 ASSERT (Filename != NULL);\r
212 ASSERT (Description != NULL);\r
213 ASSERT (LineNumber != NULL);\r
214\r
215 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&\r
216 ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&\r
217 ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {\r
218 AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
219 *Filename = (CHAR8 *)(AssertData + 1);\r
220 *Description = *Filename + AsciiStrLen (*Filename) + 1;\r
221 *LineNumber = AssertData->LineNumber;\r
222 return TRUE;\r
223 }\r
224 return FALSE;\r
225}\r
226\r
227\r
228/**\r
229 Extracts DEBUG() information from a status code structure.\r
230\r
231 Converts the status code specified by Data to the DEBUG() arguments specified\r
232 by ErrorLevel, Marker, and Format. If type GUID in Data is\r
233 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and\r
234 Format from the optional data area of the status code buffer specified by Data.\r
235 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker\r
236 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for\r
237 the Format. If the DEBUG() information could be extracted from Data, then\r
238 return TRUE. Otherwise, FALSE is returned.\r
239\r
240 If Data is NULL, then ASSERT().\r
241 If ErrorLevel is NULL, then ASSERT().\r
242 If Marker is NULL, then ASSERT().\r
243 If Format is NULL, then ASSERT().\r
244\r
245 @param Data Pointer to status code data buffer.\r
246 @param ErrorLevel Pointer to error level mask for a debug message.\r
247 @param Marker Pointer to the variable argument list associated with Format.\r
248 @param Format Pointer to a Null-terminated ASCII format string of a\r
249 debug message.\r
250\r
251 @retval TRUE The status code specified by Data was converted DEBUG() arguments\r
252 specified by ErrorLevel, Marker, and Format.\r
253 @retval FALSE The status code specified by Data could not be converted to\r
254 DEBUG() arguments.\r
255\r
256**/\r
257BOOLEAN\r
258EFIAPI\r
259ReportStatusCodeExtractDebugInfo (\r
260 IN CONST EFI_STATUS_CODE_DATA *Data,\r
261 OUT UINT32 *ErrorLevel,\r
262 OUT BASE_LIST *Marker,\r
263 OUT CHAR8 **Format\r
264 )\r
265{\r
266 EFI_DEBUG_INFO *DebugInfo;\r
267\r
268 ASSERT (Data != NULL);\r
269 ASSERT (ErrorLevel != NULL);\r
270 ASSERT (Marker != NULL);\r
271 ASSERT (Format != NULL);\r
272\r
273 //\r
274 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE\r
275 //\r
276 if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r
277 return FALSE;\r
278 }\r
279\r
280 //\r
281 // Retrieve the debug information from the status code record\r
282 //\r
283 DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r
284\r
285 *ErrorLevel = DebugInfo->ErrorLevel;\r
286\r
287 //\r
288 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
289 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r
290 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r
291 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r
292 // returned is 64-bit aligned.\r
293 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r
294 // cause unalignment exception.\r
295 //\r
296 *Marker = (BASE_LIST) (DebugInfo + 1);\r
297 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
298\r
299 return TRUE;\r
300}\r
301\r
302\r
303/**\r
304 Reports a status code.\r
305\r
306 Reports the status code specified by the parameters Type and Value. Status\r
307 code also require an instance, caller ID, and extended data. This function\r
308 passed in a zero instance, NULL extended data, and a caller ID of\r
309 gEfiCallerIdGuid, which is the GUID for the module.\r
310\r
311 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()\r
312 is called while processing another any other Report Status Code Library function,\r
313 then ReportStatusCode() must return immediately.\r
314\r
315 @param Type Status code type.\r
316 @param Value Status code value.\r
317\r
318 @retval EFI_SUCCESS The status code was reported.\r
319 @retval EFI_DEVICE_ERROR There status code could not be reported due to a\r
320 device error.\r
321 @retval EFI_UNSUPPORTED Report status code is not supported\r
322\r
323**/\r
324EFI_STATUS\r
325EFIAPI\r
326ReportStatusCode (\r
327 IN EFI_STATUS_CODE_TYPE Type,\r
328 IN EFI_STATUS_CODE_VALUE Value\r
329 )\r
330{\r
331 return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);\r
332}\r
333\r
334\r
335/**\r
336 Reports a status code with a Device Path Protocol as the extended data.\r
337\r
338 Allocates and fills in the extended data section of a status code with the\r
339 Device Path Protocol specified by DevicePath. This function is responsible\r
340 for allocating a buffer large enough for the standard header and the device\r
341 path. The standard header is filled in with a GUID of\r
342 gEfiStatusCodeSpecificDataGuid. The status code is reported with a zero\r
343 instance and a caller ID of gEfiCallerIdGuid.\r
344\r
345 ReportStatusCodeWithDevicePath()must actively prevent recursion. If\r
346 ReportStatusCodeWithDevicePath() is called while processing another any other\r
347 Report Status Code Library function, then ReportStatusCodeWithDevicePath()\r
348 must return EFI_DEVICE_ERROR immediately.\r
349\r
350 If DevicePath is NULL, then ASSERT().\r
351\r
352 @param Type Status code type.\r
353 @param Value Status code value.\r
354 @param DevicePath Pointer to the Device Path Protocol to be reported.\r
355\r
356 @retval EFI_SUCCESS The status code was reported with the extended\r
357 data specified by DevicePath.\r
358 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r
359 extended data section.\r
360 @retval EFI_UNSUPPORTED Report status code is not supported\r
361\r
362**/\r
363EFI_STATUS\r
364EFIAPI\r
365ReportStatusCodeWithDevicePath (\r
366 IN EFI_STATUS_CODE_TYPE Type,\r
367 IN EFI_STATUS_CODE_VALUE Value,\r
368 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
369 )\r
370{\r
371 ASSERT (DevicePath != NULL);\r
372 return ReportStatusCodeWithExtendedData (\r
373 Type,\r
374 Value,\r
375 (VOID *)DevicePath,\r
376 GetDevicePathSize (DevicePath)\r
377 );\r
378}\r
379\r
380\r
381/**\r
382 Reports a status code with an extended data buffer.\r
383\r
384 Allocates and fills in the extended data section of a status code with the\r
385 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData\r
386 is assumed to be one of the data structures specified in Related Definitions.\r
387 These data structure do not have the standard header, so this function is\r
388 responsible for allocating a buffer large enough for the standard header and\r
389 the extended data passed into this function. The standard header is filled\r
390 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported\r
391 with a zero instance and a caller ID of gEfiCallerIdGuid.\r
392\r
393 ReportStatusCodeWithExtendedData()must actively prevent recursion. If\r
394 ReportStatusCodeWithExtendedData() is called while processing another any other\r
395 Report Status Code Library function, then ReportStatusCodeWithExtendedData()\r
396 must return EFI_DEVICE_ERROR immediately.\r
397\r
398 If ExtendedData is NULL, then ASSERT().\r
399 If ExtendedDataSize is 0, then ASSERT().\r
400\r
401 @param Type Status code type.\r
402 @param Value Status code value.\r
403 @param ExtendedData Pointer to the extended data buffer to be reported.\r
404 @param ExtendedDataSize The size, in bytes, of the extended data buffer to\r
405 be reported.\r
406\r
407 @retval EFI_SUCCESS The status code was reported with the extended\r
408 data specified by ExtendedData and ExtendedDataSize.\r
409 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the\r
410 extended data section.\r
411 @retval EFI_UNSUPPORTED Report status code is not supported\r
412\r
413**/\r
414EFI_STATUS\r
415EFIAPI\r
416ReportStatusCodeWithExtendedData (\r
417 IN EFI_STATUS_CODE_TYPE Type,\r
418 IN EFI_STATUS_CODE_VALUE Value,\r
419 IN CONST VOID *ExtendedData,\r
420 IN UINTN ExtendedDataSize\r
421 )\r
422{\r
423 ASSERT (ExtendedData != NULL);\r
424 ASSERT (ExtendedDataSize != 0);\r
425 return ReportStatusCodeEx (\r
426 Type,\r
427 Value,\r
428 0,\r
429 NULL,\r
430 NULL,\r
431 ExtendedData,\r
432 ExtendedDataSize\r
433 );\r
434}\r
435\r
436\r
437/**\r
438 Reports a status code with full parameters.\r
439\r
440 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
441 is 0, then an extended data buffer is not reported. If ExtendedData is not\r
442 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
443 ExtendedData is assumed not have the standard status code header, so this function\r
444 is responsible for allocating a buffer large enough for the standard header and\r
445 the extended data passed into this function. The standard header is filled in\r
446 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
447 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with\r
448 an instance specified by Instance and a caller ID specified by CallerId. If\r
449 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
450\r
451 ReportStatusCodeEx()must actively prevent recursion. If\r
452 ReportStatusCodeEx() is called while processing another any\r
453 other Report Status Code Library function, then\r
454 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
455\r
456 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
457 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
458\r
459 @param Type Status code type.\r
460 @param Value Status code value.\r
461 @param Instance Status code instance number.\r
462 @param CallerId Pointer to a GUID that identifies the caller of this\r
463 function. If this parameter is NULL, then a caller\r
464 ID of gEfiCallerIdGuid is used.\r
465 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
466 If this parameter is NULL, then a the status code\r
467 standard header is filled in with\r
468 gEfiStatusCodeSpecificDataGuid.\r
469 @param ExtendedData Pointer to the extended data buffer. This is an\r
470 optional parameter that may be NULL.\r
471 @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
472\r
473 @retval EFI_SUCCESS The status code was reported.\r
474 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
475 the extended data section if it was specified.\r
476 @retval EFI_UNSUPPORTED Report status code is not supported\r
477\r
478**/\r
479EFI_STATUS\r
480EFIAPI\r
481ReportStatusCodeEx (\r
482 IN EFI_STATUS_CODE_TYPE Type,\r
483 IN EFI_STATUS_CODE_VALUE Value,\r
484 IN UINT32 Instance,\r
485 IN CONST EFI_GUID *CallerId OPTIONAL,\r
486 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
487 IN CONST VOID *ExtendedData OPTIONAL,\r
488 IN UINTN ExtendedDataSize\r
489 )\r
490{\r
491 EFI_STATUS Status;\r
492 EFI_STATUS_CODE_DATA *StatusCodeData;\r
c5e0de87 493 EFI_TPL Tpl;\r
494 UINT64 Buffer[MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)];\r
75dea6bd 495\r
496 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
497 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
498\r
499 if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
500 return EFI_UNSUPPORTED;\r
501 }\r
502\r
503 //\r
c5e0de87 504 // Retrieve the current TPL\r
75dea6bd 505 //\r
c5e0de87 506 Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
507 gBS->RestoreTPL (Tpl);\r
508 \r
75dea6bd 509 StatusCodeData = NULL;\r
c5e0de87 510 if (Tpl <= TPL_NOTIFY) {\r
511 //\r
512 // Allocate space for the Status Code Header and its buffer\r
513 //\r
514 gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
515 }\r
516\r
75dea6bd 517 if (StatusCodeData == NULL) {\r
c5e0de87 518 //\r
519 // If a buffer could not be allocated, then see if the local variable Buffer can be used\r
520 //\r
521 if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
522 //\r
523 // The local variable Buffer not large enough to hold the extended data associated\r
524 // with the status code being reported.\r
525 //\r
526 ASSERT (FALSE);\r
527 return EFI_OUT_OF_RESOURCES;\r
528 }\r
529 StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;\r
75dea6bd 530 }\r
531\r
532 //\r
533 // Fill in the extended data header\r
534 //\r
c9325700
ED
535 StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r
536 StatusCodeData->Size = (UINT16) ExtendedDataSize;\r
75dea6bd 537 if (ExtendedDataGuid == NULL) {\r
538 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
539 }\r
540 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r
541\r
542 //\r
543 // Fill in the extended data buffer\r
544 //\r
545 if (ExtendedData != NULL) {\r
546 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
547 }\r
548\r
549 //\r
550 // Report the status code\r
551 //\r
552 if (CallerId == NULL) {\r
553 CallerId = &gEfiCallerIdGuid;\r
554 }\r
555 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r
556\r
557 //\r
558 // Free the allocated buffer\r
559 //\r
c5e0de87 560 if (StatusCodeData != (EFI_STATUS_CODE_DATA *)Buffer) {\r
561 gBS->FreePool (StatusCodeData);\r
562 }\r
75dea6bd 563\r
564 return Status;\r
565}\r
566\r
567\r
568/**\r
569 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled\r
570\r
571 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED\r
572 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
573\r
574 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r
575 PcdReportStatusCodeProperyMask is set.\r
576 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of\r
577 PcdReportStatusCodeProperyMask is clear.\r
578\r
579**/\r
580BOOLEAN\r
581EFIAPI\r
582ReportProgressCodeEnabled (\r
583 VOID\r
584 )\r
585{\r
586 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
587}\r
588\r
589\r
590/**\r
591 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled\r
592\r
593 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED\r
594 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
595\r
596 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r
597 PcdReportStatusCodeProperyMask is set.\r
598 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of\r
599 PcdReportStatusCodeProperyMask is clear.\r
600\r
601**/\r
602BOOLEAN\r
603EFIAPI\r
604ReportErrorCodeEnabled (\r
605 VOID\r
606 )\r
607{\r
608 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
609}\r
610\r
611\r
612/**\r
613 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled\r
614\r
615 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED\r
616 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.\r
617\r
618 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r
619 PcdReportStatusCodeProperyMask is set.\r
620 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of\r
621 PcdReportStatusCodeProperyMask is clear.\r
622\r
623**/\r
624BOOLEAN\r
625EFIAPI\r
626ReportDebugCodeEnabled (\r
627 VOID\r
628 )\r
629{\r
630 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
631}\r