summaryrefslogtreecommitdiff
path: root/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c
diff options
context:
space:
mode:
Diffstat (limited to 'EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c')
-rw-r--r--EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c374
1 files changed, 137 insertions, 237 deletions
diff --git a/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c b/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c
index e950126c4f..980635dc7f 100644
--- a/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c
+++ b/EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/BsDataHubStatusCode/BsDataHubStatusCode.c
@@ -1,6 +1,6 @@
/*++
-Copyright (c) 2004 - 2006, Intel Corporation
+Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -26,27 +26,29 @@ Abstract:
#include "BsDataHubStatusCode.h"
//
-// Globals only work at BootService Time. NOT at Runtime!
+// Initialize FIFO to cache records.
//
-static EFI_DATA_HUB_PROTOCOL *mDataHub;
-static EFI_LIST_ENTRY *mRecordHead;
-static EFI_LIST_ENTRY *mRecordTail;
-static INTN mRecordNum = 0;
-static EFI_EVENT mLogDataHubEvent;
-static EFI_LOCK mStatusCodeReportLock = EFI_INITIALIZE_LOCK_VARIABLE(EFI_TPL_HIGH_LEVEL);
-static BOOLEAN mEventHandlerActive = FALSE;
+STATIC EFI_LIST_ENTRY mRecordsFifo = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo);
+STATIC EFI_LIST_ENTRY mRecordsBuffer = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer);
+STATIC EFI_EVENT mLogDataHubEvent;
+STATIC BOOLEAN mEventHandlerActive = FALSE;
+//
+// Cache data hub protocol.
+//
+STATIC EFI_DATA_HUB_PROTOCOL *mDataHubProtocol;
-STATUS_CODE_RECORD_LIST *
-AllocateRecordBuffer (
+STATIC
+DATA_HUB_STATUS_CODE_DATA_RECORD *
+AcquireRecordBuffer (
VOID
)
/*++
Routine Description:
- Allocate a new record list node and initialize it.
- Inserting the node into the list isn't the task of this function.
+ Return one DATAHUB_STATUSCODE_RECORD space.
+ The size of free record pool would be extend, if the pool is empty.
Arguments:
@@ -58,144 +60,94 @@ Returns:
--*/
{
- STATUS_CODE_RECORD_LIST *DataBuffer;
-
- DataBuffer = NULL;
-
- gBS->AllocatePool (EfiBootServicesData, sizeof (STATUS_CODE_RECORD_LIST), &DataBuffer);
- if (DataBuffer == NULL) {
- return NULL;
- }
-
- EfiCommonLibZeroMem (DataBuffer, sizeof (STATUS_CODE_RECORD_LIST));
- DataBuffer->Signature = BS_DATA_HUB_STATUS_CODE_SIGNATURE;
-
- return DataBuffer;
-}
-
-DATA_HUB_STATUS_CODE_DATA_RECORD *
-AquireEmptyRecordBuffer (
- VOID
- )
-/*++
-
-Routine Description:
-
- Acquire an empty record buffer from the record list if there's free node,
- or allocate one new node and insert it to the list if the list is full and
- the function isn't run in EFI_TPL_HIGH_LEVEL.
+ DATAHUB_STATUSCODE_RECORD *Record;
+ EFI_TPL CurrentTpl;
+ EFI_LIST_ENTRY *Node;
+ UINT32 Index;
-Arguments:
-
- None
-
-Returns:
-
- Pointer to new record buffer. NULL if none available.
-
---*/
-{
- EFI_TPL OldTpl;
- STATUS_CODE_RECORD_LIST *DataBuffer;
+ Record = NULL;
+ CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
- DataBuffer = NULL;
+ if (!IsListEmpty (&mRecordsBuffer)) {
+ Node = GetFirstNode (&mRecordsBuffer);
+ RemoveEntryList (Node);
- //
- // This function must be reentrant because an event with higher priority may interrupt it
- // and also report status code.
- //
- EfiAcquireLock (&mStatusCodeReportLock);
- if (mRecordTail != mRecordHead->ForwardLink) {
- if (mRecordNum != 0) {
- mRecordHead = mRecordHead->ForwardLink;
+ Record = _CR (Node, DATAHUB_STATUSCODE_RECORD, Node);
+ } else {
+ if (CurrentTpl > EFI_TPL_NOTIFY) {
+ gBS->RestoreTPL (CurrentTpl);
+ return NULL;
}
- DataBuffer = CR (mRecordHead, STATUS_CODE_RECORD_LIST, Link, BS_DATA_HUB_STATUS_CODE_SIGNATURE);
- mRecordNum++;
- EfiReleaseLock (&mStatusCodeReportLock);
- //
- // Initalize the record buffer is the responsibility of the producer,
- // because the consummer is in a lock so must keep it short.
- //
- EfiCommonLibZeroMem (&DataBuffer->RecordBuffer[0], BYTES_PER_BUFFER);
- } else if (mRecordNum < MAX_RECORD_NUM) {
- //
- // The condition of "mRecordNum < MAX_RECORD_NUM" is not promised,
- // because mRecodeNum may be increased out of this lock.
- //
- EfiReleaseLock (&mStatusCodeReportLock);
-
- //
- // Can't allocate additional buffer in EFI_TPL_HIGH_LEVEL.
- // Reporting too many status code in EFI_TPL_HIGH_LEVEL may cause status code lost.
- //
- OldTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
- if (OldTpl == EFI_TPL_HIGH_LEVEL) {
+ gBS->RestoreTPL (CurrentTpl);
+
+ gBS->AllocatePool (EfiBootServicesData, sizeof (DATAHUB_STATUSCODE_RECORD) * 16, &Record);
+ if (Record == NULL) {
return NULL;
}
- gBS->RestoreTPL (OldTpl);
- DataBuffer = AllocateRecordBuffer ();
- if (DataBuffer == NULL) {
- return NULL;
+ EfiCommonLibZeroMem (Record, sizeof (DATAHUB_STATUSCODE_RECORD) * 16);
+
+
+ CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
+ for (Index = 1; Index < 16; Index++) {
+ InsertTailList (&mRecordsBuffer, &Record[Index].Node);
}
- EfiAcquireLock (&mStatusCodeReportLock);
- InsertHeadList (mRecordHead, &DataBuffer->Link);
- mRecordHead = mRecordHead->ForwardLink;
- mRecordNum++;
- EfiReleaseLock (&mStatusCodeReportLock);
- } else {
- EfiReleaseLock (&mStatusCodeReportLock);
- return NULL;
}
- return (DATA_HUB_STATUS_CODE_DATA_RECORD *) DataBuffer->RecordBuffer;
+ Record->Signature = BS_DATA_HUB_STATUS_CODE_SIGNATURE;
+ InsertTailList (&mRecordsFifo, &Record->Node);
+
+ gBS->RestoreTPL (CurrentTpl);
+
+ return (DATA_HUB_STATUS_CODE_DATA_RECORD *) (Record->Data);
}
-EFI_STATUS
-ReleaseRecordBuffer (
- IN STATUS_CODE_RECORD_LIST *RecordBuffer
+STATIC
+DATA_HUB_STATUS_CODE_DATA_RECORD *
+RetrieveRecord (
+ VOID
)
/*++
Routine Description:
- Release a buffer in the list, remove some nodes to keep the list inital length.
+ Retrieve one record from Records FIFO. The record would be removed from FIFO and
+ release to free record buffer.
Arguments:
- RecordBuffer - Buffer to release
+ None
Returns:
- EFI_SUCCESS - If DataRecord is valid
- EFI_UNSUPPORTED - The record list has empty
+ Point to record which is ready to be logged, or NULL if the FIFO of record is empty.
---*/
+--*/
{
- ASSERT (RecordBuffer != NULL);
+ DATA_HUB_STATUS_CODE_DATA_RECORD *RecordData;
+ DATAHUB_STATUSCODE_RECORD *Record;
+ EFI_LIST_ENTRY *Node;
+ EFI_TPL CurrentTpl;
+
+ RecordData = NULL;
+
+ CurrentTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
- //
- // The consummer needn't to be reentrient and the producer won't do any meaningful thing
- // when consummer is logging records.
- //
- if (mRecordNum <= 0) {
- return EFI_UNSUPPORTED;
- } else if (mRecordNum > INITIAL_RECORD_NUM) {
- mRecordTail = mRecordTail->ForwardLink;
- RemoveEntryList (&RecordBuffer->Link);
- mRecordNum--;
- gBS->FreePool (RecordBuffer);
- } else {
- if (mRecordNum != 1) {
- mRecordTail = mRecordTail->ForwardLink;
- }
- mRecordNum--;
+ if (!IsListEmpty (&mRecordsFifo)) {
+ Node = GetFirstNode (&mRecordsFifo);
+ Record = CR (Node, DATAHUB_STATUSCODE_RECORD, Node, BS_DATA_HUB_STATUS_CODE_SIGNATURE);
+
+ RemoveEntryList (&Record->Node);
+ InsertTailList (&mRecordsBuffer, &Record->Node);
+ Record->Signature = 0;
+ RecordData = (DATA_HUB_STATUS_CODE_DATA_RECORD *) Record->Data;
}
- return EFI_SUCCESS;
+ gBS->RestoreTPL (CurrentTpl);
+
+ return RecordData;
}
-EFI_BOOTSERVICE
EFI_STATUS
EFIAPI
BsDataHubReportStatusCode (
@@ -222,31 +174,32 @@ Returns:
--*/
{
- DATA_HUB_STATUS_CODE_DATA_RECORD *DataHub;
- UINT32 ErrorLevel;
- VA_LIST Marker;
- CHAR8 *Format;
- UINTN Index;
- CHAR16 FormatBuffer[BYTES_PER_RECORD];
-
- DataHub = NULL;
+ DATA_HUB_STATUS_CODE_DATA_RECORD *Record;
+ UINT32 ErrorLevel;
+ VA_LIST Marker;
+ CHAR8 *Format;
+ CHAR16 FormatBuffer[BYTES_PER_RECORD];
+ UINTN Index;
+ //
+ // See whether in runtime phase or not.
+ //
if (EfiAtRuntime ()) {
//
// For now all we do is post code at runtime
//
return EFI_SUCCESS;
}
+
//
- // If we had an error while in our event handler, then do nothing so
- // that we don't get in an endless loop.
+ // Discard new DataHubRecord caused by DataHub->LogData()
//
if (mEventHandlerActive) {
return EFI_SUCCESS;
}
- DataHub = (DATA_HUB_STATUS_CODE_DATA_RECORD *) AquireEmptyRecordBuffer ();
- if (DataHub == NULL) {
+ Record = AcquireRecordBuffer ();
+ if (Record == NULL) {
//
// There are no empty record buffer in private buffers
//
@@ -255,24 +208,15 @@ Returns:
//
// Construct Data Hub Extended Data
//
- DataHub->CodeType = CodeType;
- DataHub->Value = Value;
- DataHub->Instance = Instance;
+ Record->CodeType = CodeType;
+ Record->Value = Value;
+ Record->Instance = Instance;
if (CallerId != NULL) {
- EfiCopyMem (&DataHub->CallerId, CallerId, sizeof (EFI_GUID));
- } else {
- EfiZeroMem (&DataHub->CallerId, sizeof (EFI_GUID));
+ EfiCopyMem (&Record->CallerId, CallerId, sizeof (EFI_GUID));
}
- if (Data == NULL) {
- EfiZeroMem (&DataHub->Data, sizeof (EFI_STATUS_CODE_DATA));
- } else {
- //
- // Copy generic Header
- //
- EfiCopyMem (&DataHub->Data, Data, sizeof (EFI_STATUS_CODE_DATA));
-
+ if (Data != NULL) {
if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
//
// Convert Ascii Format string to Unicode.
@@ -287,26 +231,25 @@ Returns:
// Put processed string into the buffer
//
Index = VSPrint (
- (UINT16 *) (DataHub + 1),
+ (CHAR16 *) (Record + 1),
BYTES_PER_RECORD - (sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD)),
FormatBuffer,
Marker
);
-
- //
- // DATA_HUB_STATUS_CODE_DATA_RECORD followed by VSPrint String Buffer
- //
- DataHub->Data.Size = (UINT16) (Index * sizeof (CHAR16));
-
+
+ EfiCopyMem (&Record->Data.Type, &gEfiStatusCodeDataTypeDebugGuid, sizeof (EFI_GUID));
+ Record->Data.HeaderSize = Data->HeaderSize;
+ Record->Data.Size = (UINT16) (Index * sizeof (CHAR16));
} else {
//
- // Default behavior is to copy optional data
+ // Copy status code data header
//
- if (Data->Size > (BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD))) {
- DataHub->Data.Size = (UINT16) (BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD));
- }
+ EfiCopyMem (&Record->Data, Data, sizeof (EFI_STATUS_CODE_DATA));
- EfiCopyMem (DataHub + 1, Data + 1, DataHub->Data.Size);
+ if (Data->Size > BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD)) {
+ Record->Data.Size = (UINT16) (BYTES_PER_RECORD - sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD));
+ }
+ EfiCopyMem ((VOID *) (Record + 1), Data + 1, Record->Data.Size);
}
}
@@ -339,39 +282,34 @@ Returns:
--*/
{
- EFI_STATUS Status;
- DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;
- UINTN Size;
+ DATA_HUB_STATUS_CODE_DATA_RECORD *Record;
+ UINT32 Size;
UINT64 DataRecordClass;
- EFI_LIST_ENTRY *Link;
- STATUS_CODE_RECORD_LIST *BufferEntry;
//
- // Set our global flag so we don't recurse if we get an error here.
+ // Set global flag so we don't recurse if DataHub->LogData eventually causes new DataHubRecord
//
mEventHandlerActive = TRUE;
//
// Log DataRecord in Data Hub.
- // If there are multiple DataRecords, Log all of them.
+ // Journal records fifo to find all record entry.
//
- Link = mRecordTail;
-
- while (mRecordNum != 0) {
- BufferEntry = CR (Link, STATUS_CODE_RECORD_LIST, Link, BS_DATA_HUB_STATUS_CODE_SIGNATURE);
- DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (BufferEntry->RecordBuffer);
- Link = Link->ForwardLink;
-
+ while (1) {
+ Record = RetrieveRecord ();
+ if (Record == NULL) {
+ break;
+ }
//
// Add in the size of the header we added.
//
- Size = sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD) + DataRecord->Data.Size;
+ Size = sizeof (DATA_HUB_STATUS_CODE_DATA_RECORD) + (UINT32) Record->Data.Size;
- if ((DataRecord->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
+ if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
DataRecordClass = EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
- } else if ((DataRecord->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
+ } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
DataRecordClass = EFI_DATA_RECORD_CLASS_ERROR;
- } else if ((DataRecord->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
+ } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG;
} else {
//
@@ -383,45 +321,27 @@ Returns:
EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
}
- if (((DataRecord->Instance & EFI_D_ERROR) != 0) &&
- (((DataRecord->Instance & EFI_D_POOL) != 0) || ((DataRecord->Instance & EFI_D_PAGE) != 0))
- ) {
- //
- // If memory error, do not call LogData ().
- //
- ErrorPrint (L"ERROR", "Memory Error\n");
- Status = EFI_OUT_OF_RESOURCES;
- } else {
- //
- // We don't log EFI_D_POOL and EFI_D_PAGE debug info to datahub
- // to avoid recursive logging due to the memory allocation in datahub
- //
- if (DataRecordClass != EFI_DATA_RECORD_CLASS_DEBUG ||
- ((DataRecord->Instance & EFI_D_POOL) == 0 && (DataRecord->Instance & EFI_D_PAGE) == 0)) {
- //
- // Log DataRecord in Data Hub
- //
- Status = mDataHub->LogData (
- mDataHub,
- &gEfiStatusCodeGuid,
- &gEfiStatusCodeRuntimeProtocolGuid,
- DataRecordClass,
- DataRecord,
- (UINT32) Size
- );
- }
- }
+ //
+ // Log DataRecord in Data Hub
+ //
+
+ mDataHubProtocol->LogData (
+ mDataHubProtocol,
+ &gEfiStatusCodeGuid,
+ &gEfiStatusCodeRuntimeProtocolGuid,
+ DataRecordClass,
+ Record,
+ Size
+ );
- ReleaseRecordBuffer (BufferEntry);
}
mEventHandlerActive = FALSE;
- return ;
}
-EFI_BOOTSERVICE
EFI_STATUS
+EFIAPI
BsDataHubInitializeStatusCode (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
@@ -444,39 +364,15 @@ Returns:
--*/
{
EFI_STATUS Status;
- STATUS_CODE_RECORD_LIST *DataBuffer;
- UINTN Index1;
- DataBuffer = NULL;
-
- Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &mDataHub);
- //
- // Should never fail due to dependency grammer
- //
+ Status = gBS->LocateProtocol (
+ &gEfiDataHubProtocolGuid,
+ NULL,
+ (VOID **) &mDataHubProtocol
+ );
ASSERT_EFI_ERROR (Status);
//
- // Initialize a record list with length not greater than INITIAL_RECORD_NUM.
- // If no buffer can be allocated, return EFI_OUT_OF_RESOURCES.
- //
- DataBuffer = AllocateRecordBuffer ();
- if (DataBuffer == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
- mRecordHead = &DataBuffer->Link;
- mRecordTail = mRecordHead;
- InitializeListHead (mRecordHead);
-
- for (Index1 = 1; Index1 < INITIAL_RECORD_NUM; Index1++) {
- DataBuffer = AllocateRecordBuffer ();
- if (DataBuffer == NULL) {
- break;
- }
- InsertHeadList (mRecordHead, &DataBuffer->Link);
- }
-
-
- //
// Create a Notify Event to log data in Data Hub
//
Status = gBS->CreateEvent (
@@ -487,5 +383,9 @@ Returns:
&mLogDataHubEvent
);
+ ASSERT_EFI_ERROR (Status);
+
return EFI_SUCCESS;
}
+
+