Initial import.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
795
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsBoot.c
Normal file
795
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsBoot.c
Normal file
@@ -0,0 +1,795 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
BdsBoot.c
|
||||
|
||||
Abstract:
|
||||
|
||||
BDS Lib functions which relate with create or process the boot
|
||||
option.
|
||||
|
||||
--*/
|
||||
#include "Performance.h"
|
||||
|
||||
BOOLEAN mEnumBootDevice = FALSE;
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibDoLegacyBoot (
|
||||
IN BDS_COMMON_OPTION *Option
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Boot the legacy system with the boot option
|
||||
|
||||
Arguments:
|
||||
|
||||
Option - The legacy boot option which have BBS device path
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_UNSUPPORTED - There is no legacybios protocol, do not support
|
||||
legacy boot.
|
||||
|
||||
EFI_STATUS - Return the status of LegacyBios->LegacyBoot ().
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
|
||||
|
||||
Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios);
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// If no LegacyBios protocol we do not support legacy boot
|
||||
//
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// Notes: if we seperate the int 19, then we don't need to refresh BBS
|
||||
//
|
||||
BdsRefreshBbsTableForBoot (Option);
|
||||
|
||||
//
|
||||
// Write boot to OS performance data to a file
|
||||
//
|
||||
PERF_CODE (
|
||||
WriteBootToOsPerformanceData ();
|
||||
);
|
||||
|
||||
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Legacy Boot: %S\n", Option->Description));
|
||||
return LegacyBios->LegacyBoot (
|
||||
LegacyBios,
|
||||
(BBS_BBS_DEVICE_PATH *) Option->DevicePath,
|
||||
Option->LoadOptionsSize,
|
||||
Option->LoadOptions
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibBootViaBootOption (
|
||||
IN BDS_COMMON_OPTION * Option,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
|
||||
OUT UINTN *ExitDataSize,
|
||||
OUT CHAR16 **ExitData OPTIONAL
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Process the boot option follow the EFI 1.1 specification and
|
||||
special treat the legacy boot option with BBS_DEVICE_PATH.
|
||||
|
||||
Arguments:
|
||||
|
||||
Option - The boot option need to be processed
|
||||
|
||||
DevicePath - The device path which describe where to load
|
||||
the boot image or the legcy BBS device path
|
||||
to boot the legacy OS
|
||||
|
||||
ExitDataSize - Returned directly from gBS->StartImage ()
|
||||
|
||||
ExitData - Returned directly from gBS->StartImage ()
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - Status from gBS->StartImage (),
|
||||
or BdsBootByDiskSignatureAndPartition ()
|
||||
|
||||
EFI_NOT_FOUND - If the Device Path is not found in the system
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_HANDLE ImageHandle;
|
||||
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *FilePath;
|
||||
EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
|
||||
EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
|
||||
|
||||
*ExitDataSize = 0;
|
||||
*ExitData = NULL;
|
||||
|
||||
//
|
||||
// Notes: put EFI64 ROM Shadow Solution
|
||||
//
|
||||
EFI64_SHADOW_ALL_LEGACY_ROM ();
|
||||
|
||||
//
|
||||
// Notes: this code can be remove after the s3 script table
|
||||
// hook on the event EFI_EVENT_SIGNAL_READY_TO_BOOT or
|
||||
// EFI_EVENT_SIGNAL_LEGACY_BOOT
|
||||
//
|
||||
Status = gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, &AcpiS3Save);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
AcpiS3Save->S3Save (AcpiS3Save, NULL);
|
||||
}
|
||||
//
|
||||
// If it's Device Path that starts with a hard drive path,
|
||||
// this routine will do the booting.
|
||||
//
|
||||
Status = BdsBootByDiskSignatureAndPartition (
|
||||
Option,
|
||||
(HARDDRIVE_DEVICE_PATH *) DevicePath,
|
||||
Option->LoadOptionsSize,
|
||||
Option->LoadOptions,
|
||||
ExitDataSize,
|
||||
ExitData
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// If we found a disk signature and partition device path return success
|
||||
//
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EfiSignalEventReadyToBoot ();
|
||||
|
||||
//
|
||||
// Set Boot Current
|
||||
//
|
||||
gRT->SetVariable (
|
||||
L"BootCurrent",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
sizeof (UINT16),
|
||||
&Option->BootCurrent
|
||||
);
|
||||
|
||||
if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&
|
||||
(DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)
|
||||
) {
|
||||
//
|
||||
// Check to see if we should legacy BOOT. If yes then do the legacy boot
|
||||
//
|
||||
return BdsLibDoLegacyBoot (Option);
|
||||
}
|
||||
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Booting EFI 1.1 way %S\n", Option->Description));
|
||||
|
||||
Status = gBS->LoadImage (
|
||||
TRUE,
|
||||
mBdsImageHandle,
|
||||
DevicePath,
|
||||
NULL,
|
||||
0,
|
||||
&ImageHandle
|
||||
);
|
||||
|
||||
//
|
||||
// If we didn't find an image, we may need to load the default
|
||||
// boot behavior for the device.
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// Find a Simple File System protocol on the device path. If the remaining
|
||||
// device path is set to end then no Files are being specified, so try
|
||||
// the removable media file name.
|
||||
//
|
||||
TempDevicePath = DevicePath;
|
||||
Status = gBS->LocateDevicePath (
|
||||
&gEfiSimpleFileSystemProtocolGuid,
|
||||
&TempDevicePath,
|
||||
&Handle
|
||||
);
|
||||
if (!EFI_ERROR (Status) && IsDevicePathEnd (TempDevicePath)) {
|
||||
FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
|
||||
if (FilePath) {
|
||||
Status = gBS->LoadImage (
|
||||
TRUE,
|
||||
mBdsImageHandle,
|
||||
FilePath,
|
||||
NULL,
|
||||
0,
|
||||
&ImageHandle
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// The DevicePath failed, and it's not a valid
|
||||
// removable media device.
|
||||
//
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Status = EFI_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// It there is any error from the Boot attempt exit now.
|
||||
//
|
||||
goto Done;
|
||||
}
|
||||
//
|
||||
// Provide the image with it's load options
|
||||
//
|
||||
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, &ImageInfo);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
if (Option->LoadOptionsSize != 0) {
|
||||
ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
|
||||
ImageInfo->LoadOptions = Option->LoadOptions;
|
||||
}
|
||||
//
|
||||
// Before calling the image, enable the Watchdog Timer for
|
||||
// the 5 Minute period
|
||||
//
|
||||
gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
|
||||
|
||||
Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Image Return Status = %r\n", Status));
|
||||
|
||||
//
|
||||
// Clear the Watchdog Timer after the image returns
|
||||
//
|
||||
gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
|
||||
|
||||
Done:
|
||||
//
|
||||
// Clear Boot Current
|
||||
//
|
||||
gRT->SetVariable (
|
||||
L"BootCurrent",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
0,
|
||||
&Option->BootCurrent
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsBootByDiskSignatureAndPartition (
|
||||
IN BDS_COMMON_OPTION * Option,
|
||||
IN HARDDRIVE_DEVICE_PATH * HardDriveDevicePath,
|
||||
IN UINT32 LoadOptionsSize,
|
||||
IN VOID *LoadOptions,
|
||||
OUT UINTN *ExitDataSize,
|
||||
OUT CHAR16 **ExitData OPTIONAL
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Check to see if a hard ware device path was passed in. If it was then search
|
||||
all the block IO devices for the passed in hard drive device path.
|
||||
|
||||
Arguments:
|
||||
|
||||
Option - The current processing boot option.
|
||||
|
||||
HardDriveDevicePath - EFI Device Path to boot, if it starts with a hard
|
||||
drive device path.
|
||||
|
||||
LoadOptionsSize - Passed into gBS->StartImage ()
|
||||
via the loaded image protocol.
|
||||
|
||||
LoadOptions - Passed into gBS->StartImage ()
|
||||
via the loaded image protocol.
|
||||
|
||||
ExitDataSize - returned directly from gBS->StartImage ()
|
||||
|
||||
ExitData - returned directly from gBS->StartImage ()
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - Status from gBS->StartImage (),
|
||||
or BootByDiskSignatureAndPartition ()
|
||||
|
||||
EFI_NOT_FOUND - If the Device Path is not found in the system
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN BlockIoHandleCount;
|
||||
EFI_HANDLE *BlockIoBuffer;
|
||||
EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *BlockIoHdDevicePath;
|
||||
HARDDRIVE_DEVICE_PATH *TmpHdPath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||
UINTN Index;
|
||||
BOOLEAN DevicePathMatch;
|
||||
HARDDRIVE_DEVICE_PATH *TempPath;
|
||||
|
||||
*ExitDataSize = 0;
|
||||
*ExitData = NULL;
|
||||
|
||||
if ( !((DevicePathType (&HardDriveDevicePath->Header) == MEDIA_DEVICE_PATH) &&
|
||||
(DevicePathSubType (&HardDriveDevicePath->Header) == MEDIA_HARDDRIVE_DP))
|
||||
) {
|
||||
//
|
||||
// If the HardDriveDevicePath does not start with a Hard Drive Device Path
|
||||
// exit.
|
||||
//
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
//
|
||||
// The boot device have already been connected
|
||||
//
|
||||
Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);
|
||||
if (EFI_ERROR (Status) || BlockIoHandleCount == 0) {
|
||||
//
|
||||
// If there was an error or there are no device handles that support
|
||||
// the BLOCK_IO Protocol, then return.
|
||||
//
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
//
|
||||
// Loop through all the device handles that support the BLOCK_IO Protocol
|
||||
//
|
||||
for (Index = 0; Index < BlockIoHandleCount; Index++) {
|
||||
|
||||
Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);
|
||||
if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {
|
||||
continue;
|
||||
}
|
||||
//
|
||||
// Make PreviousDevicePath == the device path node before the end node
|
||||
//
|
||||
DevicePath = BlockIoDevicePath;
|
||||
BlockIoHdDevicePath = NULL;
|
||||
|
||||
//
|
||||
// find HardDriver device path node
|
||||
//
|
||||
while (!IsDevicePathEnd (DevicePath)) {
|
||||
if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
|
||||
(DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
|
||||
) {
|
||||
BlockIoHdDevicePath = DevicePath;
|
||||
break;
|
||||
}
|
||||
|
||||
DevicePath = NextDevicePathNode (DevicePath);
|
||||
}
|
||||
|
||||
if (BlockIoHdDevicePath == NULL) {
|
||||
continue;
|
||||
}
|
||||
//
|
||||
// See if the harddrive device path in blockio matches the orig Hard Drive Node
|
||||
//
|
||||
DevicePathMatch = FALSE;
|
||||
|
||||
TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePath;
|
||||
TempPath = (HARDDRIVE_DEVICE_PATH *) BdsLibUnpackDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
|
||||
|
||||
//
|
||||
// Only several fields will be checked. NOT whole NODE
|
||||
//
|
||||
if ( TmpHdPath->PartitionNumber == TempPath->PartitionNumber &&
|
||||
TmpHdPath->MBRType == TempPath->MBRType &&
|
||||
TmpHdPath->SignatureType == TempPath->SignatureType &&
|
||||
CompareGuid ((EFI_GUID *) TmpHdPath->Signature, (EFI_GUID *) TempPath->Signature)) {
|
||||
//
|
||||
// Get the matched device path
|
||||
//
|
||||
DevicePathMatch = TRUE;
|
||||
}
|
||||
//
|
||||
// Only do the boot, when devicepath match
|
||||
//
|
||||
if (DevicePathMatch) {
|
||||
//
|
||||
// Combine the Block IO and Hard Drive Device path together and try
|
||||
// to boot from it.
|
||||
//
|
||||
DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
|
||||
NewDevicePath = AppendDevicePath (BlockIoDevicePath, DevicePath);
|
||||
|
||||
//
|
||||
// Recursive boot with new device path
|
||||
//
|
||||
Status = BdsLibBootViaBootOption (Option, NewDevicePath, ExitDataSize, ExitData);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (BlockIoBuffer);
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibEnumerateAllBootOption (
|
||||
IN OUT LIST_ENTRY *BdsBootOptionList
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will enumerate all possible boot device in the system,
|
||||
it will only excute once of every boot.
|
||||
|
||||
Arguments:
|
||||
|
||||
BdsBootOptionList - The header of the link list which indexed all
|
||||
current boot options
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - Finished all the boot device enumerate and create
|
||||
the boot option base on that boot device
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT16 BootOptionNumber;
|
||||
UINTN NumberFileSystemHandles;
|
||||
EFI_HANDLE *FileSystemHandles;
|
||||
UINTN NumberBlkIoHandles;
|
||||
EFI_HANDLE *BlkIoHandles;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlkIo;
|
||||
UINTN Index;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
UINTN NumberLoadFileHandles;
|
||||
EFI_HANDLE *LoadFileHandles;
|
||||
VOID *ProtocolInstance;
|
||||
EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
|
||||
UINTN FvHandleCount;
|
||||
EFI_HANDLE *FvHandleBuffer;
|
||||
EFI_FV_FILETYPE Type;
|
||||
UINTN Size;
|
||||
EFI_FV_FILE_ATTRIBUTES Attributes;
|
||||
UINT32 AuthenticationStatus;
|
||||
|
||||
BootOptionNumber = 0;
|
||||
|
||||
//
|
||||
// If the boot device enumerate happened, just get the boot
|
||||
// device from the boot order variable
|
||||
//
|
||||
if (mEnumBootDevice) {
|
||||
BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
//
|
||||
// Notes: this dirty code is to get the legacy boot option from the
|
||||
// BBS table and create to variable as the EFI boot option, it should
|
||||
// be removed after the CSM can provide legacy boot option directly
|
||||
//
|
||||
REFRESH_LEGACY_BOOT_OPTIONS;
|
||||
|
||||
//
|
||||
// Check all the block IO to create boot option
|
||||
//
|
||||
gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
NULL,
|
||||
&NumberBlkIoHandles,
|
||||
&BlkIoHandles
|
||||
);
|
||||
for (Index = 0; Index < NumberBlkIoHandles; Index++) {
|
||||
Status = gBS->HandleProtocol (
|
||||
BlkIoHandles[Index],
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
(VOID **) &BlkIo
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!BlkIo->Media->RemovableMedia) {
|
||||
//
|
||||
// Skip fixed Media device on first loop interration
|
||||
//
|
||||
continue;
|
||||
}
|
||||
|
||||
DevicePath = DevicePathFromHandle (BlkIoHandles[Index]);
|
||||
if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
|
||||
(DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
|
||||
) {
|
||||
//
|
||||
// Build the boot option
|
||||
//
|
||||
BdsLibBuildOptionFromHandle (BlkIoHandles[Index], BdsBootOptionList);
|
||||
BootOptionNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
if (NumberBlkIoHandles) {
|
||||
gBS->FreePool (BlkIoHandles);
|
||||
}
|
||||
//
|
||||
// Parse Fixed Disk Devices.
|
||||
//
|
||||
gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiSimpleFileSystemProtocolGuid,
|
||||
NULL,
|
||||
&NumberFileSystemHandles,
|
||||
&FileSystemHandles
|
||||
);
|
||||
for (Index = 0; Index < NumberFileSystemHandles; Index++) {
|
||||
Status = gBS->HandleProtocol (
|
||||
FileSystemHandles[Index],
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
(VOID **) &BlkIo
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
if (BlkIo->Media->RemovableMedia) {
|
||||
//
|
||||
// If the file system handle supports a BlkIo protocol,
|
||||
// skip the removable media devices
|
||||
//
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
DevicePath = DevicePathFromHandle (FileSystemHandles[Index]);
|
||||
if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
|
||||
(DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
|
||||
) {
|
||||
//
|
||||
// If the FileSystem protocol does not contain a BlkIo protocol,
|
||||
// then build it
|
||||
//
|
||||
BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList);
|
||||
BootOptionNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
if (NumberFileSystemHandles) {
|
||||
gBS->FreePool (FileSystemHandles);
|
||||
}
|
||||
//
|
||||
// Parse Network Boot Device
|
||||
//
|
||||
gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiSimpleNetworkProtocolGuid,
|
||||
NULL,
|
||||
&NumberLoadFileHandles,
|
||||
&LoadFileHandles
|
||||
);
|
||||
for (Index = 0; Index < NumberLoadFileHandles; Index++) {
|
||||
Status = gBS->HandleProtocol (
|
||||
LoadFileHandles[Index],
|
||||
&gEfiLoadFileProtocolGuid,
|
||||
(VOID **) &ProtocolInstance
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList);
|
||||
BootOptionNumber++;
|
||||
}
|
||||
|
||||
if (NumberLoadFileHandles) {
|
||||
gBS->FreePool (LoadFileHandles);
|
||||
}
|
||||
//
|
||||
// Check if we have on flash shell
|
||||
//
|
||||
gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiFirmwareVolumeProtocolGuid,
|
||||
NULL,
|
||||
&FvHandleCount,
|
||||
&FvHandleBuffer
|
||||
);
|
||||
for (Index = 0; Index < FvHandleCount; Index++) {
|
||||
gBS->HandleProtocol (
|
||||
FvHandleBuffer[Index],
|
||||
&gEfiFirmwareVolumeProtocolGuid,
|
||||
(VOID **) &Fv
|
||||
);
|
||||
|
||||
Status = Fv->ReadFile (
|
||||
Fv,
|
||||
&gEfiShellFileGuid,
|
||||
NULL,
|
||||
&Size,
|
||||
&Type,
|
||||
&Attributes,
|
||||
&AuthenticationStatus
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// Skip if no shell file in the FV
|
||||
//
|
||||
continue;
|
||||
}
|
||||
//
|
||||
// Build the shell boot option
|
||||
//
|
||||
BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
|
||||
BootOptionNumber++;
|
||||
}
|
||||
|
||||
if (FvHandleCount) {
|
||||
gBS->FreePool (FvHandleBuffer);
|
||||
}
|
||||
//
|
||||
// Make sure every boot only have one time
|
||||
// boot device enumerate
|
||||
//
|
||||
BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
|
||||
mEnumBootDevice = TRUE;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibBuildOptionFromHandle (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN LIST_ENTRY *BdsBootOptionList
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Build the boot option with the handle parsed in
|
||||
|
||||
Arguments:
|
||||
|
||||
Handle - The handle which present the device path to create boot option
|
||||
|
||||
BdsBootOptionList - The header of the link list which indexed all current
|
||||
boot options
|
||||
|
||||
Returns:
|
||||
|
||||
VOID
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
CHAR16 *TempString;
|
||||
|
||||
DevicePath = DevicePathFromHandle (Handle);
|
||||
TempString = DevicePathToStr (DevicePath);
|
||||
|
||||
//
|
||||
// Create and register new boot option
|
||||
//
|
||||
BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, TempString, L"BootOrder");
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibBuildOptionFromShell (
|
||||
IN EFI_HANDLE Handle,
|
||||
IN OUT LIST_ENTRY *BdsBootOptionList
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Build the on flash shell boot option with the handle parsed in
|
||||
|
||||
Arguments:
|
||||
|
||||
Handle - The handle which present the device path to create on flash shell
|
||||
boot option
|
||||
|
||||
BdsBootOptionList - The header of the link list which indexed all current
|
||||
boot options
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode;
|
||||
|
||||
DevicePath = DevicePathFromHandle (Handle);
|
||||
|
||||
//
|
||||
// Build the shell device path
|
||||
//
|
||||
EfiInitializeFwVolDevicepathNode (&ShellNode, &gEfiShellFileGuid);
|
||||
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);
|
||||
|
||||
//
|
||||
// Create and register the shell boot option
|
||||
//
|
||||
BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"Internal EFI Shell", L"BootOrder");
|
||||
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibBootNext (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Boot from the EFI1.1 spec defined "BootNext" variable
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT16 *BootNext;
|
||||
UINTN BootNextSize;
|
||||
CHAR16 Buffer[20];
|
||||
BDS_COMMON_OPTION *BootOption;
|
||||
LIST_ENTRY TempList;
|
||||
UINTN ExitDataSize;
|
||||
CHAR16 *ExitData;
|
||||
|
||||
//
|
||||
// Init the boot option name buffer and temp link list
|
||||
//
|
||||
InitializeListHead (&TempList);
|
||||
ZeroMem (Buffer, sizeof (Buffer));
|
||||
|
||||
BootNext = BdsLibGetVariableAndSize (
|
||||
L"BootNext",
|
||||
&gEfiGlobalVariableGuid,
|
||||
&BootNextSize
|
||||
);
|
||||
|
||||
//
|
||||
// Clear the boot next variable first
|
||||
//
|
||||
if (BootNext != NULL) {
|
||||
gRT->SetVariable (
|
||||
L"BootNext",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
0,
|
||||
BootNext
|
||||
);
|
||||
|
||||
//
|
||||
// Start to build the boot option and try to boot
|
||||
//
|
||||
UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext);
|
||||
BootOption = BdsLibVariableToOption (&TempList, Buffer);
|
||||
BdsLibConnectDevicePath (BootOption->DevicePath);
|
||||
BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
|
||||
}
|
||||
|
||||
}
|
357
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c
Normal file
357
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c
Normal file
@@ -0,0 +1,357 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
BdsConnect.c
|
||||
|
||||
Abstract:
|
||||
|
||||
BDS Lib functions which relate with connect the device
|
||||
|
||||
--*/
|
||||
|
||||
VOID
|
||||
BdsLibConnectAll (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will connect all the system driver to controller
|
||||
first, and then special connect the default console, this make
|
||||
sure all the system controller avialbe and the platform default
|
||||
console connected.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// Connect the platform console first
|
||||
//
|
||||
BdsLibConnectAllDefaultConsoles ();
|
||||
|
||||
//
|
||||
// Generic way to connect all the drivers
|
||||
//
|
||||
BdsLibConnectAllDriversToAllControllers ();
|
||||
|
||||
//
|
||||
// Here we have the assumption that we have already had
|
||||
// platform default console
|
||||
//
|
||||
BdsLibConnectAllDefaultConsoles ();
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibGenericConnectAll (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will connect all the system drivers to all controllers
|
||||
first, and then connect all the console devices the system current
|
||||
have. After this we should get all the device work and console avariable
|
||||
if the system have console device.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// Most generic way to connect all the drivers
|
||||
//
|
||||
BdsLibConnectAllDriversToAllControllers ();
|
||||
BdsLibConnectAllConsoles ();
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibConnectDevicePath (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
This function will create all handles associate with every device
|
||||
path node. If the handle associate with one device path node can not
|
||||
be created success, then still give one chance to do the dispatch,
|
||||
which load the missing drivers if possible.
|
||||
|
||||
Arguments:
|
||||
|
||||
DevicePathToConnect - The device path which will be connected, it can
|
||||
be a multi-instance device path
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - All handles associate with every device path
|
||||
node have been created
|
||||
|
||||
EFI_OUT_OF_RESOURCES - There is no resource to create new handles
|
||||
|
||||
EFI_NOT_FOUND - Create the handle associate with one device
|
||||
path node failed
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Instance;
|
||||
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Next;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_HANDLE PreviousHandle;
|
||||
UINTN Size;
|
||||
|
||||
if (DevicePathToConnect == NULL) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
DevicePath = DuplicateDevicePath (DevicePathToConnect);
|
||||
CopyOfDevicePath = DevicePath;
|
||||
if (DevicePath == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
do {
|
||||
//
|
||||
// The outer loop handles multi instance device paths.
|
||||
// Only console variables contain multiple instance device paths.
|
||||
//
|
||||
// After this call DevicePath points to the next Instance
|
||||
//
|
||||
Instance = GetNextDevicePathInstance (&DevicePath, &Size);
|
||||
Next = Instance;
|
||||
while (!IsDevicePathEndType (Next)) {
|
||||
Next = NextDevicePathNode (Next);
|
||||
}
|
||||
|
||||
SetDevicePathEndNode (Next);
|
||||
|
||||
//
|
||||
// Start the real work of connect with RemainingDevicePath
|
||||
//
|
||||
PreviousHandle = NULL;
|
||||
do {
|
||||
//
|
||||
// Find the handle that best matches the Device Path. If it is only a
|
||||
// partial match the remaining part of the device path is returned in
|
||||
// RemainingDevicePath.
|
||||
//
|
||||
RemainingDevicePath = Instance;
|
||||
Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
if (Handle == PreviousHandle) {
|
||||
//
|
||||
// If no forward progress is made try invoking the Dispatcher.
|
||||
// A new FV may have been added to the system an new drivers
|
||||
// may now be found.
|
||||
// Status == EFI_SUCCESS means a driver was dispatched
|
||||
// Status == EFI_NOT_FOUND means no new drivers were dispatched
|
||||
//
|
||||
Status = gDS->Dispatch ();
|
||||
}
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
PreviousHandle = Handle;
|
||||
//
|
||||
// Connect all drivers that apply to Handle and RemainingDevicePath,
|
||||
// the Recursive flag is FALSE so only one level will be expanded.
|
||||
//
|
||||
// Do not check the connect status here, if the connect controller fail,
|
||||
// then still give the chance to do dispatch, because partial
|
||||
// RemainingDevicepath may be in the new FV
|
||||
//
|
||||
// 1. If the connect fail, RemainingDevicepath and handle will not
|
||||
// change, so next time will do the dispatch, then dispatch's status
|
||||
// will take effect
|
||||
// 2. If the connect success, the RemainingDevicepath and handle will
|
||||
// change, then avoid the dispatch, we have chance to continue the
|
||||
// next connection
|
||||
//
|
||||
gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Loop until RemainingDevicePath is an empty device path
|
||||
//
|
||||
} while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath));
|
||||
|
||||
} while (DevicePath != NULL);
|
||||
|
||||
if (CopyOfDevicePath != NULL) {
|
||||
gBS->FreePool (CopyOfDevicePath);
|
||||
}
|
||||
//
|
||||
// All handle with DevicePath exists in the handle database
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibConnectAllEfi (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will connect all current system handles recursively. The
|
||||
connection will finish until every handle's child handle created if it have.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - All handles and it's child handle have been connected
|
||||
|
||||
EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
UINTN Index;
|
||||
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
AllHandles,
|
||||
NULL,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&HandleBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < HandleCount; Index++) {
|
||||
Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
|
||||
}
|
||||
|
||||
gBS->FreePool (HandleBuffer);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibDisconnectAllEfi (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will disconnect all current system handles. The disconnection
|
||||
will finish until every handle have been disconnected.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - All handles have been disconnected
|
||||
|
||||
EFI_STATUS - Return the status of gBS->LocateHandleBuffer().
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
UINTN Index;
|
||||
|
||||
//
|
||||
// Disconnect all
|
||||
//
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
AllHandles,
|
||||
NULL,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&HandleBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < HandleCount; Index++) {
|
||||
Status = gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
|
||||
}
|
||||
|
||||
gBS->FreePool (HandleBuffer);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibConnectAllDriversToAllControllers (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Connects all drivers to all controllers.
|
||||
This function make sure all the current system driver will manage
|
||||
the correspoinding controllers if have. And at the same time, make
|
||||
sure all the system controllers have driver to manage it if have.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
do {
|
||||
//
|
||||
// Connect All EFI 1.10 drivers following EFI 1.10 algorithm
|
||||
//
|
||||
BdsLibConnectAllEfi ();
|
||||
|
||||
//
|
||||
// Check to see if it's possible to dispatch an more DXE drivers.
|
||||
// The BdsLibConnectAllEfi () may have made new DXE drivers show up.
|
||||
// If anything is Dispatched Status == EFI_SUCCESS and we will try
|
||||
// the connect again.
|
||||
//
|
||||
Status = gDS->Dispatch ();
|
||||
|
||||
} while (!EFI_ERROR (Status));
|
||||
|
||||
}
|
370
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c
Normal file
370
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c
Normal file
@@ -0,0 +1,370 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
BdsConsole.c
|
||||
|
||||
Abstract:
|
||||
|
||||
BDS Lib functions which contain all the code to connect console device
|
||||
|
||||
--*/
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibUpdateConsoleVariable (
|
||||
IN CHAR16 *ConVarName,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function update console variable based on ConVarName, it can
|
||||
add or remove one specific console device path from the variable
|
||||
|
||||
Arguments:
|
||||
|
||||
ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
|
||||
|
||||
CustomizedConDevicePath - The console device path which will be added to
|
||||
the console variable ConVarName, this parameter
|
||||
can not be multi-instance.
|
||||
|
||||
ExclusiveDevicePath - The console device path which will be removed
|
||||
from the console variable ConVarName, this
|
||||
parameter can not be multi-instance.
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_UNSUPPORTED - Add or remove the same device path.
|
||||
|
||||
EFI_SUCCESS - Success add or remove the device path from
|
||||
the console variable.
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DEVICE_PATH_PROTOCOL *VarConsole;
|
||||
UINTN DevicePathSize;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Instance;
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||
|
||||
VarConsole = NULL;
|
||||
DevicePathSize = 0;
|
||||
NewDevicePath = NULL;
|
||||
Status = EFI_UNSUPPORTED;
|
||||
|
||||
//
|
||||
// Notes: check the device path point, here should check
|
||||
// with compare memory
|
||||
//
|
||||
if (CustomizedConDevicePath == ExclusiveDevicePath) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
//
|
||||
// Delete the ExclusiveDevicePath from current default console
|
||||
//
|
||||
VarConsole = BdsLibGetVariableAndSize (
|
||||
ConVarName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&DevicePathSize
|
||||
);
|
||||
|
||||
if (ExclusiveDevicePath != NULL && VarConsole != NULL) {
|
||||
if (BdsLibMatchDevicePaths (VarConsole, ExclusiveDevicePath)) {
|
||||
|
||||
Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize);
|
||||
|
||||
while (VarConsole != NULL) {
|
||||
if (CompareMem (
|
||||
Instance,
|
||||
ExclusiveDevicePath,
|
||||
DevicePathSize - sizeof (EFI_DEVICE_PATH_PROTOCOL)
|
||||
) == 0) {
|
||||
//
|
||||
// Remove the match part
|
||||
//
|
||||
NewDevicePath = AppendDevicePathInstance (NewDevicePath, VarConsole);
|
||||
break;
|
||||
} else {
|
||||
//
|
||||
// Continue the next instance
|
||||
//
|
||||
NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
|
||||
}
|
||||
|
||||
Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize);
|
||||
}
|
||||
//
|
||||
// Reset the console variable with new device path
|
||||
//
|
||||
gRT->SetVariable (
|
||||
ConVarName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
GetDevicePathSize (NewDevicePath),
|
||||
NewDevicePath
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Try to append customized device path
|
||||
//
|
||||
VarConsole = BdsLibGetVariableAndSize (
|
||||
ConVarName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&DevicePathSize
|
||||
);
|
||||
|
||||
if (CustomizedConDevicePath != NULL) {
|
||||
if (!BdsLibMatchDevicePaths (VarConsole, CustomizedConDevicePath)) {
|
||||
//
|
||||
// In the first check, the default console variable will be null,
|
||||
// just append current customized device path
|
||||
//
|
||||
VarConsole = AppendDevicePathInstance (VarConsole, CustomizedConDevicePath);
|
||||
|
||||
//
|
||||
// Update the variable of the default console
|
||||
//
|
||||
gRT->SetVariable (
|
||||
ConVarName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
GetDevicePathSize (VarConsole),
|
||||
VarConsole
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibConnectConsoleVariable (
|
||||
IN CHAR16 *ConVarName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Connect the console device base on the variable ConVarName, if
|
||||
device path of the ConVarName is multi-instance device path, if
|
||||
anyone of the instances is connected success, then this function
|
||||
will return success.
|
||||
|
||||
Arguments:
|
||||
|
||||
ConVarName - Console related variable name, ConIn, ConOut, ErrOut.
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_NOT_FOUND - There is not any console devices connected success
|
||||
|
||||
EFI_SUCCESS - Success connect any one instance of the console
|
||||
device path base on the variable ConVarName.
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DEVICE_PATH_PROTOCOL *StartDevicePath;
|
||||
UINTN VariableSize;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Instance;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Next;
|
||||
EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;
|
||||
UINTN Size;
|
||||
BOOLEAN DeviceExist;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
DeviceExist = FALSE;
|
||||
|
||||
//
|
||||
// Check if the console variable exist
|
||||
//
|
||||
StartDevicePath = BdsLibGetVariableAndSize (
|
||||
ConVarName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&VariableSize
|
||||
);
|
||||
if (StartDevicePath == NULL) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
CopyOfDevicePath = DuplicateDevicePath (StartDevicePath);
|
||||
do {
|
||||
//
|
||||
// Check every instance of the console variable
|
||||
//
|
||||
Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);
|
||||
Next = Instance;
|
||||
while (!IsDevicePathEndType (Next)) {
|
||||
Next = NextDevicePathNode (Next);
|
||||
}
|
||||
|
||||
SetDevicePathEndNode (Next);
|
||||
|
||||
//
|
||||
// Connect the instance device path
|
||||
//
|
||||
Status = BdsLibConnectDevicePath (Instance);
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// Delete the instance from the console varialbe
|
||||
//
|
||||
BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);
|
||||
} else {
|
||||
DeviceExist = TRUE;
|
||||
}
|
||||
|
||||
} while (CopyOfDevicePath != NULL);
|
||||
|
||||
gBS->FreePool (StartDevicePath);
|
||||
|
||||
if (DeviceExist == FALSE) {
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibConnectAllConsoles (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will search every simpletxt devive in current system,
|
||||
and make every simpletxt device as pertantial console device.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;
|
||||
UINTN HandleCount;
|
||||
EFI_HANDLE *HandleBuffer;
|
||||
|
||||
Index = 0;
|
||||
HandleCount = 0;
|
||||
HandleBuffer = NULL;
|
||||
ConDevicePath = NULL;
|
||||
|
||||
//
|
||||
// Update all the console varables
|
||||
//
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiSimpleTextInProtocolGuid,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&HandleBuffer
|
||||
);
|
||||
for (Index = 0; Index < HandleCount; Index++) {
|
||||
Status = gBS->HandleProtocol (
|
||||
HandleBuffer[Index],
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
(VOID **) &ConDevicePath
|
||||
);
|
||||
BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
|
||||
}
|
||||
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
ByProtocol,
|
||||
&gEfiSimpleTextOutProtocolGuid,
|
||||
NULL,
|
||||
&HandleCount,
|
||||
&HandleBuffer
|
||||
);
|
||||
for (Index = 0; Index < HandleCount; Index++) {
|
||||
Status = gBS->HandleProtocol (
|
||||
HandleBuffer[Index],
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
(VOID **) &ConDevicePath
|
||||
);
|
||||
BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
|
||||
BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
|
||||
}
|
||||
//
|
||||
// Connect all console variables
|
||||
//
|
||||
BdsLibConnectAllDefaultConsoles ();
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibConnectAllDefaultConsoles (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will connect console device base on the console
|
||||
device variable ConIn, ConOut and ErrOut.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - At least one of the ConIn and ConOut device have
|
||||
been connected success.
|
||||
|
||||
EFI_STATUS - Return the status of BdsLibConnectConsoleVariable ().
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DEVICE_PATH_PROTOCOL *VarErrout;
|
||||
UINTN DevicePathSize;
|
||||
|
||||
//
|
||||
// Connect all default console variables
|
||||
//
|
||||
Status = BdsLibConnectConsoleVariable (L"ConIn");
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = BdsLibConnectConsoleVariable (L"ConOut");
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Special treat the err out device, becaues the null
|
||||
// err out var is legal.
|
||||
//
|
||||
VarErrout = BdsLibGetVariableAndSize (
|
||||
L"ErrOut",
|
||||
&gEfiGlobalVariableGuid,
|
||||
&DevicePathSize
|
||||
);
|
||||
if (VarErrout != NULL) {
|
||||
BdsLibConnectConsoleVariable (L"ErrOut");
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
||||
}
|
764
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c
Normal file
764
EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c
Normal file
@@ -0,0 +1,764 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
BdsMisc.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Misc BDS library function
|
||||
|
||||
--*/
|
||||
|
||||
extern UINT16 gPlatformBootTimeOutDefault;
|
||||
|
||||
UINT16
|
||||
BdsLibGetTimeout (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Return the default value for system Timeout variable.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
Timeout value.
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT16 Timeout;
|
||||
UINTN Size;
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Return Timeout variable or 0xffff if no valid
|
||||
// Timeout variable exists.
|
||||
//
|
||||
Size = sizeof (UINT16);
|
||||
Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
return Timeout;
|
||||
}
|
||||
//
|
||||
// To make the current EFI Automatic-Test activity possible, just add
|
||||
// following code to make AutoBoot enabled when this variable is not
|
||||
// present.
|
||||
// This code should be removed later.
|
||||
//
|
||||
Timeout = gPlatformBootTimeOutDefault;
|
||||
|
||||
//
|
||||
// Notes: Platform should set default variable if non exists on all error cases!!!
|
||||
//
|
||||
Status = gRT->SetVariable (
|
||||
L"Timeout",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
sizeof (UINT16),
|
||||
&Timeout
|
||||
);
|
||||
return Timeout;
|
||||
}
|
||||
|
||||
VOID
|
||||
BdsLibLoadDrivers (
|
||||
IN LIST_ENTRY *BdsDriverLists
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
The function will go through the driver optoin link list, load and start
|
||||
every driver the driver optoin device path point to.
|
||||
|
||||
Arguments:
|
||||
|
||||
BdsDriverLists - The header of the current driver option link list
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LIST_ENTRY *Link;
|
||||
BDS_COMMON_OPTION *Option;
|
||||
EFI_HANDLE ImageHandle;
|
||||
EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
|
||||
UINTN ExitDataSize;
|
||||
CHAR16 *ExitData;
|
||||
BOOLEAN ReconnectAll;
|
||||
|
||||
ReconnectAll = FALSE;
|
||||
|
||||
//
|
||||
// Process the driver option
|
||||
//
|
||||
for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {
|
||||
Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
|
||||
//
|
||||
// If a load option is not marked as LOAD_OPTION_ACTIVE,
|
||||
// the boot manager will not automatically load the option.
|
||||
//
|
||||
if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {
|
||||
continue;
|
||||
}
|
||||
//
|
||||
// If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,
|
||||
// then all of the EFI drivers in the system will be disconnected and
|
||||
// reconnected after the last driver load option is processed.
|
||||
//
|
||||
if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {
|
||||
ReconnectAll = TRUE;
|
||||
}
|
||||
//
|
||||
// Make sure the driver path is connected.
|
||||
//
|
||||
BdsLibConnectDevicePath (Option->DevicePath);
|
||||
|
||||
//
|
||||
// Load and start the image that Driver#### describes
|
||||
//
|
||||
Status = gBS->LoadImage (
|
||||
FALSE,
|
||||
mBdsImageHandle,
|
||||
Option->DevicePath,
|
||||
NULL,
|
||||
0,
|
||||
&ImageHandle
|
||||
);
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, &ImageInfo);
|
||||
|
||||
//
|
||||
// Verify whether this image is a driver, if not,
|
||||
// exit it and continue to parse next load option
|
||||
//
|
||||
if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
|
||||
gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Option->LoadOptionsSize != 0) {
|
||||
ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
|
||||
ImageInfo->LoadOptions = Option->LoadOptions;
|
||||
}
|
||||
//
|
||||
// Before calling the image, enable the Watchdog Timer for
|
||||
// the 5 Minute period
|
||||
//
|
||||
gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
|
||||
|
||||
Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Driver Return Status = %r\n", Status));
|
||||
|
||||
//
|
||||
// Clear the Watchdog Timer after the image returns
|
||||
//
|
||||
gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Process the LOAD_OPTION_FORCE_RECONNECT driver option
|
||||
//
|
||||
if (ReconnectAll) {
|
||||
BdsLibDisconnectAllEfi ();
|
||||
BdsLibConnectAll ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibRegisterNewOption (
|
||||
IN LIST_ENTRY *BdsOptionList,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
IN CHAR16 *String,
|
||||
IN CHAR16 *VariableName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function will register the new boot#### or driver#### option base on
|
||||
the VariableName. The new registered boot#### or driver#### will be linked
|
||||
to BdsOptionList and also update to the VariableName. After the boot#### or
|
||||
driver#### updated, the BootOrder or DriverOrder will also be updated.
|
||||
|
||||
Arguments:
|
||||
|
||||
BdsOptionList - The header of the boot#### or driver#### link list
|
||||
|
||||
DevicePath - The device path which the boot####
|
||||
or driver#### option present
|
||||
|
||||
String - The description of the boot#### or driver####
|
||||
|
||||
VariableName - Indicate if the boot#### or driver#### option
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - The boot#### or driver#### have been success registered
|
||||
|
||||
EFI_STATUS - Return the status of gRT->SetVariable ().
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
UINT16 MaxOptionNumber;
|
||||
UINT16 RegisterOptionNumber;
|
||||
UINT16 *TempOptionPtr;
|
||||
UINTN TempOptionSize;
|
||||
UINT16 *OptionOrderPtr;
|
||||
VOID *OptionPtr;
|
||||
UINTN OptionSize;
|
||||
UINT8 *TempPtr;
|
||||
EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
|
||||
CHAR16 *Description;
|
||||
CHAR16 OptionName[10];
|
||||
BOOLEAN UpdateBootDevicePath;
|
||||
|
||||
OptionPtr = NULL;
|
||||
OptionSize = 0;
|
||||
TempPtr = NULL;
|
||||
OptionDevicePath = NULL;
|
||||
Description = NULL;
|
||||
MaxOptionNumber = 0;
|
||||
OptionOrderPtr = NULL;
|
||||
UpdateBootDevicePath = FALSE;
|
||||
ZeroMem (OptionName, sizeof (OptionName));
|
||||
|
||||
TempOptionSize = 0;
|
||||
TempOptionPtr = BdsLibGetVariableAndSize (
|
||||
VariableName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&TempOptionSize
|
||||
);
|
||||
//
|
||||
// Compare with current option variable
|
||||
//
|
||||
for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {
|
||||
//
|
||||
// Got the max option#### number
|
||||
//
|
||||
if (MaxOptionNumber < TempOptionPtr[Index]) {
|
||||
MaxOptionNumber = TempOptionPtr[Index];
|
||||
}
|
||||
|
||||
if (*VariableName == 'B') {
|
||||
UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);
|
||||
} else {
|
||||
UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);
|
||||
}
|
||||
|
||||
OptionPtr = BdsLibGetVariableAndSize (
|
||||
OptionName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&OptionSize
|
||||
);
|
||||
TempPtr = OptionPtr;
|
||||
TempPtr += sizeof (UINT32) + sizeof (UINT16);
|
||||
Description = (CHAR16 *) TempPtr;
|
||||
TempPtr += StrSize ((CHAR16 *) TempPtr);
|
||||
OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
|
||||
|
||||
//
|
||||
// Notes: the description may will change base on the GetStringToken
|
||||
//
|
||||
if (CompareMem (Description, String, StrSize (Description)) == 0) {
|
||||
if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {
|
||||
//
|
||||
// Got the option, so just return
|
||||
//
|
||||
gBS->FreePool (OptionPtr);
|
||||
gBS->FreePool (TempOptionPtr);
|
||||
return EFI_SUCCESS;
|
||||
} else {
|
||||
//
|
||||
// Boot device path changed, need update.
|
||||
//
|
||||
UpdateBootDevicePath = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (OptionPtr);
|
||||
}
|
||||
|
||||
OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String) + GetDevicePathSize (DevicePath);
|
||||
OptionPtr = AllocateZeroPool (OptionSize);
|
||||
TempPtr = OptionPtr;
|
||||
*(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
|
||||
TempPtr += sizeof (UINT32);
|
||||
*(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);
|
||||
TempPtr += sizeof (UINT16);
|
||||
CopyMem (TempPtr, String, StrSize (String));
|
||||
TempPtr += StrSize (String);
|
||||
CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));
|
||||
|
||||
if (UpdateBootDevicePath) {
|
||||
//
|
||||
// The number in option#### to be updated
|
||||
//
|
||||
RegisterOptionNumber = TempOptionPtr[Index];
|
||||
} else {
|
||||
//
|
||||
// The new option#### number
|
||||
//
|
||||
RegisterOptionNumber = MaxOptionNumber + 1;
|
||||
}
|
||||
|
||||
if (*VariableName == 'B') {
|
||||
UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);
|
||||
} else {
|
||||
UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);
|
||||
}
|
||||
|
||||
Status = gRT->SetVariable (
|
||||
OptionName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
OptionSize,
|
||||
OptionPtr
|
||||
);
|
||||
if (EFI_ERROR (Status) || UpdateBootDevicePath) {
|
||||
gBS->FreePool (OptionPtr);
|
||||
gBS->FreePool (TempOptionPtr);
|
||||
return Status;
|
||||
}
|
||||
|
||||
gBS->FreePool (OptionPtr);
|
||||
|
||||
//
|
||||
// Update the option order variable
|
||||
//
|
||||
OptionOrderPtr = AllocateZeroPool ((Index + 1) * sizeof (UINT16));
|
||||
CopyMem (OptionOrderPtr, TempOptionPtr, Index * sizeof (UINT16));
|
||||
OptionOrderPtr[Index] = RegisterOptionNumber;
|
||||
Status = gRT->SetVariable (
|
||||
VariableName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
|
||||
(Index + 1) * sizeof (UINT16),
|
||||
OptionOrderPtr
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePool (TempOptionPtr);
|
||||
gBS->FreePool (OptionOrderPtr);
|
||||
return Status;
|
||||
}
|
||||
|
||||
gBS->FreePool (TempOptionPtr);
|
||||
gBS->FreePool (OptionOrderPtr);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
BDS_COMMON_OPTION *
|
||||
BdsLibVariableToOption (
|
||||
IN OUT LIST_ENTRY *BdsCommonOptionList,
|
||||
IN CHAR16 *VariableName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Build the boot#### or driver#### option from the VariableName, the
|
||||
build boot#### or driver#### will also be linked to BdsCommonOptionList
|
||||
|
||||
Arguments:
|
||||
|
||||
BdsCommonOptionList - The header of the boot#### or driver#### option link list
|
||||
|
||||
VariableName - EFI Variable name indicate if it is boot#### or driver####
|
||||
|
||||
Returns:
|
||||
|
||||
BDS_COMMON_OPTION - Get the option just been created
|
||||
|
||||
NULL - Failed to get the new option
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT32 Attribute;
|
||||
UINT16 FilePathSize;
|
||||
UINT8 *Variable;
|
||||
UINT8 *TempPtr;
|
||||
UINTN VariableSize;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
BDS_COMMON_OPTION *Option;
|
||||
VOID *LoadOptions;
|
||||
UINT32 LoadOptionsSize;
|
||||
CHAR16 *Description;
|
||||
|
||||
//
|
||||
// Read the variable. We will never free this data.
|
||||
//
|
||||
Variable = BdsLibGetVariableAndSize (
|
||||
VariableName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&VariableSize
|
||||
);
|
||||
if (Variable == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
//
|
||||
// Notes: careful defined the variable of Boot#### or
|
||||
// Driver####, consider use some macro to abstract the code
|
||||
//
|
||||
//
|
||||
// Get the option attribute
|
||||
//
|
||||
TempPtr = Variable;
|
||||
Attribute = *(UINT32 *) Variable;
|
||||
TempPtr += sizeof (UINT32);
|
||||
|
||||
//
|
||||
// Get the option's device path size
|
||||
//
|
||||
FilePathSize = *(UINT16 *) TempPtr;
|
||||
TempPtr += sizeof (UINT16);
|
||||
|
||||
//
|
||||
// Get the option's description string
|
||||
//
|
||||
Description = (CHAR16 *) TempPtr;
|
||||
|
||||
//
|
||||
// Get the option's description string size
|
||||
//
|
||||
TempPtr += StrSize ((CHAR16 *) TempPtr);
|
||||
|
||||
//
|
||||
// Get the option's device path
|
||||
//
|
||||
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
|
||||
TempPtr += FilePathSize;
|
||||
|
||||
LoadOptions = TempPtr;
|
||||
LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
|
||||
|
||||
//
|
||||
// The Console variables may have multiple device paths, so make
|
||||
// an Entry for each one.
|
||||
//
|
||||
Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));
|
||||
if (Option == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Option->Signature = BDS_LOAD_OPTION_SIGNATURE;
|
||||
Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
|
||||
CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
|
||||
Option->Attribute = Attribute;
|
||||
Option->Description = AllocateZeroPool (StrSize (Description));
|
||||
CopyMem (Option->Description, Description, StrSize (Description));
|
||||
Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);
|
||||
CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);
|
||||
Option->LoadOptionsSize = LoadOptionsSize;
|
||||
|
||||
//
|
||||
// Insert active entry to BdsDeviceList
|
||||
//
|
||||
if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {
|
||||
InsertTailList (BdsCommonOptionList, &Option->Link);
|
||||
gBS->FreePool (Variable);
|
||||
return Option;
|
||||
}
|
||||
|
||||
gBS->FreePool (Variable);
|
||||
gBS->FreePool (Option);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibBuildOptionFromVar (
|
||||
IN LIST_ENTRY *BdsCommonOptionList,
|
||||
IN CHAR16 *VariableName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Process BootOrder, or DriverOrder variables, by calling
|
||||
BdsLibVariableToOption () for each UINT16 in the variables.
|
||||
|
||||
Arguments:
|
||||
|
||||
BdsCommonOptionList - The header of the option list base on variable
|
||||
VariableName
|
||||
|
||||
VariableName - EFI Variable name indicate the BootOrder or DriverOrder
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - Success create the boot option or driver option list
|
||||
|
||||
EFI_OUT_OF_RESOURCES - Failed to get the boot option or driver option list
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT16 *OptionOrder;
|
||||
UINTN OptionOrderSize;
|
||||
UINTN Index;
|
||||
BDS_COMMON_OPTION *Option;
|
||||
CHAR16 OptionName[20];
|
||||
|
||||
//
|
||||
// Zero Buffer in order to get all BOOT#### variables
|
||||
//
|
||||
ZeroMem (OptionName, sizeof (OptionName));
|
||||
|
||||
//
|
||||
// Read the BootOrder, or DriverOrder variable.
|
||||
//
|
||||
OptionOrder = BdsLibGetVariableAndSize (
|
||||
VariableName,
|
||||
&gEfiGlobalVariableGuid,
|
||||
&OptionOrderSize
|
||||
);
|
||||
if (OptionOrder == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
|
||||
if (*VariableName == 'B') {
|
||||
UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);
|
||||
} else {
|
||||
UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);
|
||||
}
|
||||
Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);
|
||||
Option->BootCurrent = OptionOrder[Index];
|
||||
|
||||
}
|
||||
|
||||
gBS->FreePool (OptionOrder);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibGetBootMode (
|
||||
OUT EFI_BOOT_MODE *BootMode
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Get boot mode by looking up configuration table and parsing HOB list
|
||||
|
||||
Arguments:
|
||||
|
||||
BootMode - Boot mode from PEI handoff HOB.
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - Successfully get boot mode
|
||||
|
||||
EFI_NOT_FOUND - Can not find the current system boot mode
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_HOB_HANDOFF_INFO_TABLE *HobList;
|
||||
|
||||
HobList = GetHobList ();
|
||||
ASSERT (HobList->Header.HobType == EFI_HOB_TYPE_HANDOFF);
|
||||
*BootMode = HobList->BootMode;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
VOID *
|
||||
BdsLibGetVariableAndSize (
|
||||
IN CHAR16 *Name,
|
||||
IN EFI_GUID *VendorGuid,
|
||||
OUT UINTN *VariableSize
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
|
||||
buffer, and the size of the buffer. If failure return NULL.
|
||||
|
||||
Arguments:
|
||||
|
||||
Name - String part of EFI variable name
|
||||
|
||||
VendorGuid - GUID part of EFI variable name
|
||||
|
||||
VariableSize - Returns the size of the EFI variable that was read
|
||||
|
||||
Returns:
|
||||
|
||||
Dynamically allocated memory that contains a copy of the EFI variable.
|
||||
Caller is responsible freeing the buffer.
|
||||
|
||||
NULL - Variable was not read
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN BufferSize;
|
||||
VOID *Buffer;
|
||||
|
||||
Buffer = NULL;
|
||||
|
||||
//
|
||||
// Pass in a zero size buffer to find the required buffer size.
|
||||
//
|
||||
BufferSize = 0;
|
||||
Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
//
|
||||
// Allocate the buffer to return
|
||||
//
|
||||
Buffer = AllocateZeroPool (BufferSize);
|
||||
if (Buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
//
|
||||
// Read variable into the allocated buffer.
|
||||
//
|
||||
Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
BufferSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
*VariableSize = BufferSize;
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
BdsLibMatchDevicePaths (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *Multi,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *Single
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Function compares a device path data structure to that of all the nodes of a
|
||||
second device path instance.
|
||||
|
||||
Arguments:
|
||||
|
||||
Multi - A pointer to a multi-instance device path data structure.
|
||||
|
||||
Single - A pointer to a single-instance device path data structure.
|
||||
|
||||
Returns:
|
||||
|
||||
TRUE - If the Single is contained within Multi
|
||||
|
||||
FALSE - The Single is not match within Multi
|
||||
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
|
||||
UINTN Size;
|
||||
|
||||
if (!Multi || !Single) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DevicePath = Multi;
|
||||
DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
|
||||
Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL);
|
||||
|
||||
//
|
||||
// Search for the match of 'Single' in 'Multi'
|
||||
//
|
||||
while (DevicePathInst != NULL) {
|
||||
//
|
||||
// If the single device path is found in multiple device paths,
|
||||
// return success
|
||||
//
|
||||
if (Size == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (CompareMem (Single, DevicePathInst, Size) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gBS->FreePool (DevicePathInst);
|
||||
DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
|
||||
Size -= sizeof (EFI_DEVICE_PATH_PROTOCOL);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
BdsLibOutputStrings (
|
||||
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *ConOut,
|
||||
...
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This function prints a series of strings.
|
||||
|
||||
Arguments:
|
||||
|
||||
ConOut - Pointer to EFI_SIMPLE_TEXT_OUT_PROTOCOL
|
||||
|
||||
... - A variable argument list containing series of strings,
|
||||
the last string must be NULL.
|
||||
|
||||
Returns:
|
||||
|
||||
EFI_SUCCESS - Success print out the string using ConOut.
|
||||
|
||||
EFI_STATUS - Return the status of the ConOut->OutputString ().
|
||||
|
||||
--*/
|
||||
{
|
||||
VA_LIST args;
|
||||
EFI_STATUS Status;
|
||||
CHAR16 *String;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
VA_START (args, ConOut);
|
||||
|
||||
while (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// If String is NULL, then it's the end of the list
|
||||
//
|
||||
String = VA_ARG (args, CHAR16 *);
|
||||
if (!String) {
|
||||
break;
|
||||
}
|
||||
|
||||
Status = ConOut->OutputString (ConOut, String);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
988
EdkNt32Pkg/Library/EdkGenericBdsLib/DevicePath.c
Normal file
988
EdkNt32Pkg/Library/EdkGenericBdsLib/DevicePath.c
Normal file
@@ -0,0 +1,988 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
DevicePath.c
|
||||
|
||||
Abstract:
|
||||
|
||||
BDS internal function define the default device path string, it can be
|
||||
replaced by platform device path.
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#ifdef TIANO_EXTENSION_FLAG
|
||||
EFI_GUID UnknownDeviceGuid = UNKNOWN_DEVICE_GUID;
|
||||
#endif
|
||||
|
||||
EFI_GUID mEfiWinNtThunkProtocolGuid = EFI_WIN_NT_THUNK_PROTOCOL_GUID;
|
||||
EFI_GUID mEfiWinNtUgaGuid = EFI_WIN_NT_UGA_GUID;
|
||||
EFI_GUID mEfiWinNtSerialPortGuid = EFI_WIN_NT_SERIAL_PORT_GUID;
|
||||
EFI_GUID mEfiMsgPcAnsiGuid = DEVICE_PATH_MESSAGING_PC_ANSI;
|
||||
EFI_GUID mEfiMsgVt100Guid = DEVICE_PATH_MESSAGING_VT_100;
|
||||
EFI_GUID mEfiMsgVt100PlusGuid = DEVICE_PATH_MESSAGING_VT_100_PLUS;
|
||||
EFI_GUID mEfiMsgVt100Utf8Guid = DEVICE_PATH_MESSAGING_VT_UTF8;
|
||||
|
||||
VOID *
|
||||
ReallocatePool (
|
||||
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 = AllocateZeroPool (NewSize);
|
||||
}
|
||||
|
||||
if (OldPool) {
|
||||
if (NewPool) {
|
||||
CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
|
||||
}
|
||||
|
||||
gBS->FreePool (OldPool);
|
||||
}
|
||||
|
||||
return NewPool;
|
||||
}
|
||||
|
||||
CHAR16 *
|
||||
CatPrint (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN CHAR16 *fmt,
|
||||
...
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Concatenates a formatted unicode string to allocated pool.
|
||||
The caller must free the resulting buffer.
|
||||
|
||||
Arguments:
|
||||
|
||||
Str - Tracks the allocated pool, size in use, and
|
||||
amount of pool allocated.
|
||||
|
||||
fmt - The format string
|
||||
|
||||
Returns:
|
||||
|
||||
Allocated buffer with the formatted string printed in it.
|
||||
The caller must free the allocated buffer. The buffer
|
||||
allocation is not packed.
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT16 *AppendStr;
|
||||
VA_LIST args;
|
||||
UINTN strsize;
|
||||
|
||||
AppendStr = AllocateZeroPool (0x1000);
|
||||
if (AppendStr == NULL) {
|
||||
return Str->str;
|
||||
}
|
||||
|
||||
VA_START (args, fmt);
|
||||
UnicodeVSPrint (AppendStr, 0x1000, fmt, args);
|
||||
VA_END (args);
|
||||
if (NULL == Str->str) {
|
||||
strsize = StrSize (AppendStr);
|
||||
Str->str = AllocateZeroPool (strsize);
|
||||
ASSERT (Str->str != NULL);
|
||||
} else {
|
||||
strsize = StrSize (AppendStr) + StrSize (Str->str) - sizeof (UINT16);
|
||||
Str->str = ReallocatePool (
|
||||
Str->str,
|
||||
StrSize (Str->str),
|
||||
strsize
|
||||
);
|
||||
ASSERT (Str->str != NULL);
|
||||
}
|
||||
|
||||
Str->maxlen = MAX_CHAR * sizeof (UINT16);
|
||||
if (strsize < Str->maxlen) {
|
||||
StrCat (Str->str, AppendStr);
|
||||
Str->len = strsize - sizeof (UINT16);
|
||||
}
|
||||
|
||||
gBS->FreePool (AppendStr);
|
||||
return Str->str;
|
||||
}
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
BdsLibUnpackDevicePath (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Function unpacks a device path data structure so that all the nodes
|
||||
of a device path are naturally aligned.
|
||||
|
||||
Arguments:
|
||||
|
||||
DevPath - A pointer to a device path data structure
|
||||
|
||||
Returns:
|
||||
|
||||
If the memory for the device path is successfully allocated, then a
|
||||
pointer to the new device path is returned. Otherwise, NULL is returned.
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *Src;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Dest;
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewPath;
|
||||
UINTN Size;
|
||||
|
||||
//
|
||||
// Walk device path and round sizes to valid boundries
|
||||
//
|
||||
Src = DevPath;
|
||||
Size = 0;
|
||||
for (;;) {
|
||||
Size += DevicePathNodeLength (Src);
|
||||
Size += ALIGN_SIZE (Size);
|
||||
|
||||
if (IsDevicePathEnd (Src)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Src = NextDevicePathNode (Src);
|
||||
}
|
||||
//
|
||||
// Allocate space for the unpacked path
|
||||
//
|
||||
NewPath = AllocateZeroPool (Size);
|
||||
if (NewPath) {
|
||||
|
||||
ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);
|
||||
|
||||
//
|
||||
// Copy each node
|
||||
//
|
||||
Src = DevPath;
|
||||
Dest = NewPath;
|
||||
for (;;) {
|
||||
Size = DevicePathNodeLength (Src);
|
||||
CopyMem (Dest, Src, Size);
|
||||
Size += ALIGN_SIZE (Size);
|
||||
SetDevicePathNodeLength (Dest, Size);
|
||||
Dest->Type |= EFI_DP_TYPE_UNPACKED;
|
||||
Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);
|
||||
|
||||
if (IsDevicePathEnd (Src)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Src = NextDevicePathNode (Src);
|
||||
}
|
||||
}
|
||||
|
||||
return NewPath;
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathPci (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
PCI_DEVICE_PATH *Pci;
|
||||
|
||||
Pci = DevPath;
|
||||
CatPrint (Str, L"Pci(%x|%x)", Pci->Device, Pci->Function);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathPccard (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
PCCARD_DEVICE_PATH *Pccard;
|
||||
|
||||
Pccard = DevPath;
|
||||
CatPrint (Str, L"Pcmcia(Function%x)", Pccard->FunctionNumber);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathMemMap (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
MEMMAP_DEVICE_PATH *MemMap;
|
||||
|
||||
MemMap = DevPath;
|
||||
CatPrint (
|
||||
Str,
|
||||
L"MemMap(%d:%.lx-%.lx)",
|
||||
MemMap->MemoryType,
|
||||
MemMap->StartingAddress,
|
||||
MemMap->EndingAddress
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathController (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
CONTROLLER_DEVICE_PATH *Controller;
|
||||
|
||||
Controller = DevPath;
|
||||
CatPrint (Str, L"Ctrl(%d)", Controller->ControllerNumber);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathVendor (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Convert Vendor device path to device name
|
||||
|
||||
Arguments:
|
||||
|
||||
Str - The buffer store device name
|
||||
DevPath - Pointer to vendor device path
|
||||
|
||||
Returns:
|
||||
|
||||
When it return, the device name have been stored in *Str.
|
||||
|
||||
--*/
|
||||
{
|
||||
VENDOR_DEVICE_PATH *Vendor;
|
||||
CHAR16 *Type;
|
||||
INT32 *Temp;
|
||||
|
||||
Vendor = DevPath;
|
||||
Temp = (INT32 *) (&Vendor->Guid);
|
||||
|
||||
switch (DevicePathType (&Vendor->Header)) {
|
||||
case HARDWARE_DEVICE_PATH:
|
||||
//
|
||||
// If the device is a winntbus device, we will give it a readable device name.
|
||||
//
|
||||
if (CompareGuid (&Vendor->Guid, &mEfiWinNtThunkProtocolGuid)) {
|
||||
CatPrint (Str, L"%s", L"WinNtBus");
|
||||
return ;
|
||||
} else if (CompareGuid (&Vendor->Guid, &mEfiWinNtUgaGuid)) {
|
||||
CatPrint (Str, L"%s", L"UGA");
|
||||
return ;
|
||||
} else if (CompareGuid (&Vendor->Guid, &mEfiWinNtSerialPortGuid)) {
|
||||
CatPrint (Str, L"%s", L"Serial");
|
||||
return ;
|
||||
} else {
|
||||
Type = L"Hw";
|
||||
break;
|
||||
}
|
||||
|
||||
case MESSAGING_DEVICE_PATH:
|
||||
//
|
||||
// If the device is a winntbus device, we will give it a readable device name.
|
||||
//
|
||||
if (CompareGuid (&Vendor->Guid, &mEfiMsgPcAnsiGuid)) {
|
||||
CatPrint (Str, L"%s", L"PC-ANSI");
|
||||
return ;
|
||||
} else if (CompareGuid (&Vendor->Guid, &mEfiMsgVt100Guid)) {
|
||||
CatPrint (Str, L"%s", L"VT100");
|
||||
return ;
|
||||
} else if (CompareGuid (&Vendor->Guid, &mEfiMsgVt100PlusGuid)) {
|
||||
CatPrint (Str, L"%s", L"VT100+");
|
||||
return ;
|
||||
} else if (CompareGuid (&Vendor->Guid, &mEfiMsgVt100Utf8Guid)) {
|
||||
CatPrint (Str, L"%s", L"VT100-UTF8");
|
||||
return ;
|
||||
} else {
|
||||
Type = L"Msg";
|
||||
break;
|
||||
}
|
||||
|
||||
case MEDIA_DEVICE_PATH:
|
||||
Type = L"Media";
|
||||
break;
|
||||
|
||||
default:
|
||||
Type = L"?";
|
||||
break;
|
||||
}
|
||||
|
||||
CatPrint (Str, L"Ven%s(%g)", Type, &Vendor->Guid);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathAcpi (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
ACPI_HID_DEVICE_PATH *Acpi;
|
||||
|
||||
Acpi = DevPath;
|
||||
if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
|
||||
CatPrint (Str, L"Acpi(PNP%04x,%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
|
||||
} else {
|
||||
CatPrint (Str, L"Acpi(%08x,%x)", Acpi->HID, Acpi->UID);
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathAtapi (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
ATAPI_DEVICE_PATH *Atapi;
|
||||
|
||||
Atapi = DevPath;
|
||||
CatPrint (
|
||||
Str,
|
||||
L"Ata(%s,%s)",
|
||||
Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
|
||||
Atapi->SlaveMaster ? L"Slave" : L"Master"
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathScsi (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
SCSI_DEVICE_PATH *Scsi;
|
||||
|
||||
Scsi = DevPath;
|
||||
CatPrint (Str, L"Scsi(Pun%x,Lun%x)", Scsi->Pun, Scsi->Lun);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathFibre (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
FIBRECHANNEL_DEVICE_PATH *Fibre;
|
||||
|
||||
Fibre = DevPath;
|
||||
CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPath1394 (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
F1394_DEVICE_PATH *F1394;
|
||||
|
||||
F1394 = DevPath;
|
||||
CatPrint (Str, L"1394(%g)", &F1394->Guid);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathUsb (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
USB_DEVICE_PATH *Usb;
|
||||
|
||||
Usb = DevPath;
|
||||
CatPrint (Str, L"Usb(%x, %x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathUsbClass (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
USB_CLASS_DEVICE_PATH *UsbClass;
|
||||
|
||||
UsbClass = DevPath;
|
||||
CatPrint (
|
||||
Str,
|
||||
L"Usb Class(%x, %x, %x, %x, %x)",
|
||||
UsbClass->VendorId,
|
||||
UsbClass->ProductId,
|
||||
UsbClass->DeviceClass,
|
||||
UsbClass->DeviceSubClass,
|
||||
UsbClass->DeviceProtocol
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathI2O (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
I2O_DEVICE_PATH *I2O;
|
||||
|
||||
I2O = DevPath;
|
||||
CatPrint (Str, L"I2O(%x)", I2O->Tid);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathMacAddr (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
MAC_ADDR_DEVICE_PATH *MAC;
|
||||
UINTN HwAddressSize;
|
||||
UINTN Index;
|
||||
|
||||
MAC = DevPath;
|
||||
|
||||
HwAddressSize = sizeof (EFI_MAC_ADDRESS);
|
||||
if (MAC->IfType == 0x01 || MAC->IfType == 0x00) {
|
||||
HwAddressSize = 6;
|
||||
}
|
||||
|
||||
CatPrint (Str, L"Mac(");
|
||||
|
||||
for (Index = 0; Index < HwAddressSize; Index++) {
|
||||
CatPrint (Str, L"%02x", MAC->MacAddress.Addr[Index]);
|
||||
}
|
||||
|
||||
CatPrint (Str, L")");
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathIPv4 (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
IPv4_DEVICE_PATH *IP;
|
||||
|
||||
IP = DevPath;
|
||||
CatPrint (
|
||||
Str,
|
||||
L"IPv4(%d.%d.%d.%d:%d)",
|
||||
IP->RemoteIpAddress.Addr[0],
|
||||
IP->RemoteIpAddress.Addr[1],
|
||||
IP->RemoteIpAddress.Addr[2],
|
||||
IP->RemoteIpAddress.Addr[3],
|
||||
IP->RemotePort
|
||||
);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathIPv6 (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
IPv6_DEVICE_PATH *IP;
|
||||
|
||||
IP = DevPath;
|
||||
CatPrint (Str, L"IP-v6(not-done)");
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathInfiniBand (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
INFINIBAND_DEVICE_PATH *InfiniBand;
|
||||
|
||||
InfiniBand = DevPath;
|
||||
CatPrint (Str, L"InfiniBand(not-done)");
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathUart (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
UART_DEVICE_PATH *Uart;
|
||||
CHAR8 Parity;
|
||||
|
||||
Uart = DevPath;
|
||||
switch (Uart->Parity) {
|
||||
case 0:
|
||||
Parity = 'D';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Parity = 'N';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Parity = 'E';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Parity = 'O';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
Parity = 'M';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
Parity = 'S';
|
||||
break;
|
||||
|
||||
default:
|
||||
Parity = 'x';
|
||||
break;
|
||||
}
|
||||
|
||||
if (Uart->BaudRate == 0) {
|
||||
CatPrint (Str, L"Uart(DEFAULT %c", Parity);
|
||||
} else {
|
||||
CatPrint (Str, L"Uart(%d %c", Uart->BaudRate, Parity);
|
||||
}
|
||||
|
||||
if (Uart->DataBits == 0) {
|
||||
CatPrint (Str, L"D");
|
||||
} else {
|
||||
CatPrint (Str, L"%d", Uart->DataBits);
|
||||
}
|
||||
|
||||
switch (Uart->StopBits) {
|
||||
case 0:
|
||||
CatPrint (Str, L"D)");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
CatPrint (Str, L"1)");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
CatPrint (Str, L"1.5)");
|
||||
break;
|
||||
|
||||
case 3:
|
||||
CatPrint (Str, L"2)");
|
||||
break;
|
||||
|
||||
default:
|
||||
CatPrint (Str, L"x)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathHardDrive (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
HARDDRIVE_DEVICE_PATH *Hd;
|
||||
|
||||
Hd = DevPath;
|
||||
switch (Hd->SignatureType) {
|
||||
case SIGNATURE_TYPE_MBR:
|
||||
CatPrint (
|
||||
Str,
|
||||
L"HD(Part%d,Sig%08x)",
|
||||
Hd->PartitionNumber,
|
||||
*((UINT32 *) (&(Hd->Signature[0])))
|
||||
);
|
||||
break;
|
||||
|
||||
case SIGNATURE_TYPE_GUID:
|
||||
CatPrint (
|
||||
Str,
|
||||
L"HD(Part%d,Sig%g)",
|
||||
Hd->PartitionNumber,
|
||||
(EFI_GUID *) &(Hd->Signature[0])
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
CatPrint (
|
||||
Str,
|
||||
L"HD(Part%d,MBRType=%02x,SigType=%02x)",
|
||||
Hd->PartitionNumber,
|
||||
Hd->MBRType,
|
||||
Hd->SignatureType
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathCDROM (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
CDROM_DEVICE_PATH *Cd;
|
||||
|
||||
Cd = DevPath;
|
||||
CatPrint (Str, L"CDROM(Entry%x)", Cd->BootEntry);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathFilePath (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
FILEPATH_DEVICE_PATH *Fp;
|
||||
|
||||
Fp = DevPath;
|
||||
CatPrint (Str, L"%s", Fp->PathName);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathMediaProtocol (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
|
||||
|
||||
MediaProt = DevPath;
|
||||
CatPrint (Str, L"%g", &MediaProt->Protocol);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathFvFilePath (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
|
||||
|
||||
FvFilePath = DevPath;
|
||||
CatPrint (Str, L"%g", &FvFilePath->NameGuid);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathBssBss (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
BBS_BBS_DEVICE_PATH *Bbs;
|
||||
CHAR16 *Type;
|
||||
|
||||
Bbs = DevPath;
|
||||
switch (Bbs->DeviceType) {
|
||||
case BBS_TYPE_FLOPPY:
|
||||
Type = L"Floppy";
|
||||
break;
|
||||
|
||||
case BBS_TYPE_HARDDRIVE:
|
||||
Type = L"Harddrive";
|
||||
break;
|
||||
|
||||
case BBS_TYPE_CDROM:
|
||||
Type = L"CDROM";
|
||||
break;
|
||||
|
||||
case BBS_TYPE_PCMCIA:
|
||||
Type = L"PCMCIA";
|
||||
break;
|
||||
|
||||
case BBS_TYPE_USB:
|
||||
Type = L"Usb";
|
||||
break;
|
||||
|
||||
case BBS_TYPE_EMBEDDED_NETWORK:
|
||||
Type = L"Net";
|
||||
break;
|
||||
|
||||
default:
|
||||
Type = L"?";
|
||||
break;
|
||||
}
|
||||
//
|
||||
// Since current Print function hasn't implemented %a (for ansi string)
|
||||
// we will only print Unicode strings.
|
||||
//
|
||||
CatPrint (Str, L"Legacy-%s", Type);
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathEndInstance (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
CatPrint (Str, L",");
|
||||
}
|
||||
|
||||
VOID
|
||||
DevPathNodeUnknown (
|
||||
IN OUT POOL_PRINT *Str,
|
||||
IN VOID *DevPath
|
||||
)
|
||||
{
|
||||
CatPrint (Str, L"?");
|
||||
}
|
||||
|
||||
DEVICE_PATH_STRING_TABLE DevPathTable[] = {
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_PCI_DP,
|
||||
DevPathPci,
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_PCCARD_DP,
|
||||
DevPathPccard,
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_MEMMAP_DP,
|
||||
DevPathMemMap,
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_VENDOR_DP,
|
||||
DevPathVendor,
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_CONTROLLER_DP,
|
||||
DevPathController,
|
||||
ACPI_DEVICE_PATH,
|
||||
ACPI_DP,
|
||||
DevPathAcpi,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_ATAPI_DP,
|
||||
DevPathAtapi,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_SCSI_DP,
|
||||
DevPathScsi,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_FIBRECHANNEL_DP,
|
||||
DevPathFibre,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_1394_DP,
|
||||
DevPath1394,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_USB_DP,
|
||||
DevPathUsb,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_USB_CLASS_DP,
|
||||
DevPathUsbClass,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_I2O_DP,
|
||||
DevPathI2O,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_MAC_ADDR_DP,
|
||||
DevPathMacAddr,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_IPv4_DP,
|
||||
DevPathIPv4,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_IPv6_DP,
|
||||
DevPathIPv6,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_INFINIBAND_DP,
|
||||
DevPathInfiniBand,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_UART_DP,
|
||||
DevPathUart,
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_VENDOR_DP,
|
||||
DevPathVendor,
|
||||
MEDIA_DEVICE_PATH,
|
||||
MEDIA_HARDDRIVE_DP,
|
||||
DevPathHardDrive,
|
||||
MEDIA_DEVICE_PATH,
|
||||
MEDIA_CDROM_DP,
|
||||
DevPathCDROM,
|
||||
MEDIA_DEVICE_PATH,
|
||||
MEDIA_VENDOR_DP,
|
||||
DevPathVendor,
|
||||
MEDIA_DEVICE_PATH,
|
||||
MEDIA_FILEPATH_DP,
|
||||
DevPathFilePath,
|
||||
MEDIA_DEVICE_PATH,
|
||||
MEDIA_PROTOCOL_DP,
|
||||
DevPathMediaProtocol,
|
||||
|
||||
#if (EFI_SPECIFICATION_VERSION < 0x00020000)
|
||||
MEDIA_DEVICE_PATH,
|
||||
MEDIA_FV_FILEPATH_DP,
|
||||
DevPathFvFilePath,
|
||||
#endif
|
||||
|
||||
BBS_DEVICE_PATH,
|
||||
BBS_BBS_DP,
|
||||
DevPathBssBss,
|
||||
END_DEVICE_PATH_TYPE,
|
||||
END_INSTANCE_DEVICE_PATH_SUBTYPE,
|
||||
DevPathEndInstance,
|
||||
0,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
|
||||
CHAR16 *
|
||||
DevicePathToStr (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
|
||||
)
|
||||
/*++
|
||||
|
||||
Turns the Device Path into a printable string. Allcoates
|
||||
the string from pool. The caller must SafeFreePool the returned
|
||||
string.
|
||||
|
||||
--*/
|
||||
{
|
||||
POOL_PRINT Str;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
|
||||
VOID (*DumpNode) (POOL_PRINT *, VOID *);
|
||||
|
||||
UINTN Index;
|
||||
UINTN NewSize;
|
||||
|
||||
ZeroMem (&Str, sizeof (Str));
|
||||
|
||||
if (DevPath == NULL) {
|
||||
goto Done;
|
||||
}
|
||||
//
|
||||
// Unpacked the device path
|
||||
//
|
||||
DevPath = BdsLibUnpackDevicePath (DevPath);
|
||||
ASSERT (DevPath);
|
||||
|
||||
//
|
||||
// Process each device path node
|
||||
//
|
||||
DevPathNode = DevPath;
|
||||
while (!IsDevicePathEnd (DevPathNode)) {
|
||||
//
|
||||
// Find the handler to dump this device path node
|
||||
//
|
||||
DumpNode = NULL;
|
||||
for (Index = 0; DevPathTable[Index].Function; Index += 1) {
|
||||
|
||||
if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
|
||||
DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
|
||||
) {
|
||||
DumpNode = DevPathTable[Index].Function;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
// If not found, use a generic function
|
||||
//
|
||||
if (!DumpNode) {
|
||||
DumpNode = DevPathNodeUnknown;
|
||||
}
|
||||
//
|
||||
// Put a path seperator in if needed
|
||||
//
|
||||
if (Str.len && DumpNode != DevPathEndInstance) {
|
||||
CatPrint (&Str, L"/");
|
||||
}
|
||||
//
|
||||
// Print this node of the device path
|
||||
//
|
||||
DumpNode (&Str, DevPathNode);
|
||||
|
||||
//
|
||||
// Next device path node
|
||||
//
|
||||
DevPathNode = NextDevicePathNode (DevPathNode);
|
||||
}
|
||||
//
|
||||
// Shrink pool used for string allocation
|
||||
//
|
||||
gBS->FreePool (DevPath);
|
||||
|
||||
Done:
|
||||
NewSize = (Str.len + 1) * sizeof (CHAR16);
|
||||
Str.str = ReallocatePool (Str.str, NewSize, NewSize);
|
||||
ASSERT (Str.str != NULL);
|
||||
Str.str[Str.len] = 0;
|
||||
return Str.str;
|
||||
}
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
LibDuplicateDevicePathInstance (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Function creates a device path data structure that identically matches the
|
||||
device path passed in.
|
||||
|
||||
Arguments:
|
||||
|
||||
DevPath - A pointer to a device path data structure.
|
||||
|
||||
Returns:
|
||||
|
||||
The new copy of DevPath is created to identically match the input.
|
||||
Otherwise, NULL is returned.
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewDevPath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
|
||||
EFI_DEVICE_PATH_PROTOCOL *Temp;
|
||||
UINTN Size;
|
||||
|
||||
//
|
||||
// get the size of an instance from the input
|
||||
//
|
||||
Temp = DevPath;
|
||||
DevicePathInst = GetNextDevicePathInstance (&Temp, &Size);
|
||||
|
||||
//
|
||||
// Make a copy
|
||||
//
|
||||
NewDevPath = NULL;
|
||||
if (Size) {
|
||||
NewDevPath = AllocateZeroPool (Size);
|
||||
ASSERT (NewDevPath != NULL);
|
||||
}
|
||||
|
||||
if (NewDevPath) {
|
||||
CopyMem (NewDevPath, DevicePathInst, Size);
|
||||
}
|
||||
|
||||
return NewDevPath;
|
||||
}
|
30
EdkNt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.mbd
Normal file
30
EdkNt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.mbd
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (c) 2006, 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.
|
||||
-->
|
||||
<LibraryModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
|
||||
<MbdLibHeader>
|
||||
<BaseName>EdkGenericBdsLib</BaseName>
|
||||
<Guid>1ec995b2-d15b-44f6-abd2-050ea7dd37d2</Guid>
|
||||
<Version>0</Version>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2004-2006, Intel Corporation</Copyright>
|
||||
<License>
|
||||
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.
|
||||
</License>
|
||||
<Created>2006-03-13 17:00</Created>
|
||||
<Modified>2006-03-23 12:01</Modified>
|
||||
</MbdLibHeader>
|
||||
</LibraryModuleBuildDescription>
|
78
EdkNt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa
Normal file
78
EdkNt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa
Normal file
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (c) 2006, 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.
|
||||
-->
|
||||
<LibraryModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
|
||||
<MsaLibHeader>
|
||||
<BaseName>EdkGenericBdsLib</BaseName>
|
||||
<ModuleType>DXE_DRIVER</ModuleType>
|
||||
<ComponentType>LIBRARY</ComponentType>
|
||||
<Guid>1ec995b2-d15b-44f6-abd2-050ea7dd37d2</Guid>
|
||||
<Version>0</Version>
|
||||
<Abstract>Component description file for the entry point to a EFIDXE Drivers</Abstract>
|
||||
<Description>FIX ME!</Description>
|
||||
<Copyright>Copyright (c) 2004-2006, Intel Corporation</Copyright>
|
||||
<License>
|
||||
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.
|
||||
</License>
|
||||
<Specification>0</Specification>
|
||||
<Created>2006-03-13 17:00</Created>
|
||||
<Updated>2006-03-23 12:01</Updated>
|
||||
</MsaLibHeader>
|
||||
<LibraryClassDefinitions>
|
||||
<LibraryClass Usage="ALWAYS_PRODUCED">EdkGenericBdsLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">BaseLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">DxeServicesTableLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">DebugLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">PrintLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">HobLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">BaseMemoryLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">MemoryAllocationLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiBootServicesTableLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">UefiRuntimeServicesTableLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">DevicePathLib</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">PerformanceLib</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>BdsBoot.c</Filename>
|
||||
<Filename>BdsConsole.c</Filename>
|
||||
<Filename>BdsConnect.c</Filename>
|
||||
<Filename>DevicePath.c</Filename>
|
||||
<Filename>Performance.c</Filename>
|
||||
<Filename>BdsMisc.c</Filename>
|
||||
<Arch ArchType="IPF">
|
||||
<Filename>Ipf\ShadowRom.c</Filename>
|
||||
</Arch>
|
||||
</SourceFiles>
|
||||
<Includes>
|
||||
<PackageName>MdePkg</PackageName>
|
||||
<PackageName>EdkModulePkg</PackageName>
|
||||
<PackageName>EdkNt32Pkg</PackageName>
|
||||
</Includes>
|
||||
<Protocols>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">LoadedImage</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">FirmwareVolume</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">AcpiS3Save</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">SimpleTextOut</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">SimpleTextIn</Protocol>
|
||||
<Protocol Usage="ALWAYS_CONSUMED">SimpleNetwork</Protocol>
|
||||
</Protocols>
|
||||
<Guids>
|
||||
<GuidEntry Usage="ALWAYS_CONSUMED">
|
||||
<C_Name>ShellFile</C_Name>
|
||||
</GuidEntry>
|
||||
</Guids>
|
||||
</LibraryModuleSurfaceArea>
|
53
EdkNt32Pkg/Library/EdkGenericBdsLib/Ipf/ShadowRom.c
Normal file
53
EdkNt32Pkg/Library/EdkGenericBdsLib/Ipf/ShadowRom.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
ShadowRom.c
|
||||
|
||||
Abstract:
|
||||
|
||||
Shadow all option rom
|
||||
|
||||
Revision History
|
||||
|
||||
--*/
|
||||
|
||||
#include "Tiano.h"
|
||||
#include "EfiDriverLib.h"
|
||||
|
||||
#include EFI_PROTOCOL_DEFINITION (LegacyBios)
|
||||
|
||||
UINT8 mShadowRomFlag = 0;
|
||||
|
||||
VOID
|
||||
ShadowAllOptionRom()
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
|
||||
//
|
||||
// Rom shadow only do once.
|
||||
//
|
||||
if (mShadowRomFlag == 0) {
|
||||
Status = gBS->LocateProtocol (
|
||||
&gEfiLegacyBiosProtocolGuid,
|
||||
NULL,
|
||||
&LegacyBios
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
LegacyBios->PrepareToBootEfi (LegacyBios, NULL, NULL);
|
||||
}
|
||||
|
||||
mShadowRomFlag = 1;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
426
EdkNt32Pkg/Library/EdkGenericBdsLib/Performance.c
Normal file
426
EdkNt32Pkg/Library/EdkGenericBdsLib/Performance.c
Normal file
@@ -0,0 +1,426 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
Performance.c
|
||||
|
||||
Abstract:
|
||||
|
||||
This file include the file which can help to get the system
|
||||
performance, all the function will only include if the performance
|
||||
switch is set.
|
||||
|
||||
--*/
|
||||
|
||||
#include "Performance.h"
|
||||
|
||||
VOID
|
||||
ClearDebugRegisters (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
AsmWriteDr0 (0);
|
||||
AsmWriteDr1 (0);
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
GetShortPdbFileName (
|
||||
CHAR8 *PdbFileName,
|
||||
CHAR8 *GaugeString
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns:
|
||||
|
||||
--*/
|
||||
{
|
||||
UINTN Index;
|
||||
UINTN Index1;
|
||||
UINTN StartIndex;
|
||||
UINTN EndIndex;
|
||||
|
||||
if (PdbFileName == NULL) {
|
||||
AsciiStrCpy (GaugeString, " ");
|
||||
} else {
|
||||
StartIndex = 0;
|
||||
for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)
|
||||
;
|
||||
|
||||
for (Index = 0; PdbFileName[Index] != 0; Index++) {
|
||||
if (PdbFileName[Index] == '\\') {
|
||||
StartIndex = Index + 1;
|
||||
}
|
||||
|
||||
if (PdbFileName[Index] == '.') {
|
||||
EndIndex = Index;
|
||||
}
|
||||
}
|
||||
|
||||
Index1 = 0;
|
||||
for (Index = StartIndex; Index < EndIndex; Index++) {
|
||||
GaugeString[Index1] = PdbFileName[Index];
|
||||
Index1++;
|
||||
if (Index1 == PERF_TOKEN_LENGTH - 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GaugeString[Index1] = 0;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
STATIC
|
||||
CHAR8 *
|
||||
GetPdbPath (
|
||||
VOID *ImageBase
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Located PDB path name in PE image
|
||||
|
||||
Arguments:
|
||||
|
||||
ImageBase - base of PE to search
|
||||
|
||||
Returns:
|
||||
|
||||
Pointer into image at offset of PDB file name if PDB file name is found,
|
||||
Otherwise a pointer to an empty string.
|
||||
|
||||
--*/
|
||||
{
|
||||
CHAR8 *PdbPath;
|
||||
UINT32 DirCount;
|
||||
EFI_IMAGE_DOS_HEADER *DosHdr;
|
||||
EFI_IMAGE_NT_HEADERS *NtHdr;
|
||||
EFI_IMAGE_OPTIONAL_HEADER *OptionalHdr;
|
||||
EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
|
||||
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
|
||||
VOID *CodeViewEntryPointer;
|
||||
|
||||
CodeViewEntryPointer = NULL;
|
||||
PdbPath = NULL;
|
||||
DosHdr = ImageBase;
|
||||
|
||||
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
||||
NtHdr = (EFI_IMAGE_NT_HEADERS *) ((UINT8 *) DosHdr + DosHdr->e_lfanew);
|
||||
OptionalHdr = (VOID *) &NtHdr->OptionalHeader;
|
||||
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
||||
if (DirectoryEntry->VirtualAddress != 0) {
|
||||
for (DirCount = 0;
|
||||
(DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && CodeViewEntryPointer == NULL;
|
||||
DirCount++
|
||||
) {
|
||||
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (DirectoryEntry->VirtualAddress + (UINTN) ImageBase + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));
|
||||
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
|
||||
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageBase);
|
||||
switch (*(UINT32 *) CodeViewEntryPointer) {
|
||||
case CODEVIEW_SIGNATURE_NB10:
|
||||
PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);
|
||||
break;
|
||||
|
||||
case CODEVIEW_SIGNATURE_RSDS:
|
||||
PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PdbPath;
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
GetNameFromHandle (
|
||||
IN EFI_HANDLE Handle,
|
||||
OUT CHAR8 *GaugeString
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_LOADED_IMAGE_PROTOCOL *Image;
|
||||
CHAR8 *PdbFileName;
|
||||
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
|
||||
|
||||
AsciiStrCpy (GaugeString, " ");
|
||||
|
||||
//
|
||||
// Get handle name from image protocol
|
||||
//
|
||||
Status = gBS->HandleProtocol (
|
||||
Handle,
|
||||
&gEfiLoadedImageProtocolGuid,
|
||||
&Image
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = gBS->OpenProtocol (
|
||||
Handle,
|
||||
&gEfiDriverBindingProtocolGuid,
|
||||
(VOID **) &DriverBinding,
|
||||
NULL,
|
||||
NULL,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return ;
|
||||
}
|
||||
//
|
||||
// Get handle name from image protocol
|
||||
//
|
||||
Status = gBS->HandleProtocol (
|
||||
DriverBinding->ImageHandle,
|
||||
&gEfiLoadedImageProtocolGuid,
|
||||
&Image
|
||||
);
|
||||
}
|
||||
|
||||
PdbFileName = GetPdbPath (Image->ImageBase);
|
||||
|
||||
if (PdbFileName != NULL) {
|
||||
GetShortPdbFileName (PdbFileName, GaugeString);
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID
|
||||
WriteBootToOsPerformanceData (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Allocates a block of memory and writes performance data of booting to OS into it.
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_CPU_ARCH_PROTOCOL *Cpu;
|
||||
EFI_PHYSICAL_ADDRESS mAcpiLowMemoryBase;
|
||||
UINT32 mAcpiLowMemoryLength;
|
||||
UINT32 LimitCount;
|
||||
PERF_HEADER mPerfHeader;
|
||||
PERF_DATA mPerfData;
|
||||
EFI_HANDLE *Handles;
|
||||
UINTN NoHandles;
|
||||
CHAR8 GaugeString[PERF_TOKEN_LENGTH];
|
||||
UINT8 *Ptr;
|
||||
UINT32 mIndex;
|
||||
UINT64 Ticker;
|
||||
UINT64 Freq;
|
||||
UINT32 Duration;
|
||||
UINT64 CurrentTicker;
|
||||
UINT64 TimerPeriod;
|
||||
UINTN LogEntryKey;
|
||||
CONST VOID *Handle;
|
||||
CONST CHAR8 *Token;
|
||||
CONST CHAR8 *Module;
|
||||
UINT64 StartTicker;
|
||||
UINT64 EndTicker;
|
||||
|
||||
//
|
||||
// Retrive time stamp count as early as possilbe
|
||||
//
|
||||
Ticker = AsmReadTsc ();
|
||||
|
||||
//
|
||||
// Allocate a block of memory that contain performance data to OS
|
||||
//
|
||||
Status = gBS->AllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiACPIReclaimMemory,
|
||||
4,
|
||||
&mAcpiLowMemoryBase
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
mAcpiLowMemoryLength = 0x1000;
|
||||
|
||||
Ptr = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER));
|
||||
LimitCount = (mAcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
|
||||
|
||||
//
|
||||
// Initialize performance data structure
|
||||
//
|
||||
ZeroMem (&mPerfHeader, sizeof (PERF_HEADER));
|
||||
|
||||
//
|
||||
// Get CPU frequency
|
||||
//
|
||||
Status = gBS->LocateProtocol (
|
||||
&gEfiCpuArchProtocolGuid,
|
||||
NULL,
|
||||
&Cpu
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePages (mAcpiLowMemoryBase, 1);
|
||||
return ;
|
||||
}
|
||||
//
|
||||
// Get Cpu Frequency
|
||||
//
|
||||
Status = Cpu->GetTimerValue (Cpu, 0, &(CurrentTicker), &TimerPeriod);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePages (mAcpiLowMemoryBase, 1);
|
||||
return ;
|
||||
}
|
||||
|
||||
Freq = DivU64x32 (1000000000000, (UINTN) TimerPeriod);
|
||||
|
||||
mPerfHeader.CpuFreq = Freq;
|
||||
|
||||
//
|
||||
// Record BDS raw performance data
|
||||
//
|
||||
mPerfHeader.BDSRaw = Ticker;
|
||||
|
||||
//
|
||||
// Put Detailed performance data into memory
|
||||
//
|
||||
Handles = NULL;
|
||||
Status = gBS->LocateHandleBuffer (
|
||||
AllHandles,
|
||||
NULL,
|
||||
NULL,
|
||||
&NoHandles,
|
||||
&Handles
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
gBS->FreePages (mAcpiLowMemoryBase, 1);
|
||||
return ;
|
||||
}
|
||||
//
|
||||
// Get DXE drivers performance
|
||||
//
|
||||
for (mIndex = 0; mIndex < NoHandles; mIndex++) {
|
||||
Ticker = 0;
|
||||
LogEntryKey = 0;
|
||||
while ((LogEntryKey = GetPerformanceMeasurement (
|
||||
LogEntryKey,
|
||||
&Handle,
|
||||
&Token,
|
||||
&Module,
|
||||
&StartTicker,
|
||||
&EndTicker)) != 0) {
|
||||
if ((Handle == Handles[mIndex]) && (StartTicker < EndTicker)) {
|
||||
Ticker += (EndTicker - StartTicker);
|
||||
}
|
||||
}
|
||||
|
||||
Duration = (UINT32) DivU64x32 (
|
||||
Ticker,
|
||||
(UINT32) Freq
|
||||
);
|
||||
|
||||
if (Duration > 0) {
|
||||
ZeroMem (&mPerfData, sizeof (PERF_DATA));
|
||||
|
||||
GetNameFromHandle (Handles[mIndex], GaugeString);
|
||||
|
||||
AsciiStrCpy (mPerfData.Token, GaugeString);
|
||||
mPerfData.Duration = Duration;
|
||||
|
||||
CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
|
||||
Ptr += sizeof (PERF_DATA);
|
||||
|
||||
mPerfHeader.Count++;
|
||||
if (mPerfHeader.Count == LimitCount) {
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gBS->FreePool (Handles);
|
||||
|
||||
//
|
||||
// Get inserted performance data
|
||||
//
|
||||
LogEntryKey = 0;
|
||||
while ((LogEntryKey = GetPerformanceMeasurement (
|
||||
LogEntryKey,
|
||||
&Handle,
|
||||
&Token,
|
||||
&Module,
|
||||
&StartTicker,
|
||||
&EndTicker)) != 0) {
|
||||
if ((Handle == NULL) && (StartTicker <= EndTicker)) {
|
||||
|
||||
ZeroMem (&mPerfData, sizeof (PERF_DATA));
|
||||
|
||||
AsciiStrnCpy (mPerfData.Token, Token, DXE_PERFORMANCE_STRING_SIZE);
|
||||
mPerfData.Duration = (UINT32) DivU64x32 (
|
||||
EndTicker - StartTicker,
|
||||
(UINT32) Freq
|
||||
);
|
||||
|
||||
CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
|
||||
Ptr += sizeof (PERF_DATA);
|
||||
|
||||
mPerfHeader.Count++;
|
||||
if (mPerfHeader.Count == LimitCount) {
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Done:
|
||||
|
||||
ClearDebugRegisters ();
|
||||
|
||||
mPerfHeader.Signiture = 0x66726550;
|
||||
|
||||
//
|
||||
// Put performance data to memory
|
||||
//
|
||||
CopyMem (
|
||||
(UINT32 *) (UINT32) mAcpiLowMemoryBase,
|
||||
&mPerfHeader,
|
||||
sizeof (PERF_HEADER)
|
||||
);
|
||||
|
||||
gRT->SetVariable (
|
||||
L"PerfDataMemAddr",
|
||||
&gEfiGlobalVariableGuid,
|
||||
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
|
||||
sizeof (UINT32),
|
||||
(VOID *) &mAcpiLowMemoryBase
|
||||
);
|
||||
|
||||
return ;
|
||||
}
|
55
EdkNt32Pkg/Library/EdkGenericBdsLib/Performance.h
Normal file
55
EdkNt32Pkg/Library/EdkGenericBdsLib/Performance.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) 2006, 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:
|
||||
|
||||
Performance.h
|
||||
|
||||
Abstract:
|
||||
|
||||
This file included the performance relete function header and
|
||||
definition.
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _PERF_H_
|
||||
#define _PERF_H_
|
||||
|
||||
#define PERF_TOKEN_LENGTH 28
|
||||
#define PERF_PEI_ENTRY_MAX_NUM 50
|
||||
|
||||
typedef struct {
|
||||
CHAR8 Token[PERF_TOKEN_LENGTH];
|
||||
UINT32 Duration;
|
||||
} PERF_DATA;
|
||||
|
||||
typedef struct {
|
||||
UINT64 BootToOs;
|
||||
UINT64 S3Resume;
|
||||
UINT32 S3EntryNum;
|
||||
PERF_DATA S3Entry[PERF_PEI_ENTRY_MAX_NUM];
|
||||
UINT64 CpuFreq;
|
||||
UINT64 BDSRaw;
|
||||
UINT32 Count;
|
||||
UINT32 Signiture;
|
||||
} PERF_HEADER;
|
||||
|
||||
VOID
|
||||
WriteBootToOsPerformanceData (
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID
|
||||
ClearDebugRegisters (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif
|
47
EdkNt32Pkg/Library/EdkGenericBdsLib/build.xml
Normal file
47
EdkNt32Pkg/Library/EdkGenericBdsLib/build.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!-- Copyright (c) 2006, 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.-->
|
||||
<project basedir="." default="EdkGenericBdsLib"><!--Apply external ANT tasks-->
|
||||
<taskdef resource="GenBuild.tasks"/>
|
||||
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
|
||||
<property environment="env"/>
|
||||
<property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>
|
||||
<import file="${WORKSPACE_DIR}\Tools\Conf\BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->
|
||||
<property name="MODULE_RELATIVE_PATH" value="Library\EdkGenericBdsLib"/>
|
||||
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
|
||||
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
|
||||
<target name="EdkGenericBdsLib">
|
||||
<GenBuild baseName="EdkGenericBdsLib" mbdFilename="${MODULE_DIR}\EdkGenericBdsLib.mbd" msaFilename="${MODULE_DIR}\EdkGenericBdsLib.msa"/>
|
||||
</target>
|
||||
<target depends="EdkGenericBdsLib_clean" name="clean"/>
|
||||
<target depends="EdkGenericBdsLib_cleanall" name="cleanall"/>
|
||||
<target name="EdkGenericBdsLib_clean">
|
||||
<OutputDirSetup baseName="EdkGenericBdsLib" mbdFilename="${MODULE_DIR}\EdkGenericBdsLib.mbd" msaFilename="${MODULE_DIR}\EdkGenericBdsLib.msa"/>
|
||||
<if>
|
||||
<available file="${DEST_DIR_OUTPUT}\EdkGenericBdsLib_build.xml"/>
|
||||
<then>
|
||||
<ant antfile="${DEST_DIR_OUTPUT}\EdkGenericBdsLib_build.xml" target="clean"/>
|
||||
</then>
|
||||
</if>
|
||||
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
|
||||
</target>
|
||||
<target name="EdkGenericBdsLib_cleanall">
|
||||
<OutputDirSetup baseName="EdkGenericBdsLib" mbdFilename="${MODULE_DIR}\EdkGenericBdsLib.mbd" msaFilename="${MODULE_DIR}\EdkGenericBdsLib.msa"/>
|
||||
<if>
|
||||
<available file="${DEST_DIR_OUTPUT}\EdkGenericBdsLib_build.xml"/>
|
||||
<then>
|
||||
<ant antfile="${DEST_DIR_OUTPUT}\EdkGenericBdsLib_build.xml" target="cleanall"/>
|
||||
</then>
|
||||
</if>
|
||||
<delete dir="${DEST_DIR_OUTPUT}"/>
|
||||
<delete dir="${DEST_DIR_DEBUG}"/>
|
||||
<delete>
|
||||
<fileset dir="${BIN_DIR}" includes="**EdkGenericBdsLib*"/>
|
||||
</delete>
|
||||
</target>
|
||||
</project>
|
Reference in New Issue
Block a user