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