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