2 Data Hub status code worker.
4 Copyright (c) 2006 - 2009, 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.
15 #include "StatusCodeRuntimeDxe.h"
18 // Initialize FIFO to cache records.
20 LIST_ENTRY mRecordsFifo
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo
);
21 LIST_ENTRY mRecordsBuffer
= INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer
);
22 UINT32 mLogDataHubStatus
= 0;
23 EFI_EVENT mLogDataHubEvent
;
25 // Cache data hub protocol.
27 EFI_DATA_HUB_PROTOCOL
*mDataHubProtocol
;
31 Retrieve one record of from free record buffer. This record is removed from
34 This function retrieves one record from free record buffer.
35 If the pool has been exhausted, then new memory would be allocated for it.
37 @return Pointer to the free record.
38 NULL means failure to allocate new memeory for free record buffer.
41 DATA_HUB_STATUS_CODE_DATA_RECORD
*
46 DATAHUB_STATUSCODE_RECORD
*Record
;
51 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
53 if (!IsListEmpty (&mRecordsBuffer
)) {
55 // Strip one entry from free record buffer.
57 Node
= GetFirstNode (&mRecordsBuffer
);
58 RemoveEntryList (Node
);
60 Record
= BASE_CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
);
62 if (CurrentTpl
> TPL_NOTIFY
) {
64 // Memory management should work at <=TPL_NOTIFY
66 gBS
->RestoreTPL (CurrentTpl
);
71 // If free record buffer is exhausted, then allocate 16 new records for it.
73 gBS
->RestoreTPL (CurrentTpl
);
74 Record
= (DATAHUB_STATUSCODE_RECORD
*) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD
) * 16);
79 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
81 // Here we only insert 15 new records to the free record buffer, for the first record
82 // will be returned immediately.
84 for (Index
= 1; Index
< 16; Index
++) {
85 InsertTailList (&mRecordsBuffer
, &Record
[Index
].Node
);
89 Record
->Signature
= DATAHUB_STATUS_CODE_SIGNATURE
;
90 InsertTailList (&mRecordsFifo
, &Record
->Node
);
92 gBS
->RestoreTPL (CurrentTpl
);
94 return (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (Record
->Data
);
99 Retrieve one record from Records FIFO. The record would be removed from FIFO.
101 @return Point to record, which is ready to be logged.
102 NULL means the FIFO of record is empty.
105 DATA_HUB_STATUS_CODE_DATA_RECORD
*
110 DATA_HUB_STATUS_CODE_DATA_RECORD
*RecordData
;
111 DATAHUB_STATUSCODE_RECORD
*Record
;
117 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
119 if (!IsListEmpty (&mRecordsFifo
)) {
120 Node
= GetFirstNode (&mRecordsFifo
);
121 Record
= CR (Node
, DATAHUB_STATUSCODE_RECORD
, Node
, DATAHUB_STATUS_CODE_SIGNATURE
);
122 ASSERT (Record
!= NULL
);
124 RemoveEntryList (&Record
->Node
);
125 RecordData
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) Record
->Data
;
128 gBS
->RestoreTPL (CurrentTpl
);
134 Release given record and return it to free record buffer.
136 @param RecordData Pointer to the record to release.
141 DATA_HUB_STATUS_CODE_DATA_RECORD
*RecordData
144 DATAHUB_STATUSCODE_RECORD
*Record
;
147 Record
= CR (RecordData
, DATAHUB_STATUSCODE_RECORD
, Data
[0], DATAHUB_STATUS_CODE_SIGNATURE
);
148 ASSERT (Record
!= NULL
);
150 CurrentTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
152 InsertTailList (&mRecordsBuffer
, &Record
->Node
);
153 Record
->Signature
= 0;
155 gBS
->RestoreTPL (CurrentTpl
);
159 Report status code into DataHub.
161 @param CodeType Indicates the type of status code being reported.
162 @param Value Describes the current status of a hardware or software entity.
163 This included information about the class and subclass that is used to
164 classify the entity as well as an operation.
165 @param Instance The enumeration of a hardware or software entity within
166 the system. Valid instance numbers start with 1.
167 @param CallerId This optional parameter may be used to identify the caller.
168 This parameter allows the status code driver to apply different rules to
170 @param Data This optional parameter may be used to pass additional data.
172 @retval EFI_SUCCESS The function completed successfully.
173 @retval EFI_DEVICE_ERROR Function is reentered.
174 @retval EFI_DEVICE_ERROR Function is called at runtime.
175 @retval EFI_OUT_OF_RESOURCES Fail to allocate memory for free record buffer.
179 DataHubStatusCodeReportWorker (
180 IN EFI_STATUS_CODE_TYPE CodeType
,
181 IN EFI_STATUS_CODE_VALUE Value
,
183 IN EFI_GUID
*CallerId
,
184 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
187 DATA_HUB_STATUS_CODE_DATA_RECORD
*Record
;
194 // Use atom operation to avoid the reentant of report.
195 // If current status is not zero, then the function is reentrancy.
197 if (InterlockedCompareExchange32 (&mLogDataHubStatus
, 0, 0) == 1) {
198 return EFI_DEVICE_ERROR
;
202 // See whether in runtime phase or not.
204 if (EfiAtRuntime ()) {
205 return EFI_DEVICE_ERROR
;
208 Record
= AcquireRecordBuffer ();
209 if (Record
== NULL
) {
211 // There are no empty record buffer in private buffers
213 return EFI_OUT_OF_RESOURCES
;
217 // Construct Data Hub Extended Data
219 Record
->CodeType
= CodeType
;
220 Record
->Value
= Value
;
221 Record
->Instance
= Instance
;
223 if (CallerId
!= NULL
) {
224 CopyMem (&Record
->CallerId
, CallerId
, sizeof (EFI_GUID
));
228 if (ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
229 CharCount
= UnicodeBSPrintAsciiFormat (
230 (CHAR16
*) (Record
+ 1),
231 EFI_STATUS_CODE_DATA_MAX_SIZE
,
236 // Change record data type to DebugType.
238 CopyGuid (&Record
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
);
239 Record
->Data
.HeaderSize
= Data
->HeaderSize
;
240 Record
->Data
.Size
= (UINT16
) ((CharCount
+ 1) * sizeof (CHAR16
));
243 // Copy status code data header
245 CopyMem (&Record
->Data
, Data
, sizeof (EFI_STATUS_CODE_DATA
));
247 if (Data
->Size
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
248 Record
->Data
.Size
= EFI_STATUS_CODE_DATA_MAX_SIZE
;
250 CopyMem ((VOID
*) (Record
+ 1), Data
+ 1, Record
->Data
.Size
);
254 gBS
->SignalEvent (mLogDataHubEvent
);
261 The Event handler which will be notified to log data in Data Hub.
263 @param Event Instance of the EFI_EVENT to signal whenever data is
264 available to be logged in the system.
265 @param Context Context of the event.
270 LogDataHubEventCallBack (
275 DATA_HUB_STATUS_CODE_DATA_RECORD
*Record
;
277 UINT64 DataRecordClass
;
280 // Use atom operation to avoid the reentant of report.
281 // If current status is not zero, then the function is reentrancy.
283 if (InterlockedCompareExchange32 (&mLogDataHubStatus
, 0, 1) == 1) {
288 // Log DataRecord in Data Hub.
289 // Journal records fifo to find all record entry.
293 // Retrieve record from record FIFO until no more record can be retrieved.
295 Record
= RetrieveRecord ();
296 if (Record
== NULL
) {
300 // Add in the size of the header we added.
302 Size
= sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD
) + (UINT32
) Record
->Data
.Size
;
304 if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
305 DataRecordClass
= EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
306 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
307 DataRecordClass
= EFI_DATA_RECORD_CLASS_ERROR
;
308 } else if ((Record
->CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
309 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
;
312 // Should never get here.
314 DataRecordClass
= EFI_DATA_RECORD_CLASS_DEBUG
|
315 EFI_DATA_RECORD_CLASS_ERROR
|
316 EFI_DATA_RECORD_CLASS_DATA
|
317 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
321 // Log DataRecord in Data Hub
323 mDataHubProtocol
->LogData (
325 &gEfiDataHubStatusCodeRecordGuid
,
326 &gEfiStatusCodeRuntimeProtocolGuid
,
332 ReleaseRecord (Record
);
336 // Restore the nest status of report
338 InterlockedCompareExchange32 (&mLogDataHubStatus
, 1, 0);
343 Locate Data Hub Protocol and create event for logging data
344 as initialization for data hub status code worker.
346 @retval EFI_SUCCESS Initialization is successful.
350 DataHubStatusCodeInitializeWorker (
356 Status
= gBS
->LocateProtocol (
357 &gEfiDataHubProtocolGuid
,
359 (VOID
**) &mDataHubProtocol
361 ASSERT_EFI_ERROR (Status
);
364 // Create a Notify Event to log data in Data Hub
366 Status
= gBS
->CreateEvent (
369 LogDataHubEventCallBack
,
374 ASSERT_EFI_ERROR (Status
);