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