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