]>
Commit | Line | Data |
---|---|---|
ad1a1798 | 1 | /** @file\r |
2 | Data Hub status code worker in DXE.\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 | |
13 | Module Name: DataHubStatusCodeWorker.c\r | |
14 | \r | |
15 | **/\r | |
16 | //\r | |
17 | // Include common header file for this module.\r | |
18 | //\r | |
19 | #include "CommonHeader.h"\r | |
20 | \r | |
21 | #include "DxeStatusCode.h"\r | |
22 | \r | |
23 | //\r | |
24 | // Initialize FIFO to cache records.\r | |
25 | //\r | |
26 | STATIC\r | |
27 | LIST_ENTRY mRecordsFifo = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo);\r | |
28 | STATIC\r | |
29 | LIST_ENTRY mRecordsBuffer = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer);\r | |
30 | STATIC\r | |
31 | EFI_EVENT mLogDataHubEvent;\r | |
32 | //\r | |
33 | // Cache data hub protocol.\r | |
34 | //\r | |
35 | STATIC\r | |
36 | EFI_DATA_HUB_PROTOCOL *mDataHubProtocol;\r | |
37 | \r | |
38 | \r | |
39 | /**\r | |
40 | Return one DATAHUB_STATUSCODE_RECORD space.\r | |
41 | The size of free record pool would be extend, if the pool is empty.\r | |
42 | \r | |
43 | \r | |
44 | @retval NULL Can not allocate free memeory for record.\r | |
45 | @retval !NULL Point to buffer of record.\r | |
46 | \r | |
47 | **/\r | |
48 | STATIC\r | |
49 | DATAHUB_STATUSCODE_RECORD *\r | |
50 | AcquireRecordBuffer (\r | |
51 | VOID\r | |
52 | )\r | |
53 | {\r | |
54 | DATAHUB_STATUSCODE_RECORD *Record;\r | |
55 | EFI_TPL CurrentTpl;\r | |
56 | LIST_ENTRY *Node;\r | |
57 | UINT32 Index;\r | |
58 | \r | |
59 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
60 | \r | |
61 | if (!IsListEmpty (&mRecordsBuffer)) {\r | |
62 | Node = GetFirstNode (&mRecordsBuffer);\r | |
63 | RemoveEntryList (Node);\r | |
64 | \r | |
65 | Record = _CR (Node, DATAHUB_STATUSCODE_RECORD, Node);\r | |
66 | } else {\r | |
67 | if (CurrentTpl > TPL_NOTIFY) {\r | |
68 | gBS->RestoreTPL (CurrentTpl);\r | |
69 | return NULL;\r | |
70 | }\r | |
71 | \r | |
72 | gBS->RestoreTPL (CurrentTpl);\r | |
73 | Record = (DATAHUB_STATUSCODE_RECORD *) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD) * 16);\r | |
74 | if (NULL == Record) {\r | |
75 | return NULL;\r | |
76 | }\r | |
77 | \r | |
78 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
79 | for (Index = 1; Index < 16; Index++) {\r | |
80 | InsertTailList (&mRecordsBuffer, &Record[Index].Node);\r | |
81 | }\r | |
82 | }\r | |
83 | \r | |
84 | Record->Signature = DATAHUB_STATUS_CODE_SIGNATURE;\r | |
85 | InsertTailList (&mRecordsFifo, &Record->Node);\r | |
86 | \r | |
87 | gBS->RestoreTPL (CurrentTpl);\r | |
88 | \r | |
89 | return Record;\r | |
90 | }\r | |
91 | \r | |
92 | \r | |
93 | /**\r | |
94 | Retrieve one record from Records FIFO. The record would be removed from FIFO and\r | |
95 | release to free record buffer.\r | |
96 | \r | |
97 | @return !NULL Point to record, which is ready to be logged.\r | |
98 | @return NULL the FIFO of record is empty.\r | |
99 | \r | |
100 | **/\r | |
101 | STATIC\r | |
102 | DATAHUB_STATUSCODE_RECORD *\r | |
103 | RetrieveRecord (\r | |
104 | VOID\r | |
105 | )\r | |
106 | {\r | |
107 | DATAHUB_STATUSCODE_RECORD *Record = NULL;\r | |
108 | LIST_ENTRY *Node;\r | |
109 | EFI_TPL CurrentTpl;\r | |
110 | \r | |
111 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
112 | \r | |
113 | if (!IsListEmpty (&mRecordsFifo)) {\r | |
114 | Node = GetFirstNode (&mRecordsFifo);\r | |
115 | Record = CR (Node, DATAHUB_STATUSCODE_RECORD, Node, DATAHUB_STATUS_CODE_SIGNATURE);\r | |
116 | \r | |
117 | RemoveEntryList (&Record->Node);\r | |
118 | InsertTailList (&mRecordsBuffer, &Record->Node);\r | |
119 | Record->Signature = 0;\r | |
120 | }\r | |
121 | \r | |
122 | gBS->RestoreTPL (CurrentTpl);\r | |
123 | \r | |
124 | return Record;\r | |
125 | }\r | |
126 | \r | |
127 | \r | |
128 | /**\r | |
129 | Report status code into DataHub.\r | |
130 | \r | |
131 | @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r | |
132 | \r | |
133 | @param Value Describes the current status of a hardware or software entity.\r | |
134 | This included information about the class and subclass that is used to classify the entity\r | |
135 | as well as an operation. For progress codes, the operation is the current activity.\r | |
136 | For error codes, it is the exception. For debug codes, it is not defined at this time.\r | |
137 | Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.\r | |
138 | Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r | |
139 | \r | |
140 | @param Instance The enumeration of a hardware or software entity within the system.\r | |
141 | A system may contain multiple entities that match a class/subclass pairing.\r | |
142 | The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,\r | |
143 | not meaningful, or not relevant. Valid instance numbers start with 1.\r | |
144 | \r | |
145 | \r | |
146 | @param CallerId This optional parameter may be used to identify the caller.\r | |
147 | This parameter allows the status code driver to apply different rules to different callers.\r | |
148 | Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r | |
149 | \r | |
150 | \r | |
151 | @param Data This optional parameter may be used to pass additional data\r | |
152 | \r | |
153 | @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.\r | |
154 | @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .\r | |
155 | @retval EFI_SUCCESS Success to cache status code and signal log data event.\r | |
156 | \r | |
157 | **/\r | |
158 | EFI_STATUS\r | |
159 | DataHubStatusCodeReportWorker (\r | |
160 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
161 | IN EFI_STATUS_CODE_VALUE Value,\r | |
162 | IN UINT32 Instance,\r | |
163 | IN EFI_GUID *CallerId,\r | |
164 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
165 | )\r | |
166 | {\r | |
167 | DATAHUB_STATUSCODE_RECORD *Record;\r | |
168 | UINT32 ErrorLevel;\r | |
169 | VA_LIST Marker;\r | |
170 | CHAR8 *Format;\r | |
171 | UINTN CharCount;\r | |
172 | \r | |
173 | //\r | |
174 | // See whether in runtime phase or not.\r | |
175 | //\r | |
176 | if (EfiAtRuntime ()) {\r | |
177 | return EFI_DEVICE_ERROR;\r | |
178 | }\r | |
179 | \r | |
180 | Record = AcquireRecordBuffer ();\r | |
181 | if (Record == NULL) {\r | |
182 | //\r | |
183 | // There are no empty record buffer in private buffers\r | |
184 | //\r | |
185 | return EFI_OUT_OF_RESOURCES;\r | |
186 | }\r | |
187 | //\r | |
188 | // Construct Data Hub Extended Data\r | |
189 | //\r | |
190 | Record->CodeType = CodeType;\r | |
191 | Record->Value = Value;\r | |
192 | Record->Instance = Instance;\r | |
193 | \r | |
194 | if (CallerId != NULL) {\r | |
195 | CopyMem (&Record->CallerId, CallerId, sizeof (EFI_GUID));\r | |
196 | }\r | |
197 | \r | |
198 | if (Data != NULL) {\r | |
199 | if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r | |
200 | CharCount = UnicodeVSPrintAsciiFormat (\r | |
201 | (CHAR16 *) Record->ExtendData,\r | |
202 | EFI_STATUS_CODE_DATA_MAX_SIZE,\r | |
203 | Format,\r | |
204 | Marker\r | |
205 | );\r | |
206 | //\r | |
207 | // Change record data type from DebugType to String Type.\r | |
208 | //\r | |
209 | CopyGuid (&Record->Data.Type, &gEfiStatusCodeDataTypeStringGuid);\r | |
210 | Record->Data.HeaderSize = Data->HeaderSize;\r | |
211 | Record->Data.Size = (UINT16) ((CharCount + 1) * sizeof (CHAR16));\r | |
212 | } else {\r | |
213 | //\r | |
214 | // Copy status code data header\r | |
215 | //\r | |
216 | CopyMem (&Record->Data, Data, sizeof (EFI_STATUS_CODE_DATA));\r | |
217 | \r | |
218 | if (Data->Size > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r | |
219 | Record->Data.Size = EFI_STATUS_CODE_DATA_MAX_SIZE;\r | |
220 | }\r | |
221 | CopyMem (Record->ExtendData, Data + 1, Record->Data.Size);\r | |
222 | }\r | |
223 | }\r | |
224 | \r | |
225 | gBS->SignalEvent (mLogDataHubEvent);\r | |
226 | \r | |
227 | return EFI_SUCCESS;\r | |
228 | }\r | |
229 | \r | |
230 | \r | |
231 | /**\r | |
232 | The Event handler which will be notified to log data in Data Hub.\r | |
233 | \r | |
234 | @param Event Instance of the EFI_EVENT to signal whenever data is\r | |
235 | available to be logged in the system.\r | |
236 | @param Context Context of the event.\r | |
237 | \r | |
238 | **/\r | |
239 | STATIC\r | |
240 | VOID\r | |
241 | EFIAPI\r | |
242 | LogDataHubEventCallBack (\r | |
243 | IN EFI_EVENT Event,\r | |
244 | IN VOID *Context\r | |
245 | )\r | |
246 | {\r | |
247 | DATAHUB_STATUSCODE_RECORD *Record;\r | |
248 | UINT32 Size;\r | |
249 | UINT64 DataRecordClass;\r | |
250 | \r | |
251 | //\r | |
252 | // Log DataRecord in Data Hub.\r | |
253 | // Journal records fifo to find all record entry.\r | |
254 | //\r | |
255 | while (1) {\r | |
256 | Record = RetrieveRecord ();\r | |
257 | if (Record == NULL) {\r | |
258 | break;\r | |
259 | }\r | |
260 | //\r | |
261 | // Add in the size of the header we added.\r | |
262 | //\r | |
263 | Size = sizeof (DATAHUB_STATUSCODE_RECORD) + (UINT32) Record->Data.Size;\r | |
264 | \r | |
265 | if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r | |
266 | DataRecordClass = EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
267 | } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r | |
268 | DataRecordClass = EFI_DATA_RECORD_CLASS_ERROR;\r | |
269 | } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r | |
270 | DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG;\r | |
271 | } else {\r | |
272 | //\r | |
273 | // Should never get here.\r | |
274 | //\r | |
275 | DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG |\r | |
276 | EFI_DATA_RECORD_CLASS_ERROR |\r | |
277 | EFI_DATA_RECORD_CLASS_DATA |\r | |
278 | EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
279 | }\r | |
280 | \r | |
281 | //\r | |
282 | // Log DataRecord in Data Hub\r | |
283 | //\r | |
284 | \r | |
285 | mDataHubProtocol->LogData (\r | |
286 | mDataHubProtocol,\r | |
287 | &gEfiStatusCodeGuid,\r | |
288 | &gEfiStatusCodeRuntimeProtocolGuid,\r | |
289 | DataRecordClass,\r | |
290 | Record,\r | |
291 | Size\r | |
292 | );\r | |
293 | \r | |
294 | }\r | |
295 | }\r | |
296 | \r | |
297 | \r | |
298 | /**\r | |
299 | Initialize data hubstatus code.\r | |
300 | Create a data hub listener.\r | |
301 | \r | |
302 | @return The function always return EFI_SUCCESS\r | |
303 | \r | |
304 | **/\r | |
305 | EFI_STATUS\r | |
306 | DataHubStatusCodeInitializeWorker (\r | |
307 | VOID\r | |
308 | )\r | |
309 | {\r | |
310 | EFI_STATUS Status;\r | |
311 | \r | |
312 | Status = gBS->LocateProtocol (\r | |
313 | &gEfiDataHubProtocolGuid, \r | |
314 | NULL, \r | |
315 | (VOID **) &mDataHubProtocol\r | |
316 | );\r | |
317 | ASSERT_EFI_ERROR (Status);\r | |
318 | \r | |
319 | //\r | |
320 | // Create a Notify Event to log data in Data Hub\r | |
321 | //\r | |
322 | Status = gBS->CreateEvent (\r | |
323 | EVT_NOTIFY_SIGNAL,\r | |
324 | TPL_CALLBACK,\r | |
325 | LogDataHubEventCallBack,\r | |
326 | NULL,\r | |
327 | &mLogDataHubEvent\r | |
328 | );\r | |
329 | \r | |
330 | ASSERT_EFI_ERROR (Status);\r | |
331 | \r | |
332 | return EFI_SUCCESS;\r | |
333 | }\r | |
334 | \r | |
335 | \r |