📄 datahub.c
字号:
/*++
Copyright (c) 2004 - 2005, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DataHub.c
Abstract:
This code produces the Data Hub protocol. It preloads the data hub
with status information copied in from PEI HOBs.
Only code that implements the Data Hub protocol should go in this file!
The Term MTC stands for MonoTonicCounter.
For more information please look at DataHub.doc
NOTE: For extra security of the log GetNextDataRecord () could return a copy
of the data record.
--*/
#include "DataHub.h"
//
// Worker functions private to this file
//
STATIC
DATA_HUB_FILTER_DRIVER *
FindFilterDriverByEvent (
IN EFI_LIST_ENTRY *Head,
IN EFI_EVENT Event
);
STATIC
EFI_DATA_RECORD_HEADER *
GetNextDataRecord (
IN EFI_LIST_ENTRY *Head,
IN UINT64 ClassFilter,
IN OUT UINT64 *PtrCurrentMTC
);
EFI_STATUS
EFIAPI
DataHubLogData (
IN EFI_DATA_HUB_PROTOCOL *This,
IN EFI_GUID *DataRecordGuid,
IN EFI_GUID *ProducerName,
IN UINT64 DataRecordClass,
IN VOID *RawData,
IN UINT32 RawDataSize
)
/*++
Routine Description:
Log data record into the data logging hub
Arguments:
This - Protocol instance structure
DataRecordGuid - GUID that defines record contents
ProducerName - GUID that defines the name of the producer of the data
DataRecordClass - Class that defines generic record type
RawData - Data Log record as defined by DataRecordGuid
RawDataSize - Size of Data Log data in bytes
Returns:
EFI_SUCCESS - If data was logged
EFI_OUT_OF_RESOURCES - If data was not logged due to lack of system
resources.
--*/
{
EFI_STATUS Status;
DATA_HUB_INSTANCE *Private;
EFI_DATA_ENTRY *LogEntry;
UINT32 TotalSize;
UINT32 RecordSize;
EFI_DATA_RECORD_HEADER *Record;
VOID *Raw;
DATA_HUB_FILTER_DRIVER *FilterEntry;
EFI_LIST_ENTRY *Link;
EFI_LIST_ENTRY *Head;
EFI_GUID ZeroGuid = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Private = DATA_HUB_INSTANCE_FROM_THIS (This);
//
// Combine the storage for the internal structs and a copy of the log record.
// Record follows PrivateLogEntry. The consumer will be returned a pointer
// to Record so we don't what it to be the thing that was allocated from
// pool, so the consumer can't free an data record by mistake.
//
RecordSize = sizeof (EFI_DATA_RECORD_HEADER) + RawDataSize;
TotalSize = sizeof (EFI_DATA_ENTRY) + RecordSize;
//
// The Logging action is the critical section, so it is locked.
// The MTC asignment & update, time, and logging must be an
// atomic operation, so use the lock.
//
Status = EfiAcquireLockOrFail (&Private->DataLock);
if (EFI_ERROR (Status)) {
//
// Reentrancy detected so exit!
//
return Status;
}
Status = gBS->AllocatePool (EfiBootServicesData, TotalSize, (VOID **) &LogEntry);
if (EFI_ERROR (Status)) {
EfiReleaseLock (&Private->DataLock);
return EFI_OUT_OF_RESOURCES;
}
EfiZeroMem (LogEntry, TotalSize);
Record = (EFI_DATA_RECORD_HEADER *) (LogEntry + 1);
Raw = (VOID *) (Record + 1);
//
// Build Standard Log Header
//
Record->Version = EFI_DATA_RECORD_HEADER_VERSION;
Record->HeaderSize = sizeof (EFI_DATA_RECORD_HEADER);
Record->RecordSize = RecordSize;
EfiCopyMem (&Record->DataRecordGuid, DataRecordGuid, sizeof (EFI_GUID));
EfiCopyMem (&Record->ProducerName, ProducerName, sizeof (EFI_GUID));
Record->DataRecordClass = DataRecordClass;
Record->LogMonotonicCount = Private->GlobalMonotonicCount++;
gRT->GetTime (&Record->LogTime, NULL);
//
// Insert log into the internal linked list.
//
LogEntry->Signature = EFI_DATA_ENTRY_SIGNATURE;
LogEntry->Record = Record;
LogEntry->RecordSize = sizeof (EFI_DATA_ENTRY) + RawDataSize;
InsertTailList (&Private->DataListHead, &LogEntry->Link);
EfiCopyMem (Raw, RawData, RawDataSize);
EfiReleaseLock (&Private->DataLock);
//
// Send Signal to all the filter drivers which are interested
// in the record's class and guid.
//
Head = &Private->FilterDriverListHead;
for (Link = Head->ForwardLink; Link != Head; Link = Link->ForwardLink) {
FilterEntry = FILTER_ENTRY_FROM_LINK (Link);
if (((FilterEntry->ClassFilter & DataRecordClass) != 0) &&
(EfiCompareGuid (&FilterEntry->FilterDataRecordGuid, &ZeroGuid) ||
EfiCompareGuid (&FilterEntry->FilterDataRecordGuid, DataRecordGuid))) {
gBS->SignalEvent (FilterEntry->Event);
}
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
DataHubGetNextRecord (
IN EFI_DATA_HUB_PROTOCOL *This,
IN OUT UINT64 *MonotonicCount,
IN EFI_EVENT *FilterDriverEvent, OPTIONAL
OUT EFI_DATA_RECORD_HEADER **Record
)
/*++
Routine Description:
Get a previously logged data record and the MonotonicCount for the next
availible Record. This allows all records or all records later
than a give MonotonicCount to be returned. If an optional FilterDriverEvent
is passed in with a MonotonicCout of zero return the first record
not yet read by the filter driver. If FilterDriverEvent is NULL and
MonotonicCount is zero return the first data record.
Arguments:
This - The EFI_DATA_HUB_PROTOCOL instance.
MonotonicCount - Specifies the Record to return. On input, zero means
return the first record. On output, contains the next
record to availible. Zero indicates no more records.
FilterDriverEvent - If FilterDriverEvent is not passed in a MonotonicCount
of zero, it means to return the first data record.
If FilterDriverEvent is passed in, then a MonotonicCount
of zero means to return the first data not yet read by
FilterDriverEvent.
Record - Returns a dynamically allocated memory buffer with a data
record that matches MonotonicCount.
Returns:
EFI_SUCCESS - Data was returned in Record.
EFI_INVALID_PARAMETER - FilterDriverEvent was passed in but does not exist.
EFI_NOT_FOUND - MonotonicCount does not match any data record in the
system. If a MonotonicCount of zero was passed in, then
no data records exist in the system.
EFI_OUT_OF_RESOURCES - Record was not returned due to lack of system resources.
--*/
{
DATA_HUB_INSTANCE *Private;
DATA_HUB_FILTER_DRIVER *FilterDriver;
UINT64 ClassFilter;
UINT64 FilterMonotonicCount;
Private = DATA_HUB_INSTANCE_FROM_THIS (This);
FilterDriver = NULL;
FilterMonotonicCount = 0;
ClassFilter = EFI_DATA_RECORD_CLASS_DEBUG |
EFI_DATA_RECORD_CLASS_ERROR |
EFI_DATA_RECORD_CLASS_DATA |
EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
if (FilterDriverEvent != NULL) {
//
// For events the beginning is the last unread record. This info is
// stored in the instance structure, so we must look up the event
// to get the data.
//
FilterDriver = FindFilterDriverByEvent (
&Private->FilterDriverListHead,
*FilterDriverEvent
);
if (FilterDriver == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Use the Class filter the event was created with.
//
ClassFilter = FilterDriver->ClassFilter;
if (*MonotonicCount == 0) {
//
// Use the MTC from the Filter Driver.
//
FilterMonotonicCount = FilterDriver->GetNextMonotonicCount;
if (FilterMonotonicCount != 0) {
//
// The GetNextMonotonicCount field remembers the last value from the previous time.
// But we already processed this vaule, so we need to find the next one. So if
// It is not the first time get the new record entry.
//
*Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, &FilterMonotonicCount);
*MonotonicCount = FilterMonotonicCount;
if (FilterMonotonicCount == 0) {
//
// If there is no new record to get exit now.
//
return EFI_NOT_FOUND;
}
}
}
}
//
// Return the record
//
*Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);
if (*Record == NULL) {
return EFI_NOT_FOUND;
}
if (FilterDriver != NULL) {
//
// If we have a filter driver update the records that have been read.
// If MonotonicCount is zero No more reacords left.
//
if (*MonotonicCount == 0) {
if (FilterMonotonicCount != 0) {
//
// Return the result of our extra GetNextDataRecord.
//
FilterDriver->GetNextMonotonicCount = FilterMonotonicCount;
}
} else {
//
// Point to next undread record
//
FilterDriver->GetNextMonotonicCount = *MonotonicCount;
}
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
DataHubRegisterFilterDriver (
IN EFI_DATA_HUB_PROTOCOL * This,
IN EFI_EVENT FilterEvent,
IN EFI_TPL FilterTpl,
IN UINT64 FilterClass,
IN EFI_GUID * FilterDataRecordGuid OPTIONAL
)
/*++
Routine Description:
This function registers the data hub filter driver that is represented
by FilterEvent. Only one instance of each FilterEvent can be registered.
After the FilterEvent is registered, it will be signaled so it can sync
with data records that have been recorded prior to the FilterEvent being
registered.
Arguments:
This - The EFI_DATA_HUB_PROTOCOL instance.
FilterEvent - The EFI_EVENT to signal whenever data that matches
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -