2 Data Hub status code worker in DXE.
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
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.
15 #include "DxeStatusCode.h"
18 // Initialize FIFO to cache records.
21 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
23 LIST_ENTRY mRecordsBuffer
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer
);
25 UINT32 mLogDataHubStatus
= 0;
27 EFI_EVENT mLogDataHubEvent
;
29 // Cache data hub protocol.
32 EFI_DATA_HUB_PROTOCOL
*mDataHubProtocol
;
36 Return one DATAHUB_STATUSCODE_RECORD space.
37 The size of free record pool would be extend, if the pool is empty.
40 @retval NULL Can not allocate free memeory for record.
41 @retval !NULL Point to buffer of record.
45 DATA_HUB_STATUS_CODE_DATA_RECORD
*
50 DATAHUB_STATUSCODE_RECORD
*Record
;
55 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
57 if (!IsListEmpty (&mRecordsBuffer
)) {
58 Node
= GetFirstNode (&mRecordsBuffer
);
59 RemoveEntryList (Node
);
61 Record
= _CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
);
63 if (CurrentTpl
> TPL_NOTIFY
) {
65 // Memory management should work at <=TPL_NOTIFY
67 gBS
->RestoreTPL (CurrentTpl
);
71 gBS
->RestoreTPL (CurrentTpl
);
72 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
) * 16);
77 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
78 for (Index
= 1; Index
< 16; Index
++) {
79 InsertTailList (&mRecordsBuffer
, &Record
[Index
].Node
);
83 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
84 InsertTailList (&mRecordsFifo
, &Record
->Node
);
86 gBS
->RestoreTPL (CurrentTpl
);
88 return (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (Record
->Data
);
93 Retrieve one record from Records FIFO. The record would be removed from FIFO and
94 release to free record buffer.
96 @return !NULL Point to record, which is ready to be logged.
97 @return NULL the FIFO of record is empty.
101 DATA_HUB_STATUS_CODE_DATA_RECORD
*
106 DATA_HUB_STATUS_CODE_DATA_RECORD
*RecordData
= NULL
;
107 DATAHUB_STATUSCODE_RECORD
*Record
;
111 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
113 if (!IsListEmpty (&mRecordsFifo
)) {
114 Node
= GetFirstNode (&mRecordsFifo
);
115 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
116 ASSERT (NULL
!= Record
);
118 RemoveEntryList (&Record
->Node
);
119 RecordData
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) Record
->Data
;
122 gBS
->RestoreTPL (CurrentTpl
);
128 Release Records to FIFO.
130 @param RecordData Point to the record buffer allocated
131 from AcquireRecordBuffer.
137 DATA_HUB_STATUS_CODE_DATA_RECORD
*RecordData
140 DATAHUB_STATUSCODE_RECORD
*Record
;
143 Record
= CR (RecordData
, DATAHUB_STATUSCODE_RECORD
, Data
[0], DATAHUB_STATUS_CODE_SIGNATURE
);
144 ASSERT (NULL
!= Record
);
146 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
148 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
149 Record
->Signature
= 0;
151 gBS
->RestoreTPL (CurrentTpl
);
157 Report status code into DataHub.
159 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
161 @param Value Describes the current status of a hardware or software entity.
162 This included information about the class and subclass that is used to classify the entity
163 as well as an operation. For progress codes, the operation is the current activity.
164 For error codes, it is the exception. For debug codes, it is not defined at this time.
165 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
166 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
168 @param Instance The enumeration of a hardware or software entity within the system.
169 A system may contain multiple entities that match a class/subclass pairing.
170 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
171 not meaningful, or not relevant. Valid instance numbers start with 1.
174 @param CallerId This optional parameter may be used to identify the caller.
175 This parameter allows the status code driver to apply different rules to different callers.
176 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
179 @param Data This optional parameter may be used to pass additional data
181 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
182 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
183 @retval EFI_SUCCESS Success to cache status code and signal log data event.
187 DataHubStatusCodeReportWorker (
188 IN EFI_STATUS_CODE_TYPE CodeType
,
189 IN EFI_STATUS_CODE_VALUE Value
,
191 IN EFI_GUID
*CallerId
,
192 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
195 DATA_HUB_STATUS_CODE_DATA_RECORD
*Record
;
203 // Use atom operation to avoid the reentant of report.
204 // If current status is not zero, then the function is reentrancy.
206 if (1 == InterlockedCompareExchange32 (&mLogDataHubStatus
, 0, 0)) {
207 return EFI_DEVICE_ERROR
;
211 // See whether in runtime phase or not.
213 if (EfiAtRuntime ()) {
214 return EFI_DEVICE_ERROR
;
217 Record
= AcquireRecordBuffer ();
218 if (Record
== NULL
) {
220 // There are no empty record buffer in private buffers
222 return EFI_OUT_OF_RESOURCES
;
226 // Construct Data Hub Extended Data
228 Record
->CodeType
= CodeType
;
229 Record
->Value
= Value
;
230 Record
->Instance
= Instance
;
232 if (CallerId
!= NULL
) {
233 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
237 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
238 CharCount
= UnicodeVSPrintAsciiFormat (
239 (CHAR16
*) (Record
+ 1),
240 EFI_STATUS_CODE_DATA_MAX_SIZE
,
245 // Change record data type from DebugType to String Type.
247 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
);
248 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
249 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
252 // Copy status code data header
254 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
256 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
257 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
259 CopyMem ((VOID
*) (Record
+ 1), Data
+ 1, Record
->Data
.Size
);
263 gBS
->SignalEvent (mLogDataHubEvent
);
270 The Event handler which will be notified to log data in Data Hub.
272 @param Event Instance of the EFI_EVENT to signal whenever data is
273 available to be logged in the system.
274 @param Context Context of the event.
280 LogDataHubEventCallBack (
285 DATA_HUB_STATUS_CODE_DATA_RECORD
*Record
;
287 UINT64 DataRecordClass
;
290 // Use atom operation to avoid the reentant of report.
291 // If current status is not zero, then the function is reentrancy.
293 if (1 == InterlockedCompareExchange32 (&mLogDataHubStatus
, 0, 1)) {
298 // Log DataRecord in Data Hub.
299 // Journal records fifo to find all record entry.
302 Record
= RetrieveRecord ();
303 if (Record
== NULL
) {
307 // Add in the size of the header we added.
309 Size
= sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD
) + (UINT32
) Record
->Data
.Size
;
311 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
312 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
313 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
314 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
315 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
316 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
319 // Should never get here.
321 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
322 EFI_DATA_RECORD_CLASS_ERROR
|
323 EFI_DATA_RECORD_CLASS_DATA
|
324 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
328 // Log DataRecord in Data Hub
331 mDataHubProtocol
->LogData (
333 &gEfiDataHubStatusCodeRecordGuid
,
334 &gEfiStatusCodeRuntimeProtocolGuid
,
340 ReleaseRecord (Record
);
344 // Restore the nest status of report
346 InterlockedCompareExchange32 (&mLogDataHubStatus
, 1, 0);
351 Initialize data hubstatus code.
352 Create a data hub listener.
354 @return The function always return EFI_SUCCESS
358 DataHubStatusCodeInitializeWorker (
364 Status
= gBS
->LocateProtocol (
365 &gEfiDataHubProtocolGuid
,
367 (VOID
**) &mDataHubProtocol
369 ASSERT_EFI_ERROR (Status
);
372 // Create a Notify Event to log data in Data Hub
374 Status
= gBS
->CreateEvent (
377 LogDataHubEventCallBack
,
382 ASSERT_EFI_ERROR (Status
);