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.
13 Module Name: DataHubStatusCodeWorker.c
17 #include "DxeStatusCode.h"
20 // Initialize FIFO to cache records.
23 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
25 LIST_ENTRY mRecordsBuffer
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer
);
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
) {
64 gBS
->RestoreTPL (CurrentTpl
);
68 gBS
->RestoreTPL (CurrentTpl
);
69 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
) * 16);
74 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
75 for (Index
= 1; Index
< 16; Index
++) {
76 InsertTailList (&mRecordsBuffer
, &Record
[Index
].Node
);
80 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
81 InsertTailList (&mRecordsFifo
, &Record
->Node
);
83 gBS
->RestoreTPL (CurrentTpl
);
85 return (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (Record
->Data
);
90 Retrieve one record from Records FIFO. The record would be removed from FIFO and
91 release to free record buffer.
93 @return !NULL Point to record, which is ready to be logged.
94 @return NULL the FIFO of record is empty.
98 DATA_HUB_STATUS_CODE_DATA_RECORD
*
103 DATA_HUB_STATUS_CODE_DATA_RECORD
*RecordData
= NULL
;
104 DATAHUB_STATUSCODE_RECORD
*Record
;
108 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
110 if (!IsListEmpty (&mRecordsFifo
)) {
111 Node
= GetFirstNode (&mRecordsFifo
);
112 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
114 RemoveEntryList (&Record
->Node
);
115 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
116 Record
->Signature
= 0;
117 RecordData
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) Record
->Data
;
120 gBS
->RestoreTPL (CurrentTpl
);
127 Report status code into DataHub.
129 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
131 @param Value Describes the current status of a hardware or software entity.
132 This included information about the class and subclass that is used to classify the entity
133 as well as an operation. For progress codes, the operation is the current activity.
134 For error codes, it is the exception. For debug codes, it is not defined at this time.
135 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
136 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
138 @param Instance The enumeration of a hardware or software entity within the system.
139 A system may contain multiple entities that match a class/subclass pairing.
140 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
141 not meaningful, or not relevant. Valid instance numbers start with 1.
144 @param CallerId This optional parameter may be used to identify the caller.
145 This parameter allows the status code driver to apply different rules to different callers.
146 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
149 @param Data This optional parameter may be used to pass additional data
151 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
152 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
153 @retval EFI_SUCCESS Success to cache status code and signal log data event.
157 DataHubStatusCodeReportWorker (
158 IN EFI_STATUS_CODE_TYPE CodeType
,
159 IN EFI_STATUS_CODE_VALUE Value
,
161 IN EFI_GUID
*CallerId
,
162 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
165 DATA_HUB_STATUS_CODE_DATA_RECORD
*Record
;
172 // See whether in runtime phase or not.
174 if (EfiAtRuntime ()) {
175 return EFI_DEVICE_ERROR
;
178 Record
= AcquireRecordBuffer ();
179 if (Record
== NULL
) {
181 // There are no empty record buffer in private buffers
183 return EFI_OUT_OF_RESOURCES
;
187 // Construct Data Hub Extended Data
189 Record
->CodeType
= CodeType
;
190 Record
->Value
= Value
;
191 Record
->Instance
= Instance
;
193 if (CallerId
!= NULL
) {
194 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
198 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
199 CharCount
= UnicodeVSPrintAsciiFormat (
200 (CHAR16
*) (Record
+ 1),
201 EFI_STATUS_CODE_DATA_MAX_SIZE
,
206 // Change record data type from DebugType to String Type.
208 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
);
209 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
210 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
213 // Copy status code data header
215 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
217 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
218 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
220 CopyMem ((VOID
*) (Record
+ 1), Data
+ 1, Record
->Data
.Size
);
224 gBS
->SignalEvent (mLogDataHubEvent
);
231 The Event handler which will be notified to log data in Data Hub.
233 @param Event Instance of the EFI_EVENT to signal whenever data is
234 available to be logged in the system.
235 @param Context Context of the event.
241 LogDataHubEventCallBack (
246 DATA_HUB_STATUS_CODE_DATA_RECORD
*Record
;
248 UINT64 DataRecordClass
;
251 // Log DataRecord in Data Hub.
252 // Journal records fifo to find all record entry.
255 Record
= RetrieveRecord ();
256 if (Record
== NULL
) {
260 // Add in the size of the header we added.
262 Size
= sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD
) + (UINT32
) Record
->Data
.Size
;
264 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
265 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
266 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
267 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
268 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
269 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
272 // Should never get here.
274 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
275 EFI_DATA_RECORD_CLASS_ERROR
|
276 EFI_DATA_RECORD_CLASS_DATA
|
277 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
281 // Log DataRecord in Data Hub
284 mDataHubProtocol
->LogData (
287 &gEfiStatusCodeRuntimeProtocolGuid
,
298 Initialize data hubstatus code.
299 Create a data hub listener.
301 @return The function always return EFI_SUCCESS
305 DataHubStatusCodeInitializeWorker (
311 Status
= gBS
->LocateProtocol (
312 &gEfiDataHubProtocolGuid
,
314 (VOID
**) &mDataHubProtocol
316 ASSERT_EFI_ERROR (Status
);
319 // Create a Notify Event to log data in Data Hub
321 Status
= gBS
->CreateEvent (
324 LogDataHubEventCallBack
,
329 ASSERT_EFI_ERROR (Status
);