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
16 #include "DxeStatusCode.h"
19 // Initialize FIFO to cache records.
22 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
24 LIST_ENTRY mRecordsBuffer
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer
);
26 EFI_EVENT mLogDataHubEvent
;
28 // Cache data hub protocol.
31 EFI_DATA_HUB_PROTOCOL
*mDataHubProtocol
;
35 Return one DATAHUB_STATUSCODE_RECORD space.
36 The size of free record pool would be extend, if the pool is empty.
39 @retval NULL Can not allocate free memeory for record.
40 @retval !NULL Point to buffer of record.
44 DATAHUB_STATUSCODE_RECORD
*
49 DATAHUB_STATUSCODE_RECORD
*Record
;
54 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
56 if (!IsListEmpty (&mRecordsBuffer
)) {
57 Node
= GetFirstNode (&mRecordsBuffer
);
58 RemoveEntryList (Node
);
60 Record
= _CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
);
62 if (CurrentTpl
> EFI_TPL_NOTIFY
) {
63 gBS
->RestoreTPL (CurrentTpl
);
67 gBS
->RestoreTPL (CurrentTpl
);
68 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
) * 16);
73 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
74 for (Index
= 1; Index
< 16; Index
++) {
75 InsertTailList (&mRecordsBuffer
, &Record
[Index
].Node
);
79 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
80 InsertTailList (&mRecordsFifo
, &Record
->Node
);
82 gBS
->RestoreTPL (CurrentTpl
);
89 Retrieve one record from Records FIFO. The record would be removed from FIFO and
90 release to free record buffer.
92 @return !NULL Point to record, which is ready to be logged.
93 @return NULL the FIFO of record is empty.
97 DATAHUB_STATUSCODE_RECORD
*
102 DATAHUB_STATUSCODE_RECORD
*Record
= NULL
;
106 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
108 if (!IsListEmpty (&mRecordsFifo
)) {
109 Node
= GetFirstNode (&mRecordsFifo
);
110 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
112 RemoveEntryList (&Record
->Node
);
113 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
114 Record
->Signature
= 0;
117 gBS
->RestoreTPL (CurrentTpl
);
124 Report status code into DataHub.
126 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
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.
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.
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.
146 @param Data This optional parameter may be used to pass additional data
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.
154 DataHubStatusCodeReportWorker (
155 IN EFI_STATUS_CODE_TYPE CodeType
,
156 IN EFI_STATUS_CODE_VALUE Value
,
158 IN EFI_GUID
*CallerId
,
159 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
162 DATAHUB_STATUSCODE_RECORD
*Record
;
169 // See whether in runtime phase or not.
171 if (EfiAtRuntime ()) {
172 return EFI_DEVICE_ERROR
;
175 Record
= AcquireRecordBuffer ();
176 if (Record
== NULL
) {
178 // There are no empty record buffer in private buffers
180 return EFI_OUT_OF_RESOURCES
;
183 // Construct Data Hub Extended Data
185 Record
->CodeType
= CodeType
;
186 Record
->Value
= Value
;
187 Record
->Instance
= Instance
;
189 if (CallerId
!= NULL
) {
190 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
194 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
195 CharCount
= UnicodeVSPrintAsciiFormat (
196 (CHAR16
*) Record
->ExtendData
,
197 EFI_STATUS_CODE_DATA_MAX_SIZE
,
202 // Change record data type from DebugType to String Type.
204 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
205 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
206 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
209 // Copy status code data header
211 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
213 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
214 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
216 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
220 gBS
->SignalEvent (mLogDataHubEvent
);
227 The Event handler which will be notified to log data in Data Hub.
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.
237 LogDataHubEventCallBack (
242 DATAHUB_STATUSCODE_RECORD
*Record
;
244 UINT64 DataRecordClass
;
247 // Log DataRecord in Data Hub.
248 // Journal records fifo to find all record entry.
251 Record
= RetrieveRecord ();
252 if (Record
== NULL
) {
256 // Add in the size of the header we added.
258 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + (UINT32
) Record
->Data
.Size
;
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
;
268 // Should never get here.
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
;
277 // Log DataRecord in Data Hub
280 mDataHubProtocol
->LogData (
283 &gEfiStatusCodeRuntimeProtocolGuid
,
294 Initialize data hubstatus code.
295 Create a data hub listener.
297 @return The function always return EFI_SUCCESS
301 DataHubStatusCodeInitializeWorker (
307 Status
= gBS
->LocateProtocol (
308 &gEfiDataHubProtocolGuid
,
310 (VOID
**) &mDataHubProtocol
312 ASSERT_EFI_ERROR (Status
);
315 // Create a Notify Event to log data in Data Hub
317 Status
= gBS
->CreateEvent (
318 EFI_EVENT_NOTIFY_SIGNAL
,
320 LogDataHubEventCallBack
,
325 ASSERT_EFI_ERROR (Status
);