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 EFI_LOCK mFifoLock
= EFI_INITIALIZE_LOCK_VARIABLE (EFI_TPL_HIGH_LEVEL
);
24 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
26 UINTN mNumberOfRecords
= 0;
28 EFI_EVENT mLogDataHubEvent
;
30 // Cache data hub protocol.
33 EFI_DATA_HUB_PROTOCOL
*mDataHubProtocol
;
37 Return buffer of length DATAHUB_STATUSCODE_RECORD
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
;
50 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
));
54 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
56 EfiAcquireLock (&mFifoLock
);
57 InsertTailList (&mRecordsFifo
, &Record
->Node
);
59 EfiReleaseLock (&mFifoLock
);
66 Release a mRecordBuffer entry allocated by AcquirRecordBuffer ().
68 @param Record Point to record buffer which is acquired by AcquirRecordBuffer()
73 IN DATAHUB_STATUSCODE_RECORD
*Record
76 ASSERT (Record
!= NULL
);
77 ASSERT (mNumberOfRecords
!= 0);
79 EfiAcquireLock (&mFifoLock
);
80 RemoveEntryList (&Record
->Node
);
82 EfiReleaseLock (&mFifoLock
);
89 Report status code into DataHub.
91 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
93 @param Value Describes the current status of a hardware or software entity.
94 This included information about the class and subclass that is used to classify the entity
95 as well as an operation. For progress codes, the operation is the current activity.
96 For error codes, it is the exception. For debug codes, it is not defined at this time.
97 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
98 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
100 @param Instance The enumeration of a hardware or software entity within the system.
101 A system may contain multiple entities that match a class/subclass pairing.
102 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
103 not meaningful, or not relevant. Valid instance numbers start with 1.
106 @param CallerId This optional parameter may be used to identify the caller.
107 This parameter allows the status code driver to apply different rules to different callers.
108 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
111 @param Data This optional parameter may be used to pass additional data
113 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
114 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
115 @retval EFI_SUCCESS Success to cache status code and signal log data event.
119 DataHubStatusCodeReportWorker (
120 IN EFI_STATUS_CODE_TYPE CodeType
,
121 IN EFI_STATUS_CODE_VALUE Value
,
123 IN EFI_GUID
*CallerId
,
124 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
127 DATAHUB_STATUSCODE_RECORD
*Record
;
134 // See whether in runtime phase or not.
136 if (EfiAtRuntime ()) {
137 return EFI_DEVICE_ERROR
;
140 Record
= AcquireRecordBuffer ();
141 if (Record
== NULL
) {
143 // There are no empty record buffer in private buffers
145 return EFI_OUT_OF_RESOURCES
;
148 // Construct Data Hub Extended Data
150 Record
->CodeType
= CodeType
;
151 Record
->Value
= Value
;
152 Record
->Instance
= Instance
;
154 if (CallerId
!= NULL
) {
155 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
159 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
160 CharCount
= UnicodeVSPrintAsciiFormat (
161 (CHAR16
*) Record
->ExtendData
,
162 EFI_STATUS_CODE_DATA_MAX_SIZE
,
167 // Change record data type from DebugType to String Type.
169 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
170 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
171 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
174 // Copy status code data header
176 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
178 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
179 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
181 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
185 gBS
->SignalEvent (mLogDataHubEvent
);
192 The Event handler which will be notified to log data in Data Hub.
194 @param Event Instance of the EFI_EVENT to signal whenever data is
195 available to be logged in the system.
196 @param Context Context of the event.
201 LogDataHubEventCallBack (
206 DATAHUB_STATUSCODE_RECORD
*Record
;
208 UINT64 DataRecordClass
;
212 // Log DataRecord in Data Hub.
213 // Journal records fifo to find all record entry.
216 for (Node
= mRecordsFifo
.ForwardLink
; Node
!= &mRecordsFifo
;) {
217 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
218 Node
= Node
->ForwardLink
;
221 // Add in the size of the header we added.
223 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + (UINT32
) Record
->Data
.Size
;
225 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
226 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
227 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
228 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
229 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
230 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
233 // Should never get here.
235 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
236 EFI_DATA_RECORD_CLASS_ERROR
|
237 EFI_DATA_RECORD_CLASS_DATA
|
238 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
242 // Log DataRecord in Data Hub
245 mDataHubProtocol
->LogData (
248 &gEfiStatusCodeRuntimeProtocolGuid
,
254 FreeRecordBuffer (Record
);
260 Initialize data hubstatus code.
261 Create a data hub listener.
263 @return The function always return EFI_SUCCESS
267 DataHubStatusCodeInitializeWorker (
273 Status
= gBS
->LocateProtocol (
274 &gEfiDataHubProtocolGuid
,
276 (VOID
**) &mDataHubProtocol
278 ASSERT_EFI_ERROR (Status
);
281 // Create a Notify Event to log data in Data Hub
283 Status
= gBS
->CreateEvent (
284 EFI_EVENT_NOTIFY_SIGNAL
,
286 LogDataHubEventCallBack
,
291 ASSERT_EFI_ERROR (Status
);