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