summaryrefslogtreecommitdiff
path: root/Nt32Pkg
diff options
context:
space:
mode:
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>2008-02-28 12:04:31 +0000
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>2008-02-28 12:04:31 +0000
commit0a9e9295d994aff5033ecb33479591f5e4a40b6b (patch)
tree8c43e0b60d0d0cd6c15d4e9a6f39d3ceb8079298 /Nt32Pkg
parent725a03bd4aa084ce55bb72ab914251df6f849d5d (diff)
downloadedk2-platforms-0a9e9295d994aff5033ecb33479591f5e4a40b6b.tar.xz
Replaced by Y:\work\MdeModulePkg\Library\GenericBdsLib\GenericBdsLib.inf
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4772 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Nt32Pkg')
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/BdsBoot.c1310
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c359
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c396
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c1097
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/DevicePath.c1121
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.inf89
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa144
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLibInternal.h96
-rw-r--r--Nt32Pkg/Library/EdkGenericBdsLib/Performance.c386
9 files changed, 0 insertions, 4998 deletions
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/BdsBoot.c b/Nt32Pkg/Library/EdkGenericBdsLib/BdsBoot.c
deleted file mode 100644
index a8078b4b7a..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/BdsBoot.c
+++ /dev/null
@@ -1,1310 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-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 "EdkGenericBdsLibInternal.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 UEFI 2.0 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_BLOCK_IO_PROTOCOL *BlkIo;
- VOID *Buffer;
- LIST_ENTRY TempBootLists;
-
- //
- // Record the performance data for End of BDS
- //
- PERF_END (0, BDS_TOK, NULL, 0);
-
- *ExitDataSize = 0;
- *ExitData = NULL;
-
- //
- // Notes: put EFI64 ROM Shadow Solution
- //
- EFI64_SHADOW_ALL_LEGACY_ROM ();
-
- //
- // 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;
- }
- //
- // Signal the EFI_EVENT_SIGNAL_READY_TO_BOOT event
- //
- 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);
- }
-
- //
- // If the boot option point to Internal FV shell, make sure it is valid
- //
- Status = UpdateFvFileDevicePath (&DevicePath, &gEfiShellFileGuid);
- if (!EFI_ERROR(Status)) {
- if (Option->DevicePath != NULL) {
- FreePool (Option->DevicePath);
- }
- Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
- CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
- //
- // Update the shell boot option
- //
- InitializeListHead (&TempBootLists);
- BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");
- }
-
- DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Booting UEFI 2.0 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) {
- //
- // Issue a dummy read to the device to check for media change.
- // When the removable media is changed, any Block IO read/write will
- // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is
- // returned. After the Block IO protocol is reinstalled, subsequent
- // Block IO read/write will success.
- //
- Status = gBS->HandleProtocol (
- Handle,
- &gEfiBlockIoProtocolGuid,
- (VOID **) &BlkIo
- );
- if (!EFI_ERROR (Status)) {
- Buffer = AllocatePool (BlkIo->Media->BlockSize);
- if (Buffer != NULL) {
- BlkIo->ReadBlocks (
- BlkIo,
- BlkIo->Media->MediaId,
- 0,
- BlkIo->Media->BlockSize,
- Buffer
- );
- FreePool (Buffer);
- }
- }
-
- 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;
- }
- }
- }
-
- FreePool (BlockIoBuffer);
- return Status;
-}
-
-EFI_STATUS
-BdsLibDeleteOptionFromHandle (
- IN EFI_HANDLE Handle
- )
-/*++
-
-Routine Description:
-
- Delete the boot option associated with the handle passed in
-
-Arguments:
-
- Handle - The handle which present the device path to create boot option
-
-Returns:
-
- EFI_SUCCESS - Delete the boot option success
-
- EFI_NOT_FOUND - If the Device Path is not found in the system
-
- EFI_OUT_OF_RESOURCES - Lack of memory resource
-
- Other - Error return value from SetVariable()
-
---*/
-{
- UINT16 *BootOrder;
- UINT8 *BootOptionVar;
- UINTN BootOrderSize;
- UINTN BootOptionSize;
- EFI_STATUS Status;
- UINTN Index;
- UINT16 BootOption[BOOT_OPTION_MAX_CHAR];
- UINTN DevicePathSize;
- UINTN OptionDevicePathSize;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
- UINT8 *TempPtr;
- CHAR16 *Description;
-
- Status = EFI_SUCCESS;
- BootOrder = NULL;
- BootOrderSize = 0;
-
- BootOrder = BdsLibGetVariableAndSize (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- &BootOrderSize
- );
- if (NULL == BootOrder) {
- return EFI_NOT_FOUND;
- }
-
- DevicePath = DevicePathFromHandle (Handle);
- if (DevicePath == NULL) {
- return EFI_NOT_FOUND;
- }
- DevicePathSize = GetDevicePathSize (DevicePath);
-
- Index = 0;
- while (Index < BootOrderSize / sizeof (UINT16)) {
- UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
- BootOptionVar = BdsLibGetVariableAndSize (
- BootOption,
- &gEfiGlobalVariableGuid,
- &BootOptionSize
- );
- if (NULL == BootOptionVar) {
- FreePool (BootOrder);
- return EFI_OUT_OF_RESOURCES;
- }
-
- TempPtr = BootOptionVar;
- TempPtr += sizeof (UINT32) + sizeof (UINT16);
- Description = (CHAR16 *) TempPtr;
- TempPtr += StrSize ((CHAR16 *) TempPtr);
- OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
- OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);
-
- //
- // Check whether the device path match
- //
- if ((OptionDevicePathSize == DevicePathSize) &&
- (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {
- BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);
- FreePool (BootOptionVar);
- break;
- }
-
- FreePool (BootOptionVar);
- Index++;
- }
-
- Status = gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- BootOrderSize,
- BootOrder
- );
-
- FreePool (BootOrder);
-
- return Status;
-}
-
-EFI_STATUS
-BdsDeleteAllInvalidEfiBootOption (
- VOID
- )
-/*++
-
-Routine Description:
-
- Delete all invalid EFI boot options. The probable invalid boot option could
- be Removable media or Network boot device.
-
-Arguments:
-
- VOID
-
-Returns:
-
- EFI_SUCCESS - Delete all invalid boot option success
-
- EFI_NOT_FOUND - Variable "BootOrder" is not found
-
- EFI_OUT_OF_RESOURCES - Lack of memory resource
-
- Other - Error return value from SetVariable()
-
---*/
-{
- UINT16 *BootOrder;
- UINT8 *BootOptionVar;
- UINTN BootOrderSize;
- UINTN BootOptionSize;
- EFI_STATUS Status;
- UINTN Index;
- UINTN Index2;
- UINT16 BootOption[BOOT_OPTION_MAX_CHAR];
- UINTN OptionDevicePathSize;
- EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
- EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
- UINT8 *TempPtr;
- CHAR16 *Description;
- EFI_HANDLE Handle;
- BOOLEAN NeedDelete;
-
- Status = EFI_SUCCESS;
- BootOrder = NULL;
- BootOrderSize = 0;
-
- BootOrder = BdsLibGetVariableAndSize (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- &BootOrderSize
- );
- if (NULL == BootOrder) {
- return EFI_NOT_FOUND;
- }
-
- Index = 0;
- while (Index < BootOrderSize / sizeof (UINT16)) {
- UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
- BootOptionVar = BdsLibGetVariableAndSize (
- BootOption,
- &gEfiGlobalVariableGuid,
- &BootOptionSize
- );
- if (NULL == BootOptionVar) {
- FreePool (BootOrder);
- return EFI_OUT_OF_RESOURCES;
- }
-
- TempPtr = BootOptionVar;
- TempPtr += sizeof (UINT32) + sizeof (UINT16);
- Description = (CHAR16 *) TempPtr;
- TempPtr += StrSize ((CHAR16 *) TempPtr);
- OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
- OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);
-
- //
- // Skip legacy boot option (BBS boot device)
- //
- if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&
- (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {
- FreePool (BootOptionVar);
- Index++;
- continue;
- }
-
- TempDevicePath = OptionDevicePath;
- LastDeviceNode = OptionDevicePath;
- while (!EfiIsDevicePathEnd (TempDevicePath)) {
- LastDeviceNode = TempDevicePath;
- TempDevicePath = EfiNextDevicePathNode (TempDevicePath);
- }
- //
- // Skip the boot option that point to a file, since the device path in
- // removable media boot option doesn't contains a file name.
- //
- if (((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) &&
- (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) ||
- //
- // Skip boot option for internal Shell, it's always valid
- //
- (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode) != NULL)) {
- FreePool (BootOptionVar);
- Index++;
- continue;
- }
-
- NeedDelete = TRUE;
- //
- // Check if it's a valid boot option for removable media
- //
- TempDevicePath = OptionDevicePath;
- Status = gBS->LocateDevicePath (
- &gEfiSimpleFileSystemProtocolGuid,
- &TempDevicePath,
- &Handle
- );
- if (!EFI_ERROR (Status)) {
- NeedDelete = FALSE;
- }
- //
- // Check if it's a valid boot option for network boot device
- //
- TempDevicePath = OptionDevicePath;
- Status = gBS->LocateDevicePath (
- &gEfiLoadFileProtocolGuid,
- &TempDevicePath,
- &Handle
- );
- if (!EFI_ERROR (Status)) {
- NeedDelete = FALSE;
- }
-
- if (NeedDelete) {
- //
- // Delete this invalid boot option "Boot####"
- //
- Status = gRT->SetVariable (
- BootOption,
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- 0,
- NULL
- );
- //
- // Mark this boot option in boot order as deleted
- //
- BootOrder[Index] = 0xffff;
- }
-
- FreePool (BootOptionVar);
- Index++;
- }
-
- //
- // Adjust boot order array
- //
- Index2 = 0;
- for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
- if (BootOrder[Index] != 0xffff) {
- BootOrder[Index2] = BootOrder[Index];
- Index2 ++;
- }
- }
- Status = gRT->SetVariable (
- L"BootOrder",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- Index2 * sizeof (UINT16),
- BootOrder
- );
-
- FreePool (BootOrder);
-
- 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;
- EFI_BLOCK_IO_PROTOCOL *BlkIo;
- UINTN Index;
- UINTN NumberLoadFileHandles;
- EFI_HANDLE *LoadFileHandles;
- VOID *ProtocolInstance;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
- UINTN FvHandleCount;
- EFI_HANDLE *FvHandleBuffer;
- EFI_FV_FILETYPE Type;
- UINTN Size;
- EFI_FV_FILE_ATTRIBUTES Attributes;
- UINT32 AuthenticationStatus;
- EFI_DEVICE_PATH_PROTOCOL *FilePath;
- EFI_HANDLE ImageHandle;
- EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
- BOOLEAN NeedDelete;
-
- 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;
-
- //
- // Delete invalid boot option
- //
- BdsDeleteAllInvalidEfiBootOption ();
- //
- // Parse removable media
- //
- 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;
- }
- }
-
- //
- // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
- // machinename is ia32, ia64, x64, ...
- //
- FilePath = FileDevicePath (FileSystemHandles[Index], EFI_REMOVABLE_MEDIA_FILE_NAME);
- NeedDelete = TRUE;
- Status = gBS->LoadImage (
- TRUE,
- mBdsImageHandle,
- FilePath,
- NULL,
- 0,
- &ImageHandle
- );
- if (!EFI_ERROR(Status)) {
- //
- // Verify the image is a EFI application (and not a driver)
- //
- Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
- ASSERT (!EFI_ERROR(Status));
-
- if (ImageInfo->ImageCodeType == EfiLoaderCode) {
- NeedDelete = FALSE;
- }
- }
-
- if (NeedDelete) {
- //
- // No such file or the file is not a EFI application, delete this boot option
- //
- BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
- } else {
- BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList);
- BootOptionNumber++;
- }
- }
-
- if (NumberFileSystemHandles) {
- 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) {
- FreePool (LoadFileHandles);
- }
- //
- // Check if we have on flash shell
- //
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiFirmwareVolume2ProtocolGuid,
- NULL,
- &FvHandleCount,
- &FvHandleBuffer
- );
- for (Index = 0; Index < FvHandleCount; Index++) {
- gBS->HandleProtocol (
- FvHandleBuffer[Index],
- &gEfiFirmwareVolume2ProtocolGuid,
- (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) {
- 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);
- }
-
-}
-
-EFI_STATUS
-EFIAPI
-UpdateFvFileDevicePath (
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- IN EFI_GUID *FileGuid
- )
-/*++
-
-Routine Description:
- According to a file guild, check a Fv file device path is valid. If it is invalid,
- try to return the valid device path.
- FV address maybe changes for memory layout adjust from time to time, use this funciton
- could promise the Fv file device path is right.
-
-Arguments:
- DevicePath - on input, the Fv file device path need to check
- on output, the updated valid Fv file device path
-
- FileGuid - the Fv file guild
-
-Returns:
- EFI_INVALID_PARAMETER - the input DevicePath or FileGuid is invalid parameter
- EFI_UNSUPPORTED - the input DevicePath does not contain Fv file guild at all
- EFI_ALREADY_STARTED - the input DevicePath has pointed to Fv file, it is valid
- EFI_SUCCESS - has successfully updated the invalid DevicePath, and return the updated
- device path in DevicePath
-
---*/
-{
- EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
- EFI_STATUS Status;
- EFI_GUID *GuidPoint;
- UINTN Index;
- UINTN FvHandleCount;
- EFI_HANDLE *FvHandleBuffer;
- EFI_FV_FILETYPE Type;
- UINTN Size;
- EFI_FV_FILE_ATTRIBUTES Attributes;
- UINT32 AuthenticationStatus;
- BOOLEAN FindFvFile;
- EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
- EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode;
- EFI_HANDLE FoundFvHandle;
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
-
- if ((DevicePath == NULL) || (*DevicePath == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
- if (FileGuid == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- //
- // Check whether the device path point to the default the input Fv file
- //
- TempDevicePath = *DevicePath;
- LastDeviceNode = TempDevicePath;
- while (!EfiIsDevicePathEnd (TempDevicePath)) {
- LastDeviceNode = TempDevicePath;
- TempDevicePath = EfiNextDevicePathNode (TempDevicePath);
- }
-
- GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LastDeviceNode);
-
- if (GuidPoint == NULL) {
- //
- // if this option does not points to a Fv file, just return EFI_UNSUPPORTED
- //
- return EFI_UNSUPPORTED;
- }
-
- if (!CompareGuid (GuidPoint, FileGuid)) {
- //
- // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED
- //
- return EFI_UNSUPPORTED;
- }
-
- //
- // Check whether the input Fv file device path is valid
- //
- TempDevicePath = *DevicePath;
- FoundFvHandle = NULL;
- Status = gBS->LocateDevicePath (
- &gEfiFirmwareVolume2ProtocolGuid,
- &TempDevicePath,
- &FoundFvHandle
- );
- if (!EFI_ERROR (Status)) {
- Status = gBS->HandleProtocol (
- FoundFvHandle,
- &gEfiFirmwareVolume2ProtocolGuid,
- (VOID **) &Fv
- );
- if (!EFI_ERROR (Status)) {
- //
- // Set FV ReadFile Buffer as NULL, only need to check whether input Fv file exist there
- //
- Status = Fv->ReadFile (
- Fv,
- FileGuid,
- NULL,
- &Size,
- &Type,
- &Attributes,
- &AuthenticationStatus
- );
- if (!EFI_ERROR (Status)) {
- return EFI_ALREADY_STARTED;
- }
- }
- }
-
- //
- // Look for the input wanted FV file in current FV
- // First, try to look for in Bds own FV. Bds and input wanted FV file usually are in the same FV
- //
- FindFvFile = FALSE;
- FoundFvHandle = NULL;
- Status = gBS->HandleProtocol (
- mBdsImageHandle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **) &LoadedImage
- );
- if (!EFI_ERROR (Status)) {
- Status = gBS->HandleProtocol (
- LoadedImage->DeviceHandle,
- &gEfiFirmwareVolume2ProtocolGuid,
- (VOID **) &Fv
- );
- if (!EFI_ERROR (Status)) {
- Status = Fv->ReadFile (
- Fv,
- FileGuid,
- NULL,
- &Size,
- &Type,
- &Attributes,
- &AuthenticationStatus
- );
- if (!EFI_ERROR (Status)) {
- FindFvFile = TRUE;
- FoundFvHandle = LoadedImage->DeviceHandle;
- }
- }
- }
- //
- // Second, if fail to find, try to enumerate all FV
- //
- if (!FindFvFile) {
- gBS->LocateHandleBuffer (
- ByProtocol,
- &gEfiFirmwareVolume2ProtocolGuid,
- NULL,
- &FvHandleCount,
- &FvHandleBuffer
- );
- for (Index = 0; Index < FvHandleCount; Index++) {
- gBS->HandleProtocol (
- FvHandleBuffer[Index],
- &gEfiFirmwareVolume2ProtocolGuid,
- (VOID **) &Fv
- );
-
- Status = Fv->ReadFile (
- Fv,
- FileGuid,
- NULL,
- &Size,
- &Type,
- &Attributes,
- &AuthenticationStatus
- );
- if (EFI_ERROR (Status)) {
- //
- // Skip if input Fv file not in the FV
- //
- continue;
- }
- FindFvFile = TRUE;
- FoundFvHandle = FvHandleBuffer[Index];
- break;
- }
- }
-
- if (FindFvFile) {
- //
- // Build the shell device path
- //
- NewDevicePath = DevicePathFromHandle (FoundFvHandle);
- EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
- NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
- *DevicePath = NewDevicePath;
- return EFI_SUCCESS;
- }
-
- return EFI_NOT_FOUND;
-}
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c b/Nt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c
deleted file mode 100644
index c2f541e532..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/BdsConnect.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-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
-
---*/
-
-#include <EdkGenericBdsLibInternal.h>
-
-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) {
- 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);
- }
-
- 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);
- }
-
- 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 UEFI 2.0 drivers following UEFI 2.0 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));
-
-}
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c b/Nt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c
deleted file mode 100644
index 4dedf1d7ff..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/BdsConsole.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-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
-
---*/
-
-#include <EdkGenericBdsLibInternal.h>
-
-BOOLEAN
-IsNvNeed (
- IN CHAR16 *ConVarName
- )
-{
- CHAR16 *Ptr;
-
- Ptr = ConVarName;
-
- //
- // If the variable includes "Dev" at last, we consider
- // it does not support NV attribute.
- //
- while (*Ptr) {
- Ptr++;
- }
-
- if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {
- return FALSE;
- } else {
- return TRUE;
- }
-}
-
-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 *NewDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
- UINT32 Attributes;
-
- VarConsole = NULL;
- DevicePathSize = 0;
- 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
- );
-
- //
- // Initialize NewDevicePath
- //
- NewDevicePath = VarConsole;
-
- //
- // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
- // In the end, NewDevicePath is the final device path.
- //
- if (ExclusiveDevicePath != NULL && VarConsole != NULL) {
- NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);
- }
- //
- // Try to append customized device path to NewDevicePath.
- //
- if (CustomizedConDevicePath != NULL) {
- if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {
- //
- // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
- //
- NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);
- //
- // In the first check, the default console variable will be null,
- // just append current customized device path
- //
- TempNewDevicePath = NewDevicePath;
- NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
- BdsLibSafeFreePool(TempNewDevicePath);
- }
- }
-
- //
- // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
- //
- if (IsNvNeed(ConVarName)) {
- //
- // ConVarName has NV attribute.
- //
- Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
- } else {
- //
- // ConVarName does not have NV attribute.
- //
- Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
- }
-
- //
- // Finally, Update the variable of the default console by NewDevicePath
- //
- gRT->SetVariable (
- ConVarName,
- &gEfiGlobalVariableGuid,
- Attributes,
- GetDevicePathSize (NewDevicePath),
- NewDevicePath
- );
-
- if (VarConsole == NewDevicePath) {
- BdsLibSafeFreePool(VarConsole);
- } else {
- BdsLibSafeFreePool(VarConsole);
- BdsLibSafeFreePool(NewDevicePath);
- }
-
- 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 = 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;
- }
- BdsLibSafeFreePool(Instance);
- } while (CopyOfDevicePath != NULL);
-
- 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);
- }
-
- BdsLibSafeFreePool(HandleBuffer);
-
- 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);
- }
-
- BdsLibSafeFreePool(HandleBuffer);
-
- //
- // 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;
-
- //
- // Connect all default console variables
- //
-
- //
- // Because possibly the platform is legacy free, in such case,
- // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
- // so we need not check the status.
- //
- BdsLibConnectConsoleVariable (L"ConIn");
-
- //
- // It seems impossible not to have any ConOut device on platform,
- // so we check the status here.
- //
- Status = BdsLibConnectConsoleVariable (L"ConOut");
- if (EFI_ERROR (Status)) {
- return Status;
- }
- //
- // Special treat the err out device, becaues the null
- // err out var is legal.
- //
- BdsLibConnectConsoleVariable (L"ErrOut");
-
- return EFI_SUCCESS;
-
-}
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c b/Nt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c
deleted file mode 100644
index 70d337e338..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c
+++ /dev/null
@@ -1,1097 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-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
-
---*/
-
-#include <EdkGenericBdsLibInternal.h>
-
-
-#define MAX_STRING_LEN 200
-static BOOLEAN mFeaturerSwitch = TRUE;
-static BOOLEAN mResetRequired = FALSE;
-
-
-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 = PcdGet16 (PcdUefiVariableDefaultTimeout);
-
- //
- // 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
- //
- FreePool (OptionPtr);
- FreePool (TempOptionPtr);
- return EFI_SUCCESS;
- } else {
- //
- // Boot device path changed, need update.
- //
- UpdateBootDevicePath = TRUE;
- break;
- }
- }
-
- 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) {
- FreePool (OptionPtr);
- FreePool (TempOptionPtr);
- return Status;
- }
-
- 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)) {
- FreePool (TempOptionPtr);
- FreePool (OptionOrderPtr);
- return Status;
- }
-
- if (TempOptionPtr != NULL) {
- FreePool (TempOptionPtr);
- }
- 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);
- FreePool (Variable);
- return Option;
- }
-
- FreePool (Variable);
- 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];
-
- }
-
- FreePool (OptionOrder);
-
- 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;
-}
-
-VOID
-BdsLibSafeFreePool (
- IN VOID *Buffer
- )
-/*++
-
-Routine Description:
-
- Free pool safely.
-
-Arguments:
-
- Buffer - The allocated pool entry to free
-
-Returns:
-
- Pointer of the buffer allocated.
-
---*/
-{
- if (Buffer != NULL) {
- FreePool (Buffer);
- Buffer = NULL;
- }
-}
-
-EFI_DEVICE_PATH_PROTOCOL *
-BdsLibDelPartMatchInstance (
- IN EFI_DEVICE_PATH_PROTOCOL *Multi,
- IN EFI_DEVICE_PATH_PROTOCOL *Single
- )
-/*++
-
-Routine Description:
-
- Delete the instance in Multi which matches partly with Single 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:
-
- This function will remove the device path instances in Multi which partly
- match with the Single, and return the result device path. If there is no
- remaining device path as a result, this function will return NULL.
-
---*/
-{
- EFI_DEVICE_PATH_PROTOCOL *Instance;
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
- UINTN InstanceSize;
- UINTN SingleDpSize;
- UINTN Size;
-
- NewDevicePath = NULL;
- TempNewDevicePath = NULL;
-
- if (Multi == NULL || Single == NULL) {
- return Multi;
- }
-
- Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
- SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;
- InstanceSize -= END_DEVICE_PATH_LENGTH;
-
- while (Instance != NULL) {
-
- Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;
-
- if ((CompareMem (Instance, Single, Size) != 0)) {
- //
- // Append the device path instance which does not match with Single
- //
- TempNewDevicePath = NewDevicePath;
- NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
- BdsLibSafeFreePool(TempNewDevicePath);
- }
- BdsLibSafeFreePool(Instance);
- Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
- InstanceSize -= END_DEVICE_PATH_LENGTH;
- }
-
- return NewDevicePath;
-}
-
-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);
-
- //
- // 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 (CompareMem (Single, DevicePathInst, Size) == 0) {
- FreePool (DevicePathInst);
- return TRUE;
- }
-
- FreePool (DevicePathInst);
- DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
- }
-
- return FALSE;
-}
-
-EFI_STATUS
-BdsLibOutputStrings (
- IN EFI_SIMPLE_TEXT_OUTPUT_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;
-}
-
-//
-// Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
-// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
-// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
-//
-
-VOID
-EnableResetReminderFeature (
- VOID
- )
-/*++
-
-Routine Description:
-
- Enable the setup browser reset reminder feature.
- This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- mFeaturerSwitch = TRUE;
-}
-
-VOID
-DisableResetReminderFeature (
- VOID
- )
-/*++
-
-Routine Description:
-
- Disable the setup browser reset reminder feature.
- This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- mFeaturerSwitch = FALSE;
-}
-
-VOID
-EnableResetRequired (
- VOID
- )
-/*++
-
-Routine Description:
-
- Record the info that a reset is required.
- A module boolean variable is used to record whether a reset is required.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- mResetRequired = TRUE;
-}
-
-VOID
-DisableResetRequired (
- VOID
- )
-/*++
-
-Routine Description:
-
- Record the info that no reset is required.
- A module boolean variable is used to record whether a reset is required.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- mResetRequired = FALSE;
-}
-
-BOOLEAN
-IsResetReminderFeatureEnable (
- VOID
- )
-/*++
-
-Routine Description:
-
- Check whether platform policy enable the reset reminder feature. The default is enabled.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- return mFeaturerSwitch;
-}
-
-BOOLEAN
-IsResetRequired (
- VOID
- )
-/*++
-
-Routine Description:
-
- Check if user changed any option setting which needs a system reset to be effective.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- return mResetRequired;
-}
-
-VOID
-SetupResetReminder (
- VOID
- )
-/*++
-
-Routine Description:
-
- Check whether a reset is needed, and finish the reset reminder feature.
- If a reset is needed, Popup a menu to notice user, and finish the feature
- according to the user selection.
-
-Arguments:
-
- VOID
-
-Returns:
-
- VOID
-
---*/
-{
- EFI_STATUS Status;
- EFI_FORM_BROWSER_PROTOCOL *Browser;
- EFI_INPUT_KEY Key;
- CHAR16 *StringBuffer1;
- CHAR16 *StringBuffer2;
-
-
- //
- //check any reset required change is applied? if yes, reset system
- //
- if (IsResetReminderFeatureEnable ()) {
- if (IsResetRequired ()) {
-
- Status = gBS->LocateProtocol (
- &gEfiFormBrowserProtocolGuid,
- NULL,
- &Browser
- );
-
- ASSERT_EFI_ERROR (Status);
-
- StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
- ASSERT (StringBuffer1 != NULL);
- StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
- ASSERT (StringBuffer2 != NULL);
- StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");
- StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
- //
- // Popup a menu to notice user
- //
- do {
- Browser->CreatePopUp (2, TRUE, 0, NULL, &Key, StringBuffer1, StringBuffer2);
- } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
-
- FreePool (StringBuffer1);
- FreePool (StringBuffer2);
- //
- // If the user hits the YES Response key, reset
- //
- if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {
- gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
- }
- gST->ConOut->ClearScreen (gST->ConOut);
- }
- }
-}
-
-EFI_STATUS
-BdsLibGetHiiHandles (
- IN EFI_HII_PROTOCOL *Hii,
- IN OUT UINT16 *HandleBufferLength,
- OUT FRAMEWORK_EFI_HII_HANDLE **HiiHandleBuffer
- )
-/*++
-
-Routine Description:
-
- Determines the handles that are currently active in the database.
- It's the caller's responsibility to free handle buffer.
-
-Arguments:
-
- This - A pointer to the EFI_HII_PROTOCOL instance.
- HandleBufferLength - On input, a pointer to the length of the handle buffer. On output,
- the length of the handle buffer that is required for the handles found.
- HiiHandleBuffer - Pointer to an array of EFI_HII_PROTOCOL instances returned.
-
-Returns:
-
- EFI_SUCCESS - Get an array of EFI_HII_PROTOCOL instances successfully.
- EFI_INVALID_PARAMETER - Hii is NULL.
- EFI_NOT_FOUND - Database not found.
-
---*/
-{
- UINT16 TempBufferLength;
- EFI_STATUS Status;
-
- TempBufferLength = 0;
-
- //
- // Try to find the actual buffer size for HiiHandle Buffer.
- //
- Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);
-
- if (Status == EFI_BUFFER_TOO_SMALL) {
- *HiiHandleBuffer = AllocateZeroPool (TempBufferLength);
- Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);
- //
- // we should not fail here.
- //
- ASSERT_EFI_ERROR (Status);
- }
-
- *HandleBufferLength = TempBufferLength;
-
- return Status;
-
-}
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/DevicePath.c b/Nt32Pkg/Library/EdkGenericBdsLib/DevicePath.c
deleted file mode 100644
index c544c77b13..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/DevicePath.c
+++ /dev/null
@@ -1,1121 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-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.
-
---*/
-
-#include <EdkGenericBdsLibInternal.h>
-
-EFI_GUID mEfiWinNtThunkProtocolGuid = EFI_WIN_NT_THUNK_PROTOCOL_GUID;
-EFI_GUID mEfiWinNtUgaGuid = EFI_WIN_NT_UGA_GUID;
-EFI_GUID mEfiWinNtGopGuid = EFI_WIN_NT_GOP_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);
- }
-
- 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);
- }
-
- 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, &mEfiWinNtGopGuid)) {
- CatPrint (Str, L"%s", L"GOP");
- 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
-DevPathExtendedAcpi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;
- //
- // Index for HID, UID and CID strings, 0 for non-exist
- //
- UINT16 HIDSTRIdx;
- UINT16 UIDSTRIdx;
- UINT16 CIDSTRIdx;
- UINT16 Index;
- UINT16 Length;
- UINT16 Anchor;
- CHAR8 *AsChar8Array;
-
- ASSERT (Str != NULL);
- ASSERT (DevPath != NULL);
-
- HIDSTRIdx = 0;
- UIDSTRIdx = 0;
- CIDSTRIdx = 0;
- ExtendedAcpi = DevPath;
- Length = DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);
-
- ASSERT (Length >= 19);
- AsChar8Array = (CHAR8 *) ExtendedAcpi;
-
- //
- // find HIDSTR
- //
- Anchor = 16;
- for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {
- ;
- }
- if (Index > Anchor) {
- HIDSTRIdx = Anchor;
- }
- //
- // find UIDSTR
- //
- Anchor = Index + 1;
- for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {
- ;
- }
- if (Index > Anchor) {
- UIDSTRIdx = Anchor;
- }
- //
- // find CIDSTR
- //
- Anchor = Index + 1;
- for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {
- ;
- }
- if (Index > Anchor) {
- CIDSTRIdx = Anchor;
- }
-
- if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {
- CatPrint (Str, L"AcpiExp(");
- if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", EISA_ID_TO_NUM (ExtendedAcpi->HID));
- } else {
- CatPrint (Str, L"%08x,", ExtendedAcpi->HID);
- }
- if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", EISA_ID_TO_NUM (ExtendedAcpi->CID));
- } else {
- CatPrint (Str, L"%08x,", ExtendedAcpi->CID);
- }
- if (UIDSTRIdx != 0) {
- CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\")");
- }
- } else {
- CatPrint (Str, L"AcpiEx(");
- if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", EISA_ID_TO_NUM (ExtendedAcpi->HID));
- } else {
- CatPrint (Str, L"%08x,", ExtendedAcpi->HID);
- }
- if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- CatPrint (Str, L"PNP%04x,", EISA_ID_TO_NUM (ExtendedAcpi->CID));
- } else {
- CatPrint (Str, L"%08x,", ExtendedAcpi->CID);
- }
- CatPrint (Str, L"%x,", ExtendedAcpi->UID);
-
- if (HIDSTRIdx != 0) {
- CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\",");
- }
- if (CIDSTRIdx != 0) {
- CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\",");
- }
- if (UIDSTRIdx != 0) {
- CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
- } else {
- CatPrint (Str, L"\"\")");
- }
- }
-
-}
-
-VOID
-DevPathAdrAcpi (
- IN OUT POOL_PRINT *Str,
- IN VOID *DevPath
- )
-{
- ACPI_ADR_DEVICE_PATH *AcpiAdr;
- UINT16 Index;
- UINT16 Length;
- UINT16 AdditionalAdrCount;
-
- AcpiAdr = DevPath;
- Length = DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
- AdditionalAdrCount = (Length - 8) / 4;
-
- CatPrint (Str, L"AcpiAdr(%x", AcpiAdr->ADR);
- for (Index = 0; Index < AdditionalAdrCount; Index++) {
- CatPrint (Str, L",%x", *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
- }
- CatPrint (Str, L")");
-}
-
-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->FvFileName);
-}
-
-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,
- ACPI_DEVICE_PATH,
- ACPI_EXTENDED_DP,
- DevPathExtendedAcpi,
- ACPI_DEVICE_PATH,
- ACPI_ADR_DP,
- DevPathAdrAcpi,
- 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,
- 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
- //
- 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;
-}
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.inf b/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.inf
deleted file mode 100644
index 085aee1cd1..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.inf
+++ /dev/null
@@ -1,89 +0,0 @@
-#/** @file
-# EDK Generic BDS Common APIs Library Instance.
-#
-# The library instance provides common library routines help in
-# performance measurement, device path debug print, boot device selections,
-# boot device connection, console supports in BDS phase and boot from boot
-# device.
-# Copyright (c) 2006 - 2007, Intel Corporation.
-#
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# 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.
-#
-#
-#**/
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = EdkGenericBdsLib
- FILE_GUID = 1ec995b2-d15b-44f6-abd2-050ea7dd37d2
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- LIBRARY_CLASS = EdkGenericBdsLib|DXE_DRIVER
- EDK_RELEASE_VERSION = 0x00020000
- EFI_SPECIFICATION_VERSION = 0x00020000
-
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32
-#
-
-[Sources.common]
- BdsMisc.c
- Performance.c
- DevicePath.c
- BdsConnect.c
- BdsConsole.c
- BdsBoot.c
- EdkGenericBdsLibInternal.h
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- IntelFrameworkPkg/IntelFrameworkPkg.dec
- Nt32Pkg/Nt32Pkg.dec
-
-[LibraryClasses]
- PeCoffLib
- PerformanceLib
- DevicePathLib
- UefiRuntimeServicesTableLib
- UefiBootServicesTableLib
- MemoryAllocationLib
- BaseMemoryLib
- HobLib
- PrintLib
- DebugLib
- DxeServicesTableLib
- UefiLib
- BaseLib
- PcdLib
-
-[Guids]
- gEfiGlobalVariableGuid # ALWAYS_CONSUMED
- gEfiGenericPlatformVariableGuid # ALWAYS_CONSUMED
- gEfiShellFileGuid # ALWAYS_CONSUMED
-
-[Protocols]
- gEfiSimpleFileSystemProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiLoadFileProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiFormBrowserProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiDriverBindingProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiBlockIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiLegacyBiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiSimpleNetworkProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiSimpleTextInProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiSimpleTextOutProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiFirmwareVolumeProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
- gEfiLoadedImageProtocolGuid # PROTOCOL ALWAYS_CONSUMED
-
-[FixedPcd.common]
- gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultTimeout
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa b/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa
deleted file mode 100644
index 062660218a..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLib.msa
+++ /dev/null
@@ -1,144 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <MsaHeader>
- <ModuleName>EdkGenericBdsLib</ModuleName>
- <ModuleType>DXE_DRIVER</ModuleType>
- <GuidValue>1ec995b2-d15b-44f6-abd2-050ea7dd37d2</GuidValue>
- <Version>1.0</Version>
- <Abstract>EDK Generic BDS Common APIs Library Instance.</Abstract>
- <Description>The library instance provides common library routines help in
- performance measurement, device path debug print, boot device selections,
- boot device connection, console supports in BDS phase and boot from boot
- device.</Description>
- <Copyright>Copyright (c) 2006 - 2007, 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>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
- </MsaHeader>
- <ModuleDefinitions>
- <SupportedArchitectures>IA32</SupportedArchitectures>
- <BinaryModule>false</BinaryModule>
- <OutputFileBasename>EdkGenericBdsLib</OutputFileBasename>
- </ModuleDefinitions>
- <LibraryClassDefinitions>
- <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER">
- <Keyword>EdkGenericBdsLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>BaseLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>DxeServicesTableLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>DebugLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>PrintLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>HobLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>BaseMemoryLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>MemoryAllocationLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiBootServicesTableLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>UefiRuntimeServicesTableLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>DevicePathLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>PerformanceLib</Keyword>
- </LibraryClass>
- <LibraryClass Usage="ALWAYS_CONSUMED">
- <Keyword>PeCoffLib</Keyword>
- </LibraryClass>
- </LibraryClassDefinitions>
- <SourceFiles>
- <Filename>BdsBoot.c</Filename>
- <Filename>BdsConsole.c</Filename>
- <Filename>BdsConnect.c</Filename>
- <Filename>DevicePath.c</Filename>
- <Filename>Performance.h</Filename>
- <Filename>Performance.c</Filename>
- <Filename>BdsMisc.c</Filename>
- </SourceFiles>
- <PackageDependencies>
- <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
- <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
- <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>
- </PackageDependencies>
- <Protocols>
- <Protocol Usage="ALWAYS_CONSUMED">
- <ProtocolCName>gEfiLoadedImageProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiFirmwareVolumeProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiAcpiS3SaveProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiSimpleNetworkProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="ALWAYS_CONSUMED">
- <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="ALWAYS_CONSUMED">
- <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="ALWAYS_CONSUMED">
- <ProtocolCName>gEfiLegacyBiosProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="ALWAYS_CONSUMED">
- <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiDriverBindingProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="ALWAYS_CONSUMED">
- <ProtocolCName>gEfiFormBrowserProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiLoadFileProtocolGuid</ProtocolCName>
- </Protocol>
- <Protocol Usage="SOMETIMES_CONSUMED">
- <ProtocolCName>gEfiSimpleFileSystemProtocolGuid</ProtocolCName>
- </Protocol>
- </Protocols>
- <Guids>
- <GuidCNames Usage="ALWAYS_CONSUMED">
- <GuidCName>gEfiShellFileGuid</GuidCName>
- </GuidCNames>
- <GuidCNames Usage="ALWAYS_CONSUMED">
- <GuidCName>gEfiGenericPlatformVariableGuid</GuidCName>
- </GuidCNames>
- <GuidCNames Usage="ALWAYS_CONSUMED">
- <GuidCName>gEfiGlobalVariableGuid</GuidCName>
- </GuidCNames>
- </Guids>
- <Externs>
- <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
- <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
- </Externs>
-</ModuleSurfaceArea> \ No newline at end of file
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLibInternal.h b/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLibInternal.h
deleted file mode 100644
index 830e715e70..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/EdkGenericBdsLibInternal.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/**@file
- Common header file shared by all source files.
-
- This file includes package header files, library classes and protocol, PPI & GUID definitions.
-
- Copyright (c) 2006 - 2007, Intel Corporation.
- All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- 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.
-**/
-
-#ifndef __EDK_GENERIC_BDS_LIB_INTERNAL_H_
-#define __EDK_GENERIC_BDS_LIB_INTERNAL_H_
-
-
-//
-// The package level header files this module uses
-//
-#include <PiDxe.h>
-#include <WinNtDxe.h>
-#include <Protocol/Cpu.h>
-#include <Protocol/SimpleTextIn.h>
-#include <Protocol/SimpleTextOut.h>
-#include <Protocol/LoadedImage.h>
-#include <Protocol/SimpleFileSystem.h>
-#include <Protocol/BlockIo.h>
-#include <Protocol/SimpleNetwork.h>
-#include <Protocol/FrameworkFormBrowser.h>
-#include <Protocol/LegacyBios.h>
-#include <Protocol/DriverBinding.h>
-#include <Protocol/LoadFile.h>
-#include <Protocol/DevicePath.h>
-#include <Protocol/FirmwareVolume2.h>
-#include <Protocol/Performance.h>
-#include <Protocol/WinNtIo.h>
-#include <Guid/PcAnsi.h>
-#include <Guid/GlobalVariable.h>
-#include <Guid/GenericPlatformVariable.h>
-#include <Guid/ShellFile.h>
-#include <Library/EdkGenericBdsLib.h>
-#include <Library/BaseLib.h>
-#include <Library/UefiLib.h>
-#include <Library/DxeServicesTableLib.h>
-#include <Library/DebugLib.h>
-#include <Library/PrintLib.h>
-#include <Library/HobLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/PerformanceLib.h>
-#include <Library/PeCoffLib.h>
-#include <Library/PcdLib.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
- );
-
-EFI_STATUS
-EFIAPI
-UpdateFvFileDevicePath (
- IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- IN EFI_GUID *FileGuid
- );
-
-#endif
diff --git a/Nt32Pkg/Library/EdkGenericBdsLib/Performance.c b/Nt32Pkg/Library/EdkGenericBdsLib/Performance.c
deleted file mode 100644
index 7d581b45f0..0000000000
--- a/Nt32Pkg/Library/EdkGenericBdsLib/Performance.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/*++
-
-Copyright (c) 2006 - 2007, Intel Corporation
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-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 <EdkGenericBdsLibInternal.h>
-
-
-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.
-
---*/
-{
- PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
-
- ZeroMem (&ImageContext, sizeof (ImageContext));
- ImageContext.Handle = ImageBase;
- ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
-
- PeCoffLoaderGetImageInfo (&ImageContext);
-
- return ImageContext.PdbPointer;
-}
-
-
-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
- //
- mAcpiLowMemoryBase = 0xFFFFFFFF;
- Status = gBS->AllocatePages (
- AllocateMaxAddress,
- EfiReservedMemoryType,
- 4,
- &mAcpiLowMemoryBase
- );
- if (EFI_ERROR (Status)) {
- return ;
- }
-
- mAcpiLowMemoryLength = EFI_PAGES_TO_SIZE(4);
-
- 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, 4);
- return ;
- }
- //
- // Get Cpu Frequency
- //
- Status = Cpu->GetTimerValue (Cpu, 0, &(CurrentTicker), &TimerPeriod);
- if (EFI_ERROR (Status)) {
- gBS->FreePages (mAcpiLowMemoryBase, 4);
- 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, 4);
- 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;
- }
- }
- }
-
- 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:
-
- mPerfHeader.Signiture = 0x66726550;
-
- //
- // Put performance data to memory
- //
- CopyMem (
- (UINT32 *) (UINT32) mAcpiLowMemoryBase,
- &mPerfHeader,
- sizeof (PERF_HEADER)
- );
-
- gRT->SetVariable (
- L"PerfDataMemAddr",
- &gEfiGenericPlatformVariableGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- sizeof (UINT32),
- (VOID *) &mAcpiLowMemoryBase
- );
-
- return ;
-}