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