]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/StatusCode/Dxe/SerialStatusCodeWorker.c
Added the StatusCode protocol installation for the IPF architecture; removed the...
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / SerialStatusCodeWorker.c
CommitLineData
56836fe9 1\r
2/** @file\r
3 Serial I/O status code reporting worker.\r
4\r
161c26a7 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
56836fe9 13\r
14 Module Name: SerialStatusCodeWorker.c\r
15\r
16**/\r
17\r
a93763b7 18STATIC\r
19EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;\r
56836fe9 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
53408952 35 &gEfiSerialIoProtocolGuid,\r
36 NULL,\r
37 (VOID **) &mSerialIoProtocol\r
38 );\r
56836fe9 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
511710d6 49 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
56836fe9 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
511710d6 55 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. \r
56836fe9 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
a93763b7 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
56836fe9 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\r
a93763b7 94\r
95 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial) && EfiAtRuntime ()) {\r
96 return EFI_DEVICE_ERROR;\r
97 }\r
98\r
56836fe9 99 Buffer[0] = '\0';\r
100\r
101 if (Data != NULL &&\r
102 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
103 //\r
104 // Print ASSERT() information into output buffer.\r
105 //\r
106 CharCount = AsciiSPrint (\r
107 Buffer,\r
108 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
109 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",\r
110 Filename,\r
111 LineNumber,\r
112 Description\r
113 );\r
114 } else if (Data != NULL &&\r
115 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
116 //\r
117 // Print DEBUG() information into output buffer.\r
118 //\r
119 CharCount = AsciiVSPrint (\r
120 Buffer, \r
121 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
122 Format, \r
123 Marker\r
124 );\r
125 } else if (Data != NULL && \r
126 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
127 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
128 //\r
129 // Print specific data into output buffer.\r
130 //\r
131 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
132 Marker = (VA_LIST) (DebugInfo + 1);\r
133 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
134\r
135 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
136 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
137 //\r
138 // Print ERROR information into output buffer.\r
139 //\r
a93763b7 140 CharCount = AsciiSPrint (\r
141 Buffer, \r
142 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
143 "ERROR: C%x:V%x I%x", \r
144 CodeType, \r
145 Value, \r
146 Instance\r
147 );\r
56836fe9 148\r
149 //\r
a93763b7 150 // Make sure we don't try to print values that weren't \r
151 // intended to be printed, especially NULL GUID pointers.\r
56836fe9 152 //\r
153 \r
154 if (CallerId != NULL) {\r
155 CharCount += AsciiSPrint (\r
156 &Buffer[CharCount - 1],\r
157 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
158 " %g",\r
159 CallerId\r
160 );\r
161 }\r
162\r
a93763b7 163 if (Data != NULL) {\r
56836fe9 164 CharCount += AsciiSPrint (\r
165 &Buffer[CharCount - 1],\r
166 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
167 " %x",\r
168 Data\r
169 );\r
170 }\r
171\r
172 CharCount += AsciiSPrint (\r
173 &Buffer[CharCount - 1],\r
174 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
175 "\n\r"\r
176 );\r
177 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
a93763b7 178 CharCount = AsciiSPrint (\r
179 Buffer, \r
180 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
181 "PROGRESS CODE: V%x I%x\n\r", \r
182 Value, \r
183 Instance\r
184 );\r
56836fe9 185 } else {\r
a93763b7 186 CharCount = AsciiSPrint (\r
187 Buffer, \r
188 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
189 "Undefined: C%x:V%x I%x\n\r", \r
190 CodeType, \r
191 Value, \r
192 Instance\r
193 );\r
56836fe9 194 }\r
195\r
196\r
197 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {\r
198 //\r
199 // Callout to SerialPort Lib function to do print.\r
200 //\r
a8bcbf3d 201 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
56836fe9 202 }\r
203 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {\r
a93763b7 204 mSerialIoProtocol->Write (\r
205 mSerialIoProtocol,\r
56836fe9 206 &CharCount,\r
207 Buffer\r
208 );\r
209 }\r
210\r
211 return EFI_SUCCESS;\r
212}\r