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.
43 DATAHUB_STATUSCODE_RECORD
*
48 DATAHUB_STATUSCODE_RECORD
*Record
;
53 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
55 if (!IsListEmpty (&mRecordsBuffer
)) {
56 Node
= GetFirstNode (&mRecordsBuffer
);
57 RemoveEntryList (Node
);
59 Record
= _CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
);
61 if (CurrentTpl
> EFI_TPL_NOTIFY
) {
62 gBS
->RestoreTPL (CurrentTpl
);
66 gBS
->RestoreTPL (CurrentTpl
);
67 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
) * 16);
72 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
73 for (Index
= 1; Index
< 16; Index
++) {
74 InsertTailList (&mRecordsBuffer
, &Record
[Index
].Node
);
78 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
79 InsertTailList (&mRecordsFifo
, &Record
->Node
);
81 gBS
->RestoreTPL (CurrentTpl
);
88 Retrieve one record from Records FIFO. The record would be removed from FIFO and
89 release to free record buffer.
91 @return !NULL Point to record, which is ready to be logged.
92 @return NULL the FIFO of record is empty.
95 DATAHUB_STATUSCODE_RECORD
*
100 DATAHUB_STATUSCODE_RECORD
*Record
= NULL
;
104 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
106 if (!IsListEmpty (&mRecordsFifo
)) {
107 Node
= GetFirstNode (&mRecordsFifo
);
108 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
110 RemoveEntryList (&Record
->Node
);
111 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
112 Record
->Signature
= 0;
115 gBS
->RestoreTPL (CurrentTpl
);
122 Report status code into DataHub.
124 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
126 @param Value Describes the current status of a hardware or software entity.
127 This included information about the class and subclass that is used to classify the entity
128 as well as an operation. For progress codes, the operation is the current activity.
129 For error codes, it is the exception. For debug codes, it is not defined at this time.
130 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
131 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
133 @param Instance The enumeration of a hardware or software entity within the system.
134 A system may contain multiple entities that match a class/subclass pairing.
135 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
136 not meaningful, or not relevant. Valid instance numbers start with 1.
139 @param CallerId This optional parameter may be used to identify the caller.
140 This parameter allows the status code driver to apply different rules to different callers.
141 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
144 @param Data This optional parameter may be used to pass additional data
146 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
147 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
148 @retval EFI_SUCCESS Success to cache status code and signal log data event.
152 DataHubStatusCodeReportWorker (
153 IN EFI_STATUS_CODE_TYPE CodeType
,
154 IN EFI_STATUS_CODE_VALUE Value
,
156 IN EFI_GUID
*CallerId
,
157 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
160 DATAHUB_STATUSCODE_RECORD
*Record
;
167 // See whether in runtime phase or not.
169 if (EfiAtRuntime ()) {
170 return EFI_DEVICE_ERROR
;
173 Record
= AcquireRecordBuffer ();
174 if (Record
== NULL
) {
176 // There are no empty record buffer in private buffers
178 return EFI_OUT_OF_RESOURCES
;
181 // Construct Data Hub Extended Data
183 Record
->CodeType
= CodeType
;
184 Record
->Value
= Value
;
185 Record
->Instance
= Instance
;
187 if (CallerId
!= NULL
) {
188 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
192 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
193 CharCount
= UnicodeVSPrintAsciiFormat (
194 (CHAR16
*) Record
->ExtendData
,
195 EFI_STATUS_CODE_DATA_MAX_SIZE
,
200 // Change record data type from DebugType to String Type.
202 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
203 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
204 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
207 // Copy status code data header
209 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
211 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
212 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
214 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
218 gBS
->SignalEvent (mLogDataHubEvent
);
225 The Event handler which will be notified to log data in Data Hub.
227 @param Event Instance of the EFI_EVENT to signal whenever data is
228 available to be logged in the system.
229 @param Context Context of the event.
234 LogDataHubEventCallBack (
239 DATAHUB_STATUSCODE_RECORD
*Record
;
241 UINT64 DataRecordClass
;
244 // Log DataRecord in Data Hub.
245 // Journal records fifo to find all record entry.
248 Record
= RetrieveRecord ();
249 if (Record
== NULL
) {
253 // Add in the size of the header we added.
255 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + (UINT32
) Record
->Data
.Size
;
257 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
258 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
259 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
260 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
261 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
262 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
265 // Should never get here.
267 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
268 EFI_DATA_RECORD_CLASS_ERROR
|
269 EFI_DATA_RECORD_CLASS_DATA
|
270 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
274 // Log DataRecord in Data Hub
277 mDataHubProtocol
->LogData (
280 &gEfiStatusCodeRuntimeProtocolGuid
,
291 Initialize data hubstatus code.
292 Create a data hub listener.
294 @return The function always return EFI_SUCCESS
298 DataHubStatusCodeInitializeWorker (
304 Status
= gBS
->LocateProtocol (
305 &gEfiDataHubProtocolGuid
,
307 (VOID
**) &mDataHubProtocol
309 ASSERT_EFI_ERROR (Status
);
312 // Create a Notify Event to log data in Data Hub
314 Status
= gBS
->CreateEvent (
315 EFI_EVENT_NOTIFY_SIGNAL
,
317 LogDataHubEventCallBack
,
322 ASSERT_EFI_ERROR (Status
);