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