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