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