1. add EdkSerialPortLibNull.inf
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Dxe / SerialStatusCodeWorker.c
1
2 /** @file
3 Serial I/O status code reporting worker.
4
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
10
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.
13
14 Module Name: SerialStatusCodeWorker.c
15
16 **/
17
18 //
19 // Include common header file for this module.
20 //
21 #include "CommonHeader.h"
22
23 #include "DxeStatusCode.h"
24
25 STATIC
26 EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;
27
28 /**
29 Initialize serial status code worker.
30
31 @return The function always return EFI_SUCCESS
32
33 **/
34 EFI_STATUS
35 EfiSerialStatusCodeInitializeWorker (
36 VOID
37 )
38 {
39 EFI_STATUS Status;
40
41 Status = gBS->LocateProtocol (
42 &gEfiSerialIoProtocolGuid,
43 NULL,
44 (VOID **) &mSerialIoProtocol
45 );
46
47 ASSERT_EFI_ERROR (Status);
48
49 return EFI_SUCCESS;
50 }
51
52
53 /**
54 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
55
56 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
57
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.
64
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.
69
70
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.
74
75
76 @param Data This optional parameter may be used to pass additional data
77
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 .
80
81 **/
82 EFI_STATUS
83 SerialStatusCodeReportWorker (
84 IN EFI_STATUS_CODE_TYPE CodeType,
85 IN EFI_STATUS_CODE_VALUE Value,
86 IN UINT32 Instance,
87 IN EFI_GUID *CallerId,
88 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
89 )
90 {
91 CHAR8 *Filename;
92 CHAR8 *Description;
93 CHAR8 *Format;
94 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
95 UINT32 ErrorLevel;
96 UINT32 LineNumber;
97 UINTN CharCount;
98 VA_LIST Marker;
99 EFI_DEBUG_INFO *DebugInfo;
100 EFI_TPL CurrentTpl;
101
102
103 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
104 if (EfiAtRuntime ()) {
105 return EFI_DEVICE_ERROR;
106 }
107 CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
108 gBS->RestoreTPL (CurrentTpl);
109
110 if (CurrentTpl > TPL_CALLBACK ) {
111 return EFI_DEVICE_ERROR;
112 }
113 }
114
115 Buffer[0] = '\0';
116
117 if (Data != NULL &&
118 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
119 //
120 // Print ASSERT() information into output buffer.
121 //
122 CharCount = AsciiSPrint (
123 Buffer,
124 EFI_STATUS_CODE_DATA_MAX_SIZE,
125 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
126 Filename,
127 LineNumber,
128 Description
129 );
130 } else if (Data != NULL &&
131 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
132 //
133 // Print DEBUG() information into output buffer.
134 //
135 CharCount = AsciiVSPrint (
136 Buffer,
137 EFI_STATUS_CODE_DATA_MAX_SIZE,
138 Format,
139 Marker
140 );
141 } else if (Data != NULL &&
142 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
143 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
144 //
145 // Print specific data into output buffer.
146 //
147 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
148 Marker = (VA_LIST) (DebugInfo + 1);
149 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
150
151 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
152 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
153 //
154 // Print ERROR information into output buffer.
155 //
156 CharCount = AsciiSPrint (
157 Buffer,
158 EFI_STATUS_CODE_DATA_MAX_SIZE,
159 "ERROR: C%x:V%x I%x",
160 CodeType,
161 Value,
162 Instance
163 );
164
165 //
166 // Make sure we don't try to print values that weren't
167 // intended to be printed, especially NULL GUID pointers.
168 //
169
170 if (CallerId != NULL) {
171 CharCount += AsciiSPrint (
172 &Buffer[CharCount - 1],
173 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
174 " %g",
175 CallerId
176 );
177 }
178
179 if (Data != NULL) {
180 CharCount += AsciiSPrint (
181 &Buffer[CharCount - 1],
182 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
183 " %x",
184 Data
185 );
186 }
187
188 CharCount += AsciiSPrint (
189 &Buffer[CharCount - 1],
190 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
191 "\n\r"
192 );
193 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
194 CharCount = AsciiSPrint (
195 Buffer,
196 EFI_STATUS_CODE_DATA_MAX_SIZE,
197 "PROGRESS CODE: V%x I%x\n\r",
198 Value,
199 Instance
200 );
201 } else {
202 CharCount = AsciiSPrint (
203 Buffer,
204 EFI_STATUS_CODE_DATA_MAX_SIZE,
205 "Undefined: C%x:V%x I%x\n\r",
206 CodeType,
207 Value,
208 Instance
209 );
210 }
211
212
213 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
214 //
215 // Callout to SerialPort Lib function to do print.
216 //
217 SerialPortWrite ((UINT8 *) Buffer, CharCount);
218 }
219 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
220 mSerialIoProtocol->Write (
221 mSerialIoProtocol,
222 &CharCount,
223 Buffer
224 );
225 }
226
227 return EFI_SUCCESS;
228 }