3 Serial I/O status code reporting worker.
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 Module Name: SerialStatusCodeWorker.c
19 // Include common header file for this module.
21 #include "CommonHeader.h"
23 #include "DxeStatusCode.h"
26 EFI_SERIAL_IO_PROTOCOL
*mSerialIoProtocol
;
29 Initialize serial status code worker.
31 @return The function always return EFI_SUCCESS
35 EfiSerialStatusCodeInitializeWorker (
41 Status
= gBS
->LocateProtocol (
42 &gEfiSerialIoProtocolGuid
,
44 (VOID
**) &mSerialIoProtocol
47 ASSERT_EFI_ERROR (Status
);
54 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
56 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
58 @param Value Describes the current status of a hardware or software entity.
59 This included information about the class and subclass that is used to classify the entity
60 as well as an operation. For progress codes, the operation is the current activity.
61 For error codes, it is the exception. For debug codes, it is not defined at this time.
62 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
63 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
65 @param Instance The enumeration of a hardware or software entity within the system.
66 A system may contain multiple entities that match a class/subclass pairing.
67 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
68 not meaningful, or not relevant. Valid instance numbers start with 1.
71 @param CallerId This optional parameter may be used to identify the caller.
72 This parameter allows the status code driver to apply different rules to different callers.
73 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
76 @param Data This optional parameter may be used to pass additional data
78 @retval EFI_SUCCESS Success to report status code to serial I/O.
79 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
83 SerialStatusCodeReportWorker (
84 IN EFI_STATUS_CODE_TYPE CodeType
,
85 IN EFI_STATUS_CODE_VALUE Value
,
87 IN EFI_GUID
*CallerId
,
88 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
94 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
99 EFI_DEBUG_INFO
*DebugInfo
;
103 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial
)) {
104 if (EfiAtRuntime ()) {
105 return EFI_DEVICE_ERROR
;
107 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
108 gBS
->RestoreTPL (CurrentTpl
);
110 if (CurrentTpl
> TPL_CALLBACK
) {
111 return EFI_DEVICE_ERROR
;
118 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
120 // Print ASSERT() information into output buffer.
122 CharCount
= AsciiSPrint (
124 EFI_STATUS_CODE_DATA_MAX_SIZE
,
125 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
130 } else if (Data
!= NULL
&&
131 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
133 // Print DEBUG() information into output buffer.
135 CharCount
= AsciiVSPrint (
137 EFI_STATUS_CODE_DATA_MAX_SIZE
,
141 } else if (Data
!= NULL
&&
142 CompareGuid (&Data
->Type
, &gEfiStatusCodeSpecificDataGuid
) &&
143 (CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
145 // Print specific data into output buffer.
147 DebugInfo
= (EFI_DEBUG_INFO
*) (Data
+ 1);
148 Marker
= (VA_LIST
) (DebugInfo
+ 1);
149 Format
= (CHAR8
*) (((UINT64
*) Marker
) + 12);
151 CharCount
= AsciiVSPrint (Buffer
, EFI_STATUS_CODE_DATA_MAX_SIZE
, Format
, Marker
);
152 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
154 // Print ERROR information into output buffer.
156 CharCount
= AsciiSPrint (
158 EFI_STATUS_CODE_DATA_MAX_SIZE
,
159 "ERROR: C%x:V%x I%x",
166 // Make sure we don't try to print values that weren't
167 // intended to be printed, especially NULL GUID pointers.
170 if (CallerId
!= NULL
) {
171 CharCount
+= AsciiSPrint (
172 &Buffer
[CharCount
- 1],
173 (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
)),
188 CharCount
+= AsciiSPrint (
189 &Buffer
[CharCount
- 1],
190 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
193 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
194 CharCount
= AsciiSPrint (
196 EFI_STATUS_CODE_DATA_MAX_SIZE
,
197 "PROGRESS CODE: V%x I%x\n\r",
202 CharCount
= AsciiSPrint (
204 EFI_STATUS_CODE_DATA_MAX_SIZE
,
205 "Undefined: C%x:V%x I%x\n\r",
213 if (FeaturePcdGet (PcdStatusCodeUseHardSerial
)) {
215 // Callout to SerialPort Lib function to do print.
217 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
219 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial
)) {
220 mSerialIoProtocol
->Write (