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