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
, DATAHUB_STATUS_CODE_SIGNATURE
);
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 Release a mRecordBuffer entry allocated by AcquirRecordBuffer ().
90 @param Record Point to record buffer which is acquired by AcquirRecordBuffer()
95 IN DATAHUB_STATUSCODE_RECORD
*Record
100 ASSERT (Record
!= NULL
);
102 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
104 RemoveEntryList (&Record
->Node
);
105 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
107 gBS
->RestoreTPL (CurrentTpl
);
112 Report status code into DataHub.
114 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
116 @param Value Describes the current status of a hardware or software entity.
117 This included information about the class and subclass that is used to classify the entity
118 as well as an operation. For progress codes, the operation is the current activity.
119 For error codes, it is the exception. For debug codes, it is not defined at this time.
120 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
121 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
123 @param Instance The enumeration of a hardware or software entity within the system.
124 A system may contain multiple entities that match a class/subclass pairing.
125 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
126 not meaningful, or not relevant. Valid instance numbers start with 1.
129 @param CallerId This optional parameter may be used to identify the caller.
130 This parameter allows the status code driver to apply different rules to different callers.
131 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
134 @param Data This optional parameter may be used to pass additional data
136 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
137 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
138 @retval EFI_SUCCESS Success to cache status code and signal log data event.
142 DataHubStatusCodeReportWorker (
143 IN EFI_STATUS_CODE_TYPE CodeType
,
144 IN EFI_STATUS_CODE_VALUE Value
,
146 IN EFI_GUID
*CallerId
,
147 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
150 DATAHUB_STATUSCODE_RECORD
*Record
;
157 // See whether in runtime phase or not.
159 if (EfiAtRuntime ()) {
160 return EFI_DEVICE_ERROR
;
163 Record
= AcquireRecordBuffer ();
164 if (Record
== NULL
) {
166 // There are no empty record buffer in private buffers
168 return EFI_OUT_OF_RESOURCES
;
171 // Construct Data Hub Extended Data
173 Record
->CodeType
= CodeType
;
174 Record
->Value
= Value
;
175 Record
->Instance
= Instance
;
177 if (CallerId
!= NULL
) {
178 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
182 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
183 CharCount
= UnicodeVSPrintAsciiFormat (
184 (CHAR16
*) Record
->ExtendData
,
185 EFI_STATUS_CODE_DATA_MAX_SIZE
,
190 // Change record data type from DebugType to String Type.
192 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeStringGuid
);
193 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
194 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
197 // Copy status code data header
199 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
201 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
202 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
204 CopyMem (Record
->ExtendData
, Data
+ 1, Record
->Data
.Size
);
208 gBS
->SignalEvent (mLogDataHubEvent
);
215 The Event handler which will be notified to log data in Data Hub.
217 @param Event Instance of the EFI_EVENT to signal whenever data is
218 available to be logged in the system.
219 @param Context Context of the event.
224 LogDataHubEventCallBack (
229 DATAHUB_STATUSCODE_RECORD
*Record
;
231 UINT64 DataRecordClass
;
236 // Log DataRecord in Data Hub.
237 // Journal records fifo to find all record entry.
240 CurrentTpl
= gBS
->RaiseTPL (EFI_TPL_HIGH_LEVEL
);
242 for (Node
= mRecordsFifo
.ForwardLink
; Node
!= &mRecordsFifo
;) {
243 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
244 Node
= Node
->ForwardLink
;
247 // Add in the size of the header we added.
249 Size
= sizeof (DATAHUB_STATUSCODE_RECORD
) + (UINT32
) Record
->Data
.Size
;
251 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
252 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
253 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
254 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
255 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
256 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
259 // Should never get here.
261 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
262 EFI_DATA_RECORD_CLASS_ERROR
|
263 EFI_DATA_RECORD_CLASS_DATA
|
264 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
268 // Log DataRecord in Data Hub
271 mDataHubProtocol
->LogData (
274 &gEfiStatusCodeRuntimeProtocolGuid
,
282 FreeRecordBuffer (Record
);
285 gBS
->RestoreTPL (CurrentTpl
);
290 Initialize data hubstatus code.
291 Create a data hub listener.
293 @return The function always return EFI_SUCCESS
297 DataHubStatusCodeInitializeWorker (
303 Status
= gBS
->LocateProtocol (
304 &gEfiDataHubProtocolGuid
,
306 (VOID
**) &mDataHubProtocol
308 ASSERT_EFI_ERROR (Status
);
311 // Create a Notify Event to log data in Data Hub
313 Status
= gBS
->CreateEvent (
314 EFI_EVENT_NOTIFY_SIGNAL
,
316 LogDataHubEventCallBack
,
321 ASSERT_EFI_ERROR (Status
);