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