bmlib.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 661 行 · 第 1/2 页
C
661 行
Size = EfiStrSize (Src);
Dest = EfiAllocateZeroPool (Size);
ASSERT (Dest != NULL);
if (Dest) {
EfiCopyMem (Dest, Src, Size);
}
return Dest;
}
EFI_FILE_INFO *
EfiLibFileInfo (
IN EFI_FILE_HANDLE FHand
)
/*++
Routine Description:
Function gets the file information from an open file descriptor, and stores it
in a buffer allocated from pool.
Arguments:
Fhand - A file handle
Returns:
A pointer to a buffer with file information or NULL is returned
--*/
{
EFI_STATUS Status;
EFI_FILE_INFO *Buffer;
UINTN BufferSize;
//
// Initialize for GrowBuffer loop
//
Buffer = NULL;
BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
//
// Call the real function
//
while (EfiGrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
Status = FHand->GetInfo (
FHand,
&gEfiFileInfoGuid,
&BufferSize,
Buffer
);
}
return Buffer;
}
UINTN
EfiDevicePathInstanceCount (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
Routine Description:
Function is used to determine the number of device path instances
that exist in a device path.
Arguments:
DevicePath - A pointer to a device path data structure.
Returns:
This function counts and returns the number of device path instances
in DevicePath.
--*/
{
UINTN Count;
UINTN Size;
Count = 0;
while (EfiDevicePathInstance (&DevicePath, &Size)) {
Count += 1;
}
return Count;
}
VOID *
EfiReallocatePool (
IN VOID *OldPool,
IN UINTN OldSize,
IN UINTN NewSize
)
/*++
Routine Description:
Adjusts the size of a previously allocated buffer.
Arguments:
OldPool - A pointer to the buffer whose size is being adjusted.
OldSize - The size of the current buffer.
NewSize - The size of the new buffer.
Returns:
EFI_SUCEESS - The requested number of bytes were allocated.
EFI_OUT_OF_RESOURCES - The pool requested could not be allocated.
EFI_INVALID_PARAMETER - The buffer was invalid.
--*/
{
VOID *NewPool;
NewPool = NULL;
if (NewSize) {
NewPool = EfiAllocateZeroPool (NewSize);
}
if (OldPool) {
if (NewPool) {
EfiCopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
}
SafeFreePool (OldPool);
}
return NewPool;
}
EFI_STATUS
EfiLibGetStringFromToken (
IN EFI_GUID *ProducerGuid,
IN STRING_REF Token,
OUT CHAR16 **String
)
/*++
Routine Description:
Acquire the string associated with the ProducerGuid and return it.
Arguments:
ProducerGuid - The Guid to search the HII database for
Token - The token value of the string to extract
String - The string that is extracted
Returns:
EFI_SUCCESS - Buffer filled with the requested forms. BufferLength
was updated.
EFI_BUFFER_TOO_SMALL - The buffer provided was not large enough to allow the form to be stored.
--*/
{
EFI_STATUS Status;
UINT16 HandleBufferLength;
EFI_HII_HANDLE *HiiHandleBuffer;
UINTN StringBufferLength;
UINTN NumberOfHiiHandles;
UINTN Index;
UINT16 Length;
EFI_GUID HiiGuid;
EFI_HII_PROTOCOL *Hii;
//
// Initialize params.
//
HandleBufferLength = 0;
HiiHandleBuffer = NULL;
Status = gBS->LocateProtocol (
&gEfiHiiProtocolGuid,
NULL,
&Hii
);
if (EFI_ERROR (Status)) {
*String = NULL;
return Status;
}
//
// Get all the Hii handles
//
Status = BdsLibGetHiiHandles (Hii, &HandleBufferLength, &HiiHandleBuffer);
ASSERT_EFI_ERROR (Status);
//
// Get the Hii Handle that matches the StructureNode->ProducerName
//
NumberOfHiiHandles = HandleBufferLength / sizeof (EFI_HII_HANDLE);
for (Index = 0; Index < NumberOfHiiHandles; Index++) {
Length = 0;
Status = ExtractDataFromHiiHandle (
HiiHandleBuffer[Index],
&Length,
NULL,
&HiiGuid
);
if (EfiCompareGuid (ProducerGuid, &HiiGuid)) {
break;
}
}
//
// Find the string based on the current language
//
StringBufferLength = 0x100;
*String = EfiLibAllocateZeroPool (0x100);
ASSERT (*String != NULL);
Status = Hii->GetString (
Hii,
HiiHandleBuffer[Index],
Token,
FALSE,
NULL,
&StringBufferLength,
*String
);
gBS->FreePool (HiiHandleBuffer);
return Status;
}
BOOLEAN
TimeCompare (
IN EFI_TIME *FirstTime,
IN EFI_TIME *SecondTime
)
/*++
Routine Description:
Compare two EFI_TIME data.
Arguments:
FirstTime - A pointer to the first EFI_TIME data.
SecondTime - A pointer to the second EFI_TIME data.
Returns:
TRUE The FirstTime is not later than the SecondTime.
FALSE The FirstTime is later than the SecondTime.
--*/
{
if (FirstTime->Year != SecondTime->Year) {
return (BOOLEAN) (FirstTime->Year < SecondTime->Year);
} else if (FirstTime->Month != SecondTime->Month) {
return (BOOLEAN) (FirstTime->Month < SecondTime->Month);
} else if (FirstTime->Day != SecondTime->Day) {
return (BOOLEAN) (FirstTime->Day < SecondTime->Day);
} else if (FirstTime->Hour != SecondTime->Hour) {
return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour);
} else if (FirstTime->Minute != SecondTime->Minute) {
return (BOOLEAN) (FirstTime->Minute < FirstTime->Minute);
} else if (FirstTime->Second != SecondTime->Second) {
return (BOOLEAN) (FirstTime->Second < SecondTime->Second);
}
return (BOOLEAN) (FirstTime->Nanosecond <= SecondTime->Nanosecond);
}
UINT16 *
EfiLibStrFromDatahub (
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
)
{
EFI_STATUS Status;
UINT16 *Desc;
EFI_DATA_HUB_PROTOCOL *Datahub;
UINT64 Count;
EFI_DATA_RECORD_HEADER *Record;
EFI_SUBCLASS_TYPE1_HEADER *DataHdr;
EFI_GUID MiscGuid = EFI_MISC_SUBCLASS_GUID;
EFI_MISC_ONBOARD_DEVICE *ob;
EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *Port;
EFI_TIME CurTime;
Status = gBS->LocateProtocol (
&gEfiDataHubProtocolGuid,
NULL,
&Datahub
);
if (EFI_ERROR (Status)) {
return NULL;
}
Status = gRT->GetTime (&CurTime, NULL);
if (EFI_ERROR (Status)) {
return NULL;
}
Count = 0;
do {
Status = Datahub->GetNextRecord (Datahub, &Count, NULL, &Record);
if (EFI_ERROR (Status)) {
break;
}
if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA && EfiCompareGuid (&Record->DataRecordGuid, &MiscGuid)) {
//
// This record is what we need
//
DataHdr = (EFI_SUBCLASS_TYPE1_HEADER *) (Record + 1);
if (EFI_MISC_ONBOARD_DEVICE_RECORD_NUMBER == DataHdr->RecordType) {
ob = (EFI_MISC_ONBOARD_DEVICE *) (DataHdr + 1);
if (BdsLibMatchDevicePaths ((EFI_DEVICE_PATH_PROTOCOL *) &ob->OnBoardDevicePath, DevPath)) {
EfiLibGetStringFromToken (&Record->ProducerName, ob->OnBoardDeviceDescription, &Desc);
return Desc;
}
}
if (EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_RECORD_NUMBER == DataHdr->RecordType) {
Port = (EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *) (DataHdr + 1);
if (BdsLibMatchDevicePaths ((EFI_DEVICE_PATH_PROTOCOL *) &Port->PortPath, DevPath)) {
EfiLibGetStringFromToken (&Record->ProducerName, Port->PortExternalConnectorDesignator, &Desc);
return Desc;
}
}
}
} while (TimeCompare (&Record->LogTime, &CurTime) && Count != 0);
return NULL;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?