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