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