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