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