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