]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
1. Introduced CPU Exception Handler Library to provide the CPU exception handlers...
[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 - 2011, 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 EFI_EVENT mReportStatusCodeLibExitBootServicesEvent;
33 BOOLEAN mHaveExitedBootServices = FALSE;
34
35 /**
36 Locate the report status code service.
37
38 Retrieve ReportStatusCode() API of Report Status Code Protocol.
39
40 **/
41 VOID
42 InternalGetReportStatusCode (
43 VOID
44 )
45 {
46 EFI_STATUS Status;
47
48 if (mReportStatusCodeLibStatusCodeProtocol != NULL) {
49 return;
50 }
51
52 if (mHaveExitedBootServices) {
53 return;
54 }
55
56 //
57 // Check gBS just in case ReportStatusCode is called before gBS is initialized.
58 //
59 if (gBS != NULL && gBS->LocateProtocol != NULL) {
60 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &mReportStatusCodeLibStatusCodeProtocol);
61 if (EFI_ERROR (Status)) {
62 mReportStatusCodeLibStatusCodeProtocol = NULL;
63 }
64 }
65 }
66
67 /**
68 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
69
70 @param Event Event whose notification function is being invoked.
71 @param Context Pointer to the notification function's context
72
73 **/
74 VOID
75 EFIAPI
76 ReportStatusCodeLibVirtualAddressChange (
77 IN EFI_EVENT Event,
78 IN VOID *Context
79 )
80 {
81 if (mReportStatusCodeLibStatusCodeProtocol == NULL) {
82 return;
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 // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.
232 //
233 InternalGetReportStatusCode ();
234 if (mReportStatusCodeLibStatusCodeProtocol == NULL) {
235 return EFI_UNSUPPORTED;
236 }
237
238 //
239 // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.
240 //
241 return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
242 }
243
244 return EFI_UNSUPPORTED;
245 }
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 *PostCode = (UINT8) ((((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5) |
288 (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));
289 return TRUE;
290 }
291 return FALSE;
292 }
293
294
295 /**
296 Extracts ASSERT() information from a status code structure.
297
298 Converts the status code specified by CodeType, Value, and Data to the ASSERT()
299 arguments specified by Filename, Description, and LineNumber. If CodeType is
300 an EFI_ERROR_CODE, and CodeType has a severity of EFI_ERROR_UNRECOVERED, and
301 Value has an operation mask of EFI_SW_EC_ILLEGAL_SOFTWARE_STATE, extract
302 Filename, Description, and LineNumber from the optional data area of the
303 status code buffer specified by Data. The optional data area of Data contains
304 a Null-terminated ASCII string for the FileName, followed by a Null-terminated
305 ASCII string for the Description, followed by a 32-bit LineNumber. If the
306 ASSERT() information could be extracted from Data, then return TRUE.
307 Otherwise, FALSE is returned.
308
309 If Data is NULL, then ASSERT().
310 If Filename is NULL, then ASSERT().
311 If Description is NULL, then ASSERT().
312 If LineNumber is NULL, then ASSERT().
313
314 @param CodeType The type of status code being converted.
315 @param Value The status code value being converted.
316 @param Data Pointer to status code data buffer.
317 @param Filename Pointer to the source file name that generated the ASSERT().
318 @param Description Pointer to the description of the ASSERT().
319 @param LineNumber Pointer to source line number that generated the ASSERT().
320
321 @retval TRUE The status code specified by CodeType, Value, and Data was
322 converted ASSERT() arguments specified by Filename, Description,
323 and LineNumber.
324 @retval FALSE The status code specified by CodeType, Value, and Data could
325 not be converted to ASSERT() arguments.
326
327 **/
328 BOOLEAN
329 EFIAPI
330 ReportStatusCodeExtractAssertInfo (
331 IN EFI_STATUS_CODE_TYPE CodeType,
332 IN EFI_STATUS_CODE_VALUE Value,
333 IN CONST EFI_STATUS_CODE_DATA *Data,
334 OUT CHAR8 **Filename,
335 OUT CHAR8 **Description,
336 OUT UINT32 *LineNumber
337 )
338 {
339 EFI_DEBUG_ASSERT_DATA *AssertData;
340
341 ASSERT (Data != NULL);
342 ASSERT (Filename != NULL);
343 ASSERT (Description != NULL);
344 ASSERT (LineNumber != NULL);
345
346 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) &&
347 ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED) &&
348 ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE)) {
349 AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);
350 *Filename = (CHAR8 *)(AssertData + 1);
351 *Description = *Filename + AsciiStrLen (*Filename) + 1;
352 *LineNumber = AssertData->LineNumber;
353 return TRUE;
354 }
355 return FALSE;
356 }
357
358
359 /**
360 Extracts DEBUG() information from a status code structure.
361
362 Converts the status code specified by Data to the DEBUG() arguments specified
363 by ErrorLevel, Marker, and Format. If type GUID in Data is
364 EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID, then extract ErrorLevel, Marker, and
365 Format from the optional data area of the status code buffer specified by Data.
366 The optional data area of Data contains a 32-bit ErrorLevel followed by Marker
367 which is 12 UINTN parameters, followed by a Null-terminated ASCII string for
368 the Format. If the DEBUG() information could be extracted from Data, then
369 return TRUE. Otherwise, FALSE is returned.
370
371 If Data is NULL, then ASSERT().
372 If ErrorLevel is NULL, then ASSERT().
373 If Marker is NULL, then ASSERT().
374 If Format is NULL, then ASSERT().
375
376 @param Data Pointer to status code data buffer.
377 @param ErrorLevel Pointer to error level mask for a debug message.
378 @param Marker Pointer to the variable argument list associated with Format.
379 @param Format Pointer to a Null-terminated ASCII format string of a
380 debug message.
381
382 @retval TRUE The status code specified by Data was converted DEBUG() arguments
383 specified by ErrorLevel, Marker, and Format.
384 @retval FALSE The status code specified by Data could not be converted to
385 DEBUG() arguments.
386
387 **/
388 BOOLEAN
389 EFIAPI
390 ReportStatusCodeExtractDebugInfo (
391 IN CONST EFI_STATUS_CODE_DATA *Data,
392 OUT UINT32 *ErrorLevel,
393 OUT BASE_LIST *Marker,
394 OUT CHAR8 **Format
395 )
396 {
397 EFI_DEBUG_INFO *DebugInfo;
398
399 ASSERT (Data != NULL);
400 ASSERT (ErrorLevel != NULL);
401 ASSERT (Marker != NULL);
402 ASSERT (Format != NULL);
403
404 //
405 // If the GUID type is not EFI_STATUS_CODE_DATA_TYPE_DEBUG_GUID then return FALSE
406 //
407 if (!CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid)) {
408 return FALSE;
409 }
410
411 //
412 // Retrieve the debug information from the status code record
413 //
414 DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);
415
416 *ErrorLevel = DebugInfo->ErrorLevel;
417
418 //
419 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments
420 // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.
421 // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is
422 // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker
423 // returned is 64-bit aligned.
424 // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will
425 // cause unalignment exception.
426 //
427 *Marker = (BASE_LIST) (DebugInfo + 1);
428 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);
429
430 return TRUE;
431 }
432
433
434 /**
435 Reports a status code.
436
437 Reports the status code specified by the parameters Type and Value. Status
438 code also require an instance, caller ID, and extended data. This function
439 passed in a zero instance, NULL extended data, and a caller ID of
440 gEfiCallerIdGuid, which is the GUID for the module.
441
442 ReportStatusCode()must actively prevent recusrsion. If ReportStatusCode()
443 is called while processing another any other Report Status Code Library function,
444 then ReportStatusCode() must return immediately.
445
446 @param Type Status code type.
447 @param Value Status code value.
448
449 @retval EFI_SUCCESS The status code was reported.
450 @retval EFI_DEVICE_ERROR There status code could not be reported due to a
451 device error.
452 @retval EFI_UNSUPPORTED Report status code is not supported
453
454 **/
455 EFI_STATUS
456 EFIAPI
457 ReportStatusCode (
458 IN EFI_STATUS_CODE_TYPE Type,
459 IN EFI_STATUS_CODE_VALUE Value
460 )
461 {
462 return InternalReportStatusCode (Type, Value, 0, &gEfiCallerIdGuid, NULL);
463 }
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 /**
513 Reports a status code with an extended data buffer.
514
515 Allocates and fills in the extended data section of a status code with the
516 extended data specified by ExtendedData and ExtendedDataSize. ExtendedData
517 is assumed to be one of the data structures specified in Related Definitions.
518 These data structure do not have the standard header, so this function is
519 responsible for allocating a buffer large enough for the standard header and
520 the extended data passed into this function. The standard header is filled
521 in with a GUID of gEfiStatusCodeSpecificDataGuid. The status code is reported
522 with a zero instance and a caller ID of gEfiCallerIdGuid.
523
524 ReportStatusCodeWithExtendedData()must actively prevent recursion. If
525 ReportStatusCodeWithExtendedData() is called while processing another any other
526 Report Status Code Library function, then ReportStatusCodeWithExtendedData()
527 must return EFI_DEVICE_ERROR immediately.
528
529 If ExtendedData is NULL, then ASSERT().
530 If ExtendedDataSize is 0, then ASSERT().
531
532 @param Type Status code type.
533 @param Value Status code value.
534 @param ExtendedData Pointer to the extended data buffer to be reported.
535 @param ExtendedDataSize The size, in bytes, of the extended data buffer to
536 be reported.
537
538 @retval EFI_SUCCESS The status code was reported with the extended
539 data specified by ExtendedData and ExtendedDataSize.
540 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate the
541 extended data section.
542 @retval EFI_UNSUPPORTED Report status code is not supported
543
544 **/
545 EFI_STATUS
546 EFIAPI
547 ReportStatusCodeWithExtendedData (
548 IN EFI_STATUS_CODE_TYPE Type,
549 IN EFI_STATUS_CODE_VALUE Value,
550 IN CONST VOID *ExtendedData,
551 IN UINTN ExtendedDataSize
552 )
553 {
554 ASSERT (ExtendedData != NULL);
555 ASSERT (ExtendedDataSize != 0);
556 return ReportStatusCodeEx (
557 Type,
558 Value,
559 0,
560 NULL,
561 NULL,
562 ExtendedData,
563 ExtendedDataSize
564 );
565 }
566
567
568 /**
569 Reports a status code with full parameters.
570
571 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
572 is 0, then an extended data buffer is not reported. If ExtendedData is not
573 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
574 ExtendedData is assumed not have the standard status code header, so this function
575 is responsible for allocating a buffer large enough for the standard header and
576 the extended data passed into this function. The standard header is filled in
577 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
578 GUID of gEfiStatusCodeSpecificDataGuid is used. The status code is reported with
579 an instance specified by Instance and a caller ID specified by CallerId. If
580 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
581
582 ReportStatusCodeEx()must actively prevent recursion. If
583 ReportStatusCodeEx() is called while processing another any
584 other Report Status Code Library function, then
585 ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
586
587 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
588 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
589
590 @param Type Status code type.
591 @param Value Status code value.
592 @param Instance Status code instance number.
593 @param CallerId Pointer to a GUID that identifies the caller of this
594 function. If this parameter is NULL, then a caller
595 ID of gEfiCallerIdGuid is used.
596 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
597 If this parameter is NULL, then a the status code
598 standard header is filled in with
599 gEfiStatusCodeSpecificDataGuid.
600 @param ExtendedData Pointer to the extended data buffer. This is an
601 optional parameter that may be NULL.
602 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
603
604 @retval EFI_SUCCESS The status code was reported.
605 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
606 the extended data section if it was specified.
607 @retval EFI_UNSUPPORTED Report status code is not supported
608
609 **/
610 EFI_STATUS
611 EFIAPI
612 ReportStatusCodeEx (
613 IN EFI_STATUS_CODE_TYPE Type,
614 IN EFI_STATUS_CODE_VALUE Value,
615 IN UINT32 Instance,
616 IN CONST EFI_GUID *CallerId OPTIONAL,
617 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,
618 IN CONST VOID *ExtendedData OPTIONAL,
619 IN UINTN ExtendedDataSize
620 )
621 {
622 EFI_STATUS Status;
623 EFI_STATUS_CODE_DATA *StatusCodeData;
624 UINT8 StatusCodeBuffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
625
626 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
627 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
628
629 if (mHaveExitedBootServices) {
630 if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {
631 return EFI_OUT_OF_RESOURCES;
632 }
633 StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer;
634 } else {
635 if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {
636 return EFI_UNSUPPORTED;
637 }
638
639 //
640 // Allocate space for the Status Code Header and its buffer
641 //
642 StatusCodeData = NULL;
643 gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
644 if (StatusCodeData == NULL) {
645 return EFI_OUT_OF_RESOURCES;
646 }
647 }
648
649 //
650 // Fill in the extended data header
651 //
652 StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);
653 StatusCodeData->Size = (UINT16) ExtendedDataSize;
654 if (ExtendedDataGuid == NULL) {
655 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
656 }
657 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
658
659 //
660 // Fill in the extended data buffer
661 //
662 if (ExtendedData != NULL) {
663 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
664 }
665
666 //
667 // Report the status code
668 //
669 if (CallerId == NULL) {
670 CallerId = &gEfiCallerIdGuid;
671 }
672 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
673
674 //
675 // Free the allocated buffer
676 //
677 if (!mHaveExitedBootServices) {
678 gBS->FreePool (StatusCodeData);
679 }
680
681 return Status;
682 }
683
684
685 /**
686 Returns TRUE if status codes of type EFI_PROGRESS_CODE are enabled
687
688 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED
689 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
690
691 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
692 PcdReportStatusCodeProperyMask is set.
693 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED bit of
694 PcdReportStatusCodeProperyMask is clear.
695
696 **/
697 BOOLEAN
698 EFIAPI
699 ReportProgressCodeEnabled (
700 VOID
701 )
702 {
703 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);
704 }
705
706
707 /**
708 Returns TRUE if status codes of type EFI_ERROR_CODE are enabled
709
710 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED
711 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
712
713 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
714 PcdReportStatusCodeProperyMask is set.
715 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED bit of
716 PcdReportStatusCodeProperyMask is clear.
717
718 **/
719 BOOLEAN
720 EFIAPI
721 ReportErrorCodeEnabled (
722 VOID
723 )
724 {
725 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);
726 }
727
728
729 /**
730 Returns TRUE if status codes of type EFI_DEBUG_CODE are enabled
731
732 This function returns TRUE if the REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED
733 bit of PcdReportStatusCodeProperyMask is set. Otherwise FALSE is returned.
734
735 @retval TRUE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
736 PcdReportStatusCodeProperyMask is set.
737 @retval FALSE The REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED bit of
738 PcdReportStatusCodeProperyMask is clear.
739
740 **/
741 BOOLEAN
742 EFIAPI
743 ReportDebugCodeEnabled (
744 VOID
745 )
746 {
747 return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);
748 }