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