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