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