]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/StatusCode/Dxe/SerialStatusCodeWorker.c
Minor change for GenFv to support capsule attribute, GenSec to support guid header...
[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 **/
15
16 #include "DxeStatusCode.h"
17 #include "DebugInfo.h"
18
19 STATIC
20 EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;
21
22 /**
23 Initialize serial status code worker.
24
25 @return The function always return EFI_SUCCESS
26
27 **/
28 EFI_STATUS
29 EfiSerialStatusCodeInitializeWorker (
30 VOID
31 )
32 {
33 EFI_STATUS Status;
34
35 Status = gBS->LocateProtocol (
36 &gEfiSerialIoProtocolGuid,
37 NULL,
38 (VOID **) &mSerialIoProtocol
39 );
40
41 ASSERT_EFI_ERROR (Status);
42
43 return EFI_SUCCESS;
44 }
45
46
47 /**
48 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
49
50 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
51
52 @param Value Describes the current status of a hardware or software entity.
53 This included information about the class and subclass that is used to classify the entity
54 as well as an operation. For progress codes, the operation is the current activity.
55 For error codes, it is the exception. For debug codes, it is not defined at this time.
56 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
57 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
58
59 @param Instance The enumeration of a hardware or software entity within the system.
60 A system may contain multiple entities that match a class/subclass pairing.
61 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
62 not meaningful, or not relevant. Valid instance numbers start with 1.
63
64
65 @param CallerId This optional parameter may be used to identify the caller.
66 This parameter allows the status code driver to apply different rules to different callers.
67 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
68
69
70 @param Data This optional parameter may be used to pass additional data
71
72 @retval EFI_SUCCESS Success to report status code to serial I/O.
73 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
74
75 **/
76 EFI_STATUS
77 SerialStatusCodeReportWorker (
78 IN EFI_STATUS_CODE_TYPE CodeType,
79 IN EFI_STATUS_CODE_VALUE Value,
80 IN UINT32 Instance,
81 IN EFI_GUID *CallerId,
82 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
83 )
84 {
85 CHAR8 *Filename;
86 CHAR8 *Description;
87 CHAR8 *Format;
88 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
89 UINT32 ErrorLevel;
90 UINT32 LineNumber;
91 UINTN CharCount;
92 VA_LIST Marker;
93 EFI_DEBUG_INFO *DebugInfo;
94 EFI_TPL CurrentTpl;
95
96
97 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
98 if (EfiAtRuntime ()) {
99 return EFI_DEVICE_ERROR;
100 }
101 CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
102 gBS->RestoreTPL (CurrentTpl);
103
104 if (CurrentTpl > TPL_CALLBACK ) {
105 return EFI_DEVICE_ERROR;
106 }
107 }
108
109 Buffer[0] = '\0';
110
111 if (Data != NULL &&
112 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
113 //
114 // Print ASSERT() information into output buffer.
115 //
116 CharCount = AsciiSPrint (
117 Buffer,
118 EFI_STATUS_CODE_DATA_MAX_SIZE,
119 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
120 Filename,
121 LineNumber,
122 Description
123 );
124 } else if (Data != NULL &&
125 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
126 //
127 // Print DEBUG() information into output buffer.
128 //
129 CharCount = AsciiVSPrint (
130 Buffer,
131 EFI_STATUS_CODE_DATA_MAX_SIZE,
132 Format,
133 Marker
134 );
135 } else if (Data != NULL &&
136 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
137 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
138 //
139 // Print specific data into output buffer.
140 //
141 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
142 Marker = (VA_LIST) (DebugInfo + 1);
143 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
144
145 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
146 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
147 //
148 // Print ERROR information into output buffer.
149 //
150 CharCount = AsciiSPrint (
151 Buffer,
152 EFI_STATUS_CODE_DATA_MAX_SIZE,
153 "ERROR: C%x:V%x I%x",
154 CodeType,
155 Value,
156 Instance
157 );
158
159 //
160 // Make sure we don't try to print values that weren't
161 // intended to be printed, especially NULL GUID pointers.
162 //
163
164 if (CallerId != NULL) {
165 CharCount += AsciiSPrint (
166 &Buffer[CharCount - 1],
167 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
168 " %g",
169 CallerId
170 );
171 }
172
173 if (Data != NULL) {
174 CharCount += AsciiSPrint (
175 &Buffer[CharCount - 1],
176 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
177 " %x",
178 Data
179 );
180 }
181
182 CharCount += AsciiSPrint (
183 &Buffer[CharCount - 1],
184 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
185 "\n\r"
186 );
187 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
188 CharCount = AsciiSPrint (
189 Buffer,
190 EFI_STATUS_CODE_DATA_MAX_SIZE,
191 "PROGRESS CODE: V%x I%x\n\r",
192 Value,
193 Instance
194 );
195 } else {
196 CharCount = AsciiSPrint (
197 Buffer,
198 EFI_STATUS_CODE_DATA_MAX_SIZE,
199 "Undefined: C%x:V%x I%x\n\r",
200 CodeType,
201 Value,
202 Instance
203 );
204 }
205
206
207 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
208 //
209 // Callout to SerialPort Lib function to do print.
210 //
211 SerialPortWrite ((UINT8 *) Buffer, CharCount);
212 }
213 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
214 mSerialIoProtocol->Write (
215 mSerialIoProtocol,
216 &CharCount,
217 Buffer
218 );
219 }
220
221 return EFI_SUCCESS;
222 }