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