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