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