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()
70 @retval EFI_SUCCESS If DataRecord is valid.
71 @retval !EFI_SUCCESS The record list has empty.
76 IN DATAHUB_STATUSCODE_RECORD
*Record
82 Release a mRecordBuffer entry allocated by AquireEmptyRecordBuffer ().
86 RecordBuffer - Data to free
90 EFI_SUCCESS - If DataRecord is valid
91 EFI_UNSUPPORTED - The record list has empty
95 ASSERT (Record
!= NULL
);
96 ASSERT (mNumberOfRecords
!= 0);
98 EfiAcquireLock (&mFifoLock
);
99 RemoveEntryList (&Record
->Node
);
101 EfiReleaseLock (&mFifoLock
);
108 Report status code into DataHub.
110 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
112 @param Value Describes the current status of a hardware or software entity.
113 This included information about the class and subclass that is used to classify the entity
114 as well as an operation. For progress codes, the operation is the current activity.
115 For error codes, it is the exception. For debug codes, it is not defined at this time.
116 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
117 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
119 @param Instance The enumeration of a hardware or software entity within the system.
120 A system may contain multiple entities that match a class/subclass pairing.
121 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
122 not meaningful, or not relevant. Valid instance numbers start with 1.
125 @param CallerId This optional parameter may be used to identify the caller.
126 This parameter allows the status code driver to apply different rules to different callers.
127 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
130 @param Data This optional parameter may be used to pass additional data
132 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
133 @retval EFI_SUCCESS Success to cache status code and signal log data event.
137 DataHubStatusCodeReportWorker (
138 IN EFI_STATUS_CODE_TYPE CodeType
,
139 IN EFI_STATUS_CODE_VALUE Value
,
141 IN EFI_GUID
*CallerId
,
142 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
145 DATAHUB_STATUSCODE_RECORD
*Record
;
152 // See whether in runtime phase or not.
154 if (EfiAtRuntime ()) {
158 Record
= (DATAHUB_STATUSCODE_RECORD
*) AcquireRecordBuffer ();
159 if (Record
== NULL
) {
161 // There are no empty record buffer in private buffers
163 return EFI_OUT_OF_RESOURCES
;
166 // Construct Data Hub Extended Data
168 Record
->CodeType
= CodeType
;
169 Record
->Value
= Value
;
170 Record
->Instance
= Instance
;
172 if (CallerId
!= NULL
) {
173 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
177 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
178 CharCount
= UnicodeVSPrintAsciiFormat (
179 (CHAR16
*) Record
->ExtendData
,
180 EFI_STATUS_CODE_DATA_MAX_SIZE
,
185 // Change record data type from DebugType to String Type.
187 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
188 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
189 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
192 // Copy status code data header
194 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
196 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
197 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
199 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
203 gBS
->SignalEvent (mLogDataHubEvent
);
210 The Event handler which will be notified to log data in Data Hub.
212 @param Event Instance of the EFI_EVENT to signal whenever data is
213 available to be logged in the system.
214 @param Context Context of the event.
219 LogDataHubEventCallBack (
224 DATAHUB_STATUSCODE_RECORD
*Record
;
226 UINT64 DataRecordClass
;
230 // Log DataRecord in Data Hub.
231 // Journal records fifo to find all record entry.
234 for (Node
= mRecordsFifo
.ForwardLink
; Node
!= &mRecordsFifo
;) {
235 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
236 Node
= Node
->ForwardLink
;
239 // Add in the size of the header we added.
241 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + Record
->Data
.Size
;
243 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
244 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
245 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
246 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
247 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
248 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
251 // Should never get here.
253 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
254 EFI_DATA_RECORD_CLASS_ERROR
|
255 EFI_DATA_RECORD_CLASS_DATA
|
256 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
260 // Log DataRecord in Data Hub
263 mDataHubProtocol
->LogData (
266 &gEfiStatusCodeRuntimeProtocolGuid
,
272 FreeRecordBuffer (Record
);
278 Initialize data hubstatus code.
279 Create a data hub listener.
281 @return The function always return EFI_SUCCESS
285 DataHubStatusCodeInitializeWorker (
291 Status
= gBS
->LocateProtocol (
292 &gEfiDataHubProtocolGuid
,
294 (VOID
**) &mDataHubProtocol
296 ASSERT_EFI_ERROR (Status
);
299 // Create a Notify Event to log data in Data Hub
301 Status
= gBS
->CreateEvent (
302 EFI_EVENT_NOTIFY_SIGNAL
,
304 LogDataHubEventCallBack
,
309 ASSERT_EFI_ERROR (Status
);