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.
21 EFI_LOCK mFifoLock
= EFI_INITIALIZE_LOCK_VARIABLE (EFI_TPL_HIGH_LEVEL
);
22 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
23 UINTN mNumberOfRecords
= 0;
25 EFI_EVENT mLogDataHubEvent
;
27 // Cache data hub protocol.
29 EFI_DATA_HUB_PROTOCOL
*mDataHubProtocol
;
33 Return buffer of length DATAHUB_STATUSCODE_RECORD
35 @retval NULL Can not allocate free memeory for record.
36 @retval !NULL Point to buffer of record.
39 DATAHUB_STATUSCODE_RECORD
*
44 DATAHUB_STATUSCODE_RECORD
*Record
;
46 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
));
50 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
52 EfiAcquireLock (&mFifoLock
);
53 InsertTailList (&mRecordsFifo
, &Record
->Node
);
55 EfiReleaseLock (&mFifoLock
);
62 Release a mRecordBuffer entry allocated by AcquirRecordBuffer ().
64 @param Record Point to record buffer which is acquired by AcquirRecordBuffer()
66 @retval EFI_SUCCESS If DataRecord is valid.
67 @retval !EFI_SUCCESS The record list has empty.
72 IN DATAHUB_STATUSCODE_RECORD
*Record
78 Release a mRecordBuffer entry allocated by AquireEmptyRecordBuffer ().
82 RecordBuffer - Data to free
86 EFI_SUCCESS - If DataRecord is valid
87 EFI_UNSUPPORTED - The record list has empty
91 ASSERT (Record
!= NULL
);
92 ASSERT (mNumberOfRecords
!= 0);
94 EfiAcquireLock (&mFifoLock
);
95 RemoveEntryList (&Record
->Node
);
97 EfiReleaseLock (&mFifoLock
);
104 Report status code into DataHub.
106 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
108 @param Value Describes the current status of a hardware or software entity.
109 This included information about the class and subclass that is used to classify the entity
110 as well as an operation. For progress codes, the operation is the current activity.
111 For error codes, it is the exception. For debug codes, it is not defined at this time.
112 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
113 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
115 @param Instance The enumeration of a hardware or software entity within the system.
116 A system may contain multiple entities that match a class/subclass pairing.
117 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
118 not meaningful, or not relevant. Valid instance numbers start with 1.
121 @param CallerId This optional parameter may be used to identify the caller.
122 This parameter allows the status code driver to apply different rules to different callers.
123 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
126 @param Data This optional parameter may be used to pass additional data
128 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
129 @retval EFI_SUCCESS Success to cache status code and signal log data event.
133 DataHubStatusCodeReportWorker (
134 IN EFI_STATUS_CODE_TYPE CodeType
,
135 IN EFI_STATUS_CODE_VALUE Value
,
137 IN EFI_GUID
*CallerId
,
138 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
141 DATAHUB_STATUSCODE_RECORD
*Record
;
148 // See whether in runtime phase or not.
150 if (EfiAtRuntime ()) {
154 Record
= (DATAHUB_STATUSCODE_RECORD
*) AcquireRecordBuffer ();
155 if (Record
== NULL
) {
157 // There are no empty record buffer in private buffers
159 return EFI_OUT_OF_RESOURCES
;
162 // Construct Data Hub Extended Data
164 Record
->CodeType
= CodeType
;
165 Record
->Value
= Value
;
166 Record
->Instance
= Instance
;
168 if (CallerId
!= NULL
) {
169 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
173 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
174 CharCount
= UnicodeVSPrintAsciiFormat (
175 (CHAR16
*) Record
->ExtendData
,
176 EFI_STATUS_CODE_DATA_MAX_SIZE
,
181 // Change record data type from DebugType to String Type.
183 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
184 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
185 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
188 // Copy status code data header
190 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
192 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
193 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
195 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
199 gBS
->SignalEvent (mLogDataHubEvent
);
206 The Event handler which will be notified to log data in Data Hub.
208 @param Event Instance of the EFI_EVENT to signal whenever data is
209 available to be logged in the system.
210 @param Context Context of the event.
215 LogDataHubEventCallBack (
220 DATAHUB_STATUSCODE_RECORD
*Record
;
222 UINT64 DataRecordClass
;
226 // Log DataRecord in Data Hub.
227 // Journal records fifo to find all record entry.
230 for (Node
= mRecordsFifo
.ForwardLink
; Node
!= &mRecordsFifo
;) {
231 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
232 Node
= Node
->ForwardLink
;
235 // Add in the size of the header we added.
237 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + Record
->Data
.Size
;
239 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
240 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
241 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
242 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
243 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
244 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
247 // Should never get here.
249 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
250 EFI_DATA_RECORD_CLASS_ERROR
|
251 EFI_DATA_RECORD_CLASS_DATA
|
252 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
256 // Log DataRecord in Data Hub
259 mDataHubProtocol
->LogData (
262 &gEfiStatusCodeRuntimeProtocolGuid
,
268 FreeRecordBuffer (Record
);
274 Initialize data hubstatus code.
275 Create a data hub listener.
277 @return The function always return EFI_SUCCESS
281 DataHubStatusCodeInitializeWorker (
287 Status
= gBS
->LocateProtocol (
288 &gEfiDataHubProtocolGuid
,
290 (VOID
**) &mDataHubProtocol
292 ASSERT_EFI_ERROR (Status
);
295 // Create a Notify Event to log data in Data Hub
297 Status
= gBS
->CreateEvent (
298 EFI_EVENT_NOTIFY_SIGNAL
,
300 LogDataHubEventCallBack
,
305 ASSERT_EFI_ERROR (Status
);