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