2 Serial I/O status code reporting worker.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. 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
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.
15 #include "DxeStatusCode.h"
16 #include "DebugInfo.h"
18 EFI_SERIAL_IO_PROTOCOL
*mSerialIoProtocol
;
21 Initialize serial status code worker.
23 @return The function always return EFI_SUCCESS
27 EfiSerialStatusCodeInitializeWorker (
33 Status
= gBS
->LocateProtocol (
34 &gEfiSerialIoProtocolGuid
,
36 (VOID
**) &mSerialIoProtocol
39 ASSERT_EFI_ERROR (Status
);
46 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
48 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
50 @param Value Describes the current status of a hardware or software entity.
51 This included information about the class and subclass that is used to classify the entity
52 as well as an operation. For progress codes, the operation is the current activity.
53 For error codes, it is the exception. For debug codes, it is not defined at this time.
54 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
55 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
57 @param Instance The enumeration of a hardware or software entity within the system.
58 A system may contain multiple entities that match a class/subclass pairing.
59 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
60 not meaningful, or not relevant. Valid instance numbers start with 1.
63 @param CallerId This optional parameter may be used to identify the caller.
64 This parameter allows the status code driver to apply different rules to different callers.
65 Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
68 @param Data This optional parameter may be used to pass additional data
70 @retval EFI_SUCCESS Success to report status code to serial I/O.
71 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
75 SerialStatusCodeReportWorker (
76 IN EFI_STATUS_CODE_TYPE CodeType
,
77 IN EFI_STATUS_CODE_VALUE Value
,
79 IN EFI_GUID
*CallerId
,
80 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
86 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
91 EFI_DEBUG_INFO
*DebugInfo
;
95 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial
)) {
96 if (EfiAtRuntime ()) {
97 return EFI_DEVICE_ERROR
;
99 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
100 gBS
->RestoreTPL (CurrentTpl
);
102 if (CurrentTpl
> TPL_CALLBACK
) {
103 return EFI_DEVICE_ERROR
;
110 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
112 // Print ASSERT() information into output buffer.
114 CharCount
= AsciiSPrint (
116 EFI_STATUS_CODE_DATA_MAX_SIZE
,
117 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
122 } else if (Data
!= NULL
&&
123 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
125 // Print DEBUG() information into output buffer.
127 CharCount
= AsciiVSPrint (
129 EFI_STATUS_CODE_DATA_MAX_SIZE
,
133 } else if (Data
!= NULL
&&
134 CompareGuid (&Data
->Type
, &gEfiStatusCodeSpecificDataGuid
) &&
135 (CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
137 // Print specific data into output buffer.
139 DebugInfo
= (EFI_DEBUG_INFO
*) (Data
+ 1);
140 Marker
= (VA_LIST
) (DebugInfo
+ 1);
141 Format
= (CHAR8
*) (((UINT64
*) Marker
) + 12);
143 CharCount
= AsciiVSPrint (Buffer
, EFI_STATUS_CODE_DATA_MAX_SIZE
, Format
, Marker
);
144 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
146 // Print ERROR information into output buffer.
148 CharCount
= AsciiSPrint (
150 EFI_STATUS_CODE_DATA_MAX_SIZE
,
151 "ERROR: C%x:V%x I%x",
158 // Make sure we don't try to print values that weren't
159 // intended to be printed, especially NULL GUID pointers.
162 if (CallerId
!= NULL
) {
163 CharCount
+= AsciiSPrint (
164 &Buffer
[CharCount
- 1],
165 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
172 CharCount
+= AsciiSPrint (
173 &Buffer
[CharCount
- 1],
174 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
180 CharCount
+= AsciiSPrint (
181 &Buffer
[CharCount
- 1],
182 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
185 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
186 CharCount
= AsciiSPrint (
188 EFI_STATUS_CODE_DATA_MAX_SIZE
,
189 "PROGRESS CODE: V%x I%x\n\r",
194 CharCount
= AsciiSPrint (
196 EFI_STATUS_CODE_DATA_MAX_SIZE
,
197 "Undefined: C%x:V%x I%x\n\r",
205 if (FeaturePcdGet (PcdStatusCodeUseHardSerial
)) {
207 // Callout to SerialPort Lib function to do print.
209 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
211 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial
)) {
212 mSerialIoProtocol
->Write (