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