]>
Commit | Line | Data |
---|---|---|
28a94112 | 1 | /** @file\r |
2 | Data Hub status code worker.\r | |
3 | \r | |
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | 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 | **/\r | |
14 | \r | |
15 | #include "DatahubStatusCodeHandlerDxe.h"\r | |
16 | \r | |
17 | //\r | |
18 | // Initialize FIFO to cache records.\r | |
19 | //\r | |
20 | LIST_ENTRY mRecordsFifo = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo);\r | |
21 | LIST_ENTRY mRecordsBuffer = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer);\r | |
22 | UINT32 mLogDataHubStatus = 0;\r | |
23 | EFI_EVENT mLogDataHubEvent;\r | |
24 | //\r | |
25 | // Cache data hub protocol.\r | |
26 | //\r | |
27 | EFI_DATA_HUB_PROTOCOL *mDataHubProtocol = NULL;\r | |
28 | \r | |
29 | \r | |
30 | /**\r | |
31 | Retrieve one record of from free record buffer. This record is removed from\r | |
32 | free record buffer.\r | |
33 | \r | |
34 | This function retrieves one record from free record buffer.\r | |
35 | If the pool has been exhausted, then new memory would be allocated for it.\r | |
36 | \r | |
37 | @return Pointer to the free record.\r | |
38 | NULL means failure to allocate new memeory for free record buffer.\r | |
39 | \r | |
40 | **/\r | |
41 | DATA_HUB_STATUS_CODE_DATA_RECORD *\r | |
42 | AcquireRecordBuffer (\r | |
43 | VOID\r | |
44 | )\r | |
45 | {\r | |
46 | DATAHUB_STATUSCODE_RECORD *Record;\r | |
47 | EFI_TPL CurrentTpl;\r | |
48 | LIST_ENTRY *Node;\r | |
49 | UINT32 Index;\r | |
50 | \r | |
51 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
52 | \r | |
53 | if (!IsListEmpty (&mRecordsBuffer)) {\r | |
54 | //\r | |
55 | // Strip one entry from free record buffer.\r | |
56 | //\r | |
57 | Node = GetFirstNode (&mRecordsBuffer);\r | |
58 | RemoveEntryList (Node);\r | |
59 | \r | |
60 | Record = BASE_CR (Node, DATAHUB_STATUSCODE_RECORD, Node);\r | |
61 | } else {\r | |
62 | if (CurrentTpl > TPL_NOTIFY) {\r | |
63 | //\r | |
64 | // Memory management should work at <=TPL_NOTIFY\r | |
65 | // \r | |
66 | gBS->RestoreTPL (CurrentTpl);\r | |
67 | return NULL;\r | |
68 | }\r | |
69 | \r | |
70 | //\r | |
71 | // If free record buffer is exhausted, then allocate 16 new records for it.\r | |
72 | //\r | |
73 | gBS->RestoreTPL (CurrentTpl);\r | |
74 | Record = (DATAHUB_STATUSCODE_RECORD *) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD) * 16);\r | |
75 | if (Record == NULL) {\r | |
76 | return NULL;\r | |
77 | }\r | |
78 | \r | |
79 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
80 | //\r | |
81 | // Here we only insert 15 new records to the free record buffer, for the first record\r | |
82 | // will be returned immediately.\r | |
83 | //\r | |
84 | for (Index = 1; Index < 16; Index++) {\r | |
85 | InsertTailList (&mRecordsBuffer, &Record[Index].Node);\r | |
86 | }\r | |
87 | }\r | |
88 | \r | |
89 | Record->Signature = DATAHUB_STATUS_CODE_SIGNATURE;\r | |
90 | InsertTailList (&mRecordsFifo, &Record->Node);\r | |
91 | \r | |
92 | gBS->RestoreTPL (CurrentTpl);\r | |
93 | \r | |
94 | return (DATA_HUB_STATUS_CODE_DATA_RECORD *) (Record->Data);\r | |
95 | }\r | |
96 | \r | |
97 | \r | |
98 | /**\r | |
99 | Retrieve one record from Records FIFO. The record would be removed from FIFO.\r | |
100 | \r | |
101 | @return Point to record, which is ready to be logged.\r | |
102 | NULL means the FIFO of record is empty.\r | |
103 | \r | |
104 | **/\r | |
105 | DATA_HUB_STATUS_CODE_DATA_RECORD *\r | |
106 | RetrieveRecord (\r | |
107 | VOID\r | |
108 | )\r | |
109 | {\r | |
110 | DATA_HUB_STATUS_CODE_DATA_RECORD *RecordData;\r | |
111 | DATAHUB_STATUSCODE_RECORD *Record;\r | |
112 | LIST_ENTRY *Node;\r | |
113 | EFI_TPL CurrentTpl;\r | |
114 | \r | |
115 | RecordData = NULL;\r | |
116 | \r | |
117 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
118 | \r | |
119 | if (!IsListEmpty (&mRecordsFifo)) {\r | |
120 | Node = GetFirstNode (&mRecordsFifo);\r | |
121 | Record = CR (Node, DATAHUB_STATUSCODE_RECORD, Node, DATAHUB_STATUS_CODE_SIGNATURE);\r | |
122 | ASSERT (Record != NULL);\r | |
123 | \r | |
124 | RemoveEntryList (&Record->Node);\r | |
125 | RecordData = (DATA_HUB_STATUS_CODE_DATA_RECORD *) Record->Data;\r | |
126 | }\r | |
127 | \r | |
128 | gBS->RestoreTPL (CurrentTpl);\r | |
129 | \r | |
130 | return RecordData;\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
134 | Release given record and return it to free record buffer.\r | |
135 | \r | |
136 | @param RecordData Pointer to the record to release.\r | |
137 | \r | |
138 | **/\r | |
139 | VOID\r | |
140 | ReleaseRecord (\r | |
141 | DATA_HUB_STATUS_CODE_DATA_RECORD *RecordData\r | |
142 | )\r | |
143 | {\r | |
144 | DATAHUB_STATUSCODE_RECORD *Record;\r | |
145 | EFI_TPL CurrentTpl;\r | |
146 | \r | |
147 | Record = CR (RecordData, DATAHUB_STATUSCODE_RECORD, Data[0], DATAHUB_STATUS_CODE_SIGNATURE);\r | |
148 | ASSERT (Record != NULL);\r | |
149 | \r | |
150 | CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r | |
151 | \r | |
152 | InsertTailList (&mRecordsBuffer, &Record->Node);\r | |
153 | Record->Signature = 0;\r | |
154 | \r | |
155 | gBS->RestoreTPL (CurrentTpl);\r | |
156 | }\r | |
157 | \r | |
158 | /**\r | |
159 | Report status code into DataHub.\r | |
160 | \r | |
161 | @param CodeType Indicates the type of status code being reported.\r | |
162 | @param Value Describes the current status of a hardware or software entity.\r | |
163 | This included information about the class and subclass that is used to\r | |
164 | classify the entity as well as an operation.\r | |
165 | @param Instance The enumeration of a hardware or software entity within\r | |
166 | the system. Valid instance numbers start with 1.\r | |
167 | @param CallerId This optional parameter may be used to identify the caller.\r | |
168 | This parameter allows the status code driver to apply different rules to\r | |
169 | different callers.\r | |
170 | @param Data This optional parameter may be used to pass additional data.\r | |
171 | \r | |
172 | @retval EFI_SUCCESS The function completed successfully.\r | |
173 | @retval EFI_DEVICE_ERROR Function is reentered.\r | |
174 | @retval EFI_DEVICE_ERROR Function is called at runtime.\r | |
175 | @retval EFI_OUT_OF_RESOURCES Fail to allocate memory for free record buffer.\r | |
176 | \r | |
177 | **/\r | |
178 | EFI_STATUS\r | |
b61bb3b3 | 179 | EFIAPI\r |
28a94112 | 180 | DataHubStatusCodeReportWorker (\r |
181 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
182 | IN EFI_STATUS_CODE_VALUE Value,\r | |
183 | IN UINT32 Instance,\r | |
184 | IN EFI_GUID *CallerId,\r | |
185 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r | |
186 | )\r | |
187 | {\r | |
188 | DATA_HUB_STATUS_CODE_DATA_RECORD *Record;\r | |
189 | UINT32 ErrorLevel;\r | |
190 | BASE_LIST Marker;\r | |
191 | CHAR8 *Format;\r | |
192 | UINTN CharCount;\r | |
193 | \r | |
194 | //\r | |
195 | // Use atom operation to avoid the reentant of report.\r | |
196 | // If current status is not zero, then the function is reentrancy.\r | |
197 | //\r | |
198 | if (InterlockedCompareExchange32 (&mLogDataHubStatus, 0, 0) == 1) {\r | |
199 | return EFI_DEVICE_ERROR;\r | |
200 | }\r | |
201 | \r | |
202 | Record = AcquireRecordBuffer ();\r | |
203 | if (Record == NULL) {\r | |
204 | //\r | |
205 | // There are no empty record buffer in private buffers\r | |
206 | //\r | |
207 | return EFI_OUT_OF_RESOURCES;\r | |
208 | }\r | |
209 | \r | |
210 | //\r | |
211 | // Construct Data Hub Extended Data\r | |
212 | //\r | |
213 | Record->CodeType = CodeType;\r | |
214 | Record->Value = Value;\r | |
215 | Record->Instance = Instance;\r | |
216 | \r | |
217 | if (CallerId != NULL) {\r | |
218 | CopyMem (&Record->CallerId, CallerId, sizeof (EFI_GUID));\r | |
219 | }\r | |
220 | \r | |
221 | if (Data != NULL) {\r | |
222 | if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r | |
223 | CharCount = UnicodeBSPrintAsciiFormat (\r | |
224 | (CHAR16 *) (Record + 1),\r | |
225 | EFI_STATUS_CODE_DATA_MAX_SIZE,\r | |
226 | Format,\r | |
227 | Marker\r | |
228 | );\r | |
229 | //\r | |
230 | // Change record data type to DebugType.\r | |
231 | //\r | |
232 | CopyGuid (&Record->Data.Type, &gEfiStatusCodeDataTypeDebugGuid);\r | |
233 | Record->Data.HeaderSize = Data->HeaderSize;\r | |
234 | Record->Data.Size = (UINT16) ((CharCount + 1) * sizeof (CHAR16));\r | |
235 | } else {\r | |
236 | //\r | |
237 | // Copy status code data header\r | |
238 | //\r | |
239 | CopyMem (&Record->Data, Data, sizeof (EFI_STATUS_CODE_DATA));\r | |
240 | \r | |
241 | if (Data->Size > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r | |
242 | Record->Data.Size = EFI_STATUS_CODE_DATA_MAX_SIZE;\r | |
243 | }\r | |
244 | CopyMem ((VOID *) (Record + 1), Data + 1, Record->Data.Size);\r | |
245 | }\r | |
246 | }\r | |
247 | \r | |
248 | gBS->SignalEvent (mLogDataHubEvent);\r | |
249 | \r | |
250 | return EFI_SUCCESS;\r | |
251 | }\r | |
252 | \r | |
253 | \r | |
254 | /**\r | |
255 | The Event handler which will be notified to log data in Data Hub.\r | |
256 | \r | |
257 | @param Event Instance of the EFI_EVENT to signal whenever data is\r | |
258 | available to be logged in the system.\r | |
259 | @param Context Context of the event.\r | |
260 | \r | |
261 | **/\r | |
262 | VOID\r | |
263 | EFIAPI\r | |
264 | LogDataHubEventCallBack (\r | |
265 | IN EFI_EVENT Event,\r | |
266 | IN VOID *Context\r | |
267 | )\r | |
268 | {\r | |
269 | DATA_HUB_STATUS_CODE_DATA_RECORD *Record;\r | |
270 | UINT32 Size;\r | |
271 | UINT64 DataRecordClass;\r | |
272 | \r | |
273 | //\r | |
274 | // Use atom operation to avoid the reentant of report.\r | |
275 | // If current status is not zero, then the function is reentrancy.\r | |
276 | //\r | |
277 | if (InterlockedCompareExchange32 (&mLogDataHubStatus, 0, 1) == 1) {\r | |
278 | return;\r | |
279 | }\r | |
280 | \r | |
281 | //\r | |
282 | // Log DataRecord in Data Hub.\r | |
283 | // Journal records fifo to find all record entry.\r | |
284 | //\r | |
285 | while (TRUE) {\r | |
286 | //\r | |
287 | // Retrieve record from record FIFO until no more record can be retrieved.\r | |
288 | //\r | |
289 | Record = RetrieveRecord ();\r | |
290 | if (Record == NULL) {\r | |
291 | break;\r | |
292 | }\r | |
293 | //\r | |
294 | // Add in the size of the header we added.\r | |
295 | //\r | |
296 | Size = sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD) + (UINT32) Record->Data.Size;\r | |
297 | \r | |
298 | if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r | |
299 | DataRecordClass = EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
300 | } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r | |
301 | DataRecordClass = EFI_DATA_RECORD_CLASS_ERROR;\r | |
302 | } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r | |
303 | DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG;\r | |
304 | } else {\r | |
305 | //\r | |
306 | // Should never get here.\r | |
307 | //\r | |
308 | DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG |\r | |
309 | EFI_DATA_RECORD_CLASS_ERROR |\r | |
310 | EFI_DATA_RECORD_CLASS_DATA |\r | |
311 | EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
312 | }\r | |
313 | \r | |
314 | //\r | |
315 | // Log DataRecord in Data Hub\r | |
316 | //\r | |
317 | mDataHubProtocol->LogData (\r | |
318 | mDataHubProtocol,\r | |
319 | &gEfiDataHubStatusCodeRecordGuid,\r | |
320 | &gEfiStatusCodeRuntimeProtocolGuid,\r | |
321 | DataRecordClass,\r | |
322 | Record,\r | |
323 | Size\r | |
324 | );\r | |
325 | \r | |
326 | ReleaseRecord (Record);\r | |
327 | }\r | |
328 | \r | |
329 | //\r | |
330 | // Restore the nest status of report\r | |
331 | //\r | |
332 | InterlockedCompareExchange32 (&mLogDataHubStatus, 1, 0);\r | |
333 | }\r | |
334 | \r | |
335 | \r | |
336 | /**\r | |
337 | Locate Data Hub Protocol and create event for logging data\r | |
338 | as initialization for data hub status code worker.\r | |
339 | \r | |
340 | @retval EFI_SUCCESS Initialization is successful.\r | |
341 | \r | |
342 | **/\r | |
343 | EFI_STATUS\r | |
344 | DataHubStatusCodeInitializeWorker (\r | |
345 | VOID\r | |
346 | )\r | |
347 | {\r | |
348 | EFI_STATUS Status;\r | |
349 | \r | |
350 | Status = gBS->LocateProtocol (\r | |
351 | &gEfiDataHubProtocolGuid, \r | |
352 | NULL, \r | |
353 | (VOID **) &mDataHubProtocol\r | |
354 | );\r | |
355 | if (EFI_ERROR (Status)) {\r | |
356 | mDataHubProtocol = NULL;\r | |
357 | return Status;\r | |
358 | }\r | |
359 | \r | |
360 | //\r | |
361 | // Create a Notify Event to log data in Data Hub\r | |
362 | //\r | |
363 | Status = gBS->CreateEvent (\r | |
364 | EVT_NOTIFY_SIGNAL,\r | |
365 | TPL_CALLBACK,\r | |
366 | LogDataHubEventCallBack,\r | |
367 | NULL,\r | |
368 | &mLogDataHubEvent\r | |
369 | );\r | |
370 | \r | |
371 | ASSERT_EFI_ERROR (Status);\r | |
372 | \r | |
373 | return EFI_SUCCESS;\r | |
374 | }\r | |
375 | \r | |
376 | \r |