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 common header file for this module.
19 #include "CommonHeader.h"
21 #include "DxeStatusCode.h"
24 // Initialize FIFO to cache records.
27 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
29 LIST_ENTRY mRecordsBuffer
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer
);
31 EFI_EVENT mLogDataHubEvent
;
33 // Cache data hub protocol.
36 EFI_DATA_HUB_PROTOCOL
*mDataHubProtocol
;
40 Return one DATAHUB_STATUSCODE_RECORD space.
41 The size of free record pool would be extend, if the pool is empty.
44 @retval NULL Can not allocate free memeory for record.
45 @retval !NULL Point to buffer of record.
49 DATAHUB_STATUSCODE_RECORD
*
54 DATAHUB_STATUSCODE_RECORD
*Record
;
59 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
61 if (!IsListEmpty (&mRecordsBuffer
)) {
62 Node
= GetFirstNode (&mRecordsBuffer
);
63 RemoveEntryList (Node
);
65 Record
= _CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
);
67 if (CurrentTpl
> TPL_NOTIFY
) {
68 gBS
->RestoreTPL (CurrentTpl
);
72 gBS
->RestoreTPL (CurrentTpl
);
73 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
) * 16);
78 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
79 for (Index
= 1; Index
< 16; Index
++) {
80 InsertTailList (&mRecordsBuffer
, &Record
[Index
].Node
);
84 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
85 InsertTailList (&mRecordsFifo
, &Record
->Node
);
87 gBS
->RestoreTPL (CurrentTpl
);
94 Retrieve one record from Records FIFO. The record would be removed from FIFO and
95 release to free record buffer.
97 @return !NULL Point to record, which is ready to be logged.
98 @return NULL the FIFO of record is empty.
102 DATAHUB_STATUSCODE_RECORD
*
107 DATAHUB_STATUSCODE_RECORD
*Record
= NULL
;
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
);
117 RemoveEntryList (&Record
->Node
);
118 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
119 Record
->Signature
= 0;
122 gBS
->RestoreTPL (CurrentTpl
);
129 Report status code into DataHub.
131 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
133 @param Value Describes the current status of a hardware or software entity.
134 This included information about the class and subclass that is used to classify the entity
135 as well as an operation. For progress codes, the operation is the current activity.
136 For error codes, it is the exception. For debug codes, it is not defined at this time.
137 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
138 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
140 @param Instance The enumeration of a hardware or software entity within the system.
141 A system may contain multiple entities that match a class/subclass pairing.
142 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
143 not meaningful, or not relevant. Valid instance numbers start with 1.
146 @param CallerId This optional parameter may be used to identify the caller.
147 This parameter allows the status code driver to apply different rules to different callers.
148 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
151 @param Data This optional parameter may be used to pass additional data
153 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
154 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
155 @retval EFI_SUCCESS Success to cache status code and signal log data event.
159 DataHubStatusCodeReportWorker (
160 IN EFI_STATUS_CODE_TYPE CodeType
,
161 IN EFI_STATUS_CODE_VALUE Value
,
163 IN EFI_GUID
*CallerId
,
164 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
167 DATAHUB_STATUSCODE_RECORD
*Record
;
174 // See whether in runtime phase or not.
176 if (EfiAtRuntime ()) {
177 return EFI_DEVICE_ERROR
;
180 Record
= AcquireRecordBuffer ();
181 if (Record
== NULL
) {
183 // There are no empty record buffer in private buffers
185 return EFI_OUT_OF_RESOURCES
;
188 // Construct Data Hub Extended Data
190 Record
->CodeType
= CodeType
;
191 Record
->Value
= Value
;
192 Record
->Instance
= Instance
;
194 if (CallerId
!= NULL
) {
195 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
199 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
200 CharCount
= UnicodeVSPrintAsciiFormat (
201 (CHAR16
*) Record
->ExtendData
,
202 EFI_STATUS_CODE_DATA_MAX_SIZE
,
207 // Change record data type from DebugType to String Type.
209 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
210 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
211 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
214 // Copy status code data header
216 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
218 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
219 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
221 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
225 gBS
->SignalEvent (mLogDataHubEvent
);
232 The Event handler which will be notified to log data in Data Hub.
234 @param Event Instance of the EFI_EVENT to signal whenever data is
235 available to be logged in the system.
236 @param Context Context of the event.
242 LogDataHubEventCallBack (
247 DATAHUB_STATUSCODE_RECORD
*Record
;
249 UINT64 DataRecordClass
;
252 // Log DataRecord in Data Hub.
253 // Journal records fifo to find all record entry.
256 Record
= RetrieveRecord ();
257 if (Record
== NULL
) {
261 // Add in the size of the header we added.
263 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + (UINT32
) Record
->Data
.Size
;
265 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
266 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
267 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
268 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
269 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
270 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
273 // Should never get here.
275 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
276 EFI_DATA_RECORD_CLASS_ERROR
|
277 EFI_DATA_RECORD_CLASS_DATA
|
278 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
282 // Log DataRecord in Data Hub
285 mDataHubProtocol
->LogData (
288 &gEfiStatusCodeRuntimeProtocolGuid
,
299 Initialize data hubstatus code.
300 Create a data hub listener.
302 @return The function always return EFI_SUCCESS
306 DataHubStatusCodeInitializeWorker (
312 Status
= gBS
->LocateProtocol (
313 &gEfiDataHubProtocolGuid
,
315 (VOID
**) &mDataHubProtocol
317 ASSERT_EFI_ERROR (Status
);
320 // Create a Notify Event to log data in Data Hub
322 Status
= gBS
->CreateEvent (
325 LogDataHubEventCallBack
,
330 ASSERT_EFI_ERROR (Status
);