Move BdsDxe and GenericBdsLib to IntelFrameworkModulePkg, these modules need dependent on gEfiLegacyBiosProtocol to provide legacy boot support. But legacy boot is not described by PI/UEFI specification.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7354 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
klu2
2009-01-23 07:24:55 +00:00
parent c516c7178a
commit 5c08e11737
51 changed files with 23764 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,415 @@
/** @file
BDS Lib functions which relate with connect the device
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
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.
**/
#include "InternalBdsLib.h"
/**
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 available and the platform default
console connected.
**/
VOID
EFIAPI
BdsLibConnectAll (
VOID
)
{
//
// 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 ();
}
/**
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 available
if the system have console device.
**/
VOID
BdsLibGenericConnectAll (
VOID
)
{
//
// Most generic way to connect all the drivers
//
BdsLibConnectAllDriversToAllControllers ();
BdsLibConnectAllConsoles ();
}
/**
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.
@param DevicePathToConnect The device path which will be connected, it can be
a multi-instance device path
@retval EFI_SUCCESS All handles associate with every device path node
have been created
@retval EFI_OUT_OF_RESOURCES There is no resource to create new handles
@retval EFI_NOT_FOUND Create the handle associate with one device path
node failed
**/
EFI_STATUS
EFIAPI
BdsLibConnectDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect
)
{
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);
if (DevicePath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CopyOfDevicePath = DevicePath;
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);
if (Instance == NULL) {
FreePool (CopyOfDevicePath);
return EFI_OUT_OF_RESOURCES;
}
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;
}
/**
This function will connect all current system handles recursively. The
connection will finish until every handle's child handle created if it have.
@retval EFI_SUCCESS All handles and it's child handle have been
connected
@retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
**/
EFI_STATUS
EFIAPI
BdsLibConnectAllEfi (
VOID
)
{
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);
}
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
return EFI_SUCCESS;
}
/**
This function will disconnect all current system handles. The disconnection
will finish until every handle have been disconnected.
@retval EFI_SUCCESS All handles have been disconnected
@retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
**/
EFI_STATUS
EFIAPI
BdsLibDisconnectAllEfi (
VOID
)
{
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);
}
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
return EFI_SUCCESS;
}
/**
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.
**/
VOID
EFIAPI
BdsLibConnectAllDriversToAllControllers (
VOID
)
{
EFI_STATUS Status;
do {
//
// Connect All EFI 1.10 drivers following EFI 1.10 algorithm
//
BdsLibConnectAllEfi ();
//
// Check to see if it's possible to dispatch an more DXE drivers.
// The BdsLibConnectAllEfi () may have made new DXE drivers show up.
// If anything is Dispatched Status == EFI_SUCCESS and we will try
// the connect again.
//
Status = gDS->Dispatch ();
} while (!EFI_ERROR (Status));
}
/**
Connect the specific Usb device which match the short form device path,
and whose bus is determined by Host Controller (Uhci or Ehci).
@param HostControllerPI Uhci (0x00) or Ehci (0x20) or Both uhci and ehci
(0xFF)
@param RemainingDevicePath a short-form device path that starts with the first
element being a USB WWID or a USB Class device
path
@return EFI_INVALID_PARAMETER RemainingDevicePath is NULL pointer.
RemainingDevicePath is not a USB device path.
Invalid HostControllerPI type.
@return EFI_SUCCESS Success to connect USB device
@return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
**/
EFI_STATUS
EFIAPI
BdsLibConnectUsbDevByShortFormDP(
IN UINT8 HostControllerPI,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_HANDLE *HandleArray;
UINTN HandleArrayCount;
UINTN Index;
EFI_PCI_IO_PROTOCOL *PciIo;
UINT8 Class[3];
BOOLEAN AtLeastOneConnected;
//
// Check the passed in parameters
//
if (RemainingDevicePath == NULL) {
return EFI_INVALID_PARAMETER;
}
if ((DevicePathType (RemainingDevicePath) != MESSAGING_DEVICE_PATH) ||
((DevicePathSubType (RemainingDevicePath) != MSG_USB_CLASS_DP)
&& (DevicePathSubType (RemainingDevicePath) != MSG_USB_WWID_DP)
)) {
return EFI_INVALID_PARAMETER;
}
if (HostControllerPI != 0xFF &&
HostControllerPI != 0x00 &&
HostControllerPI != 0x20) {
return EFI_INVALID_PARAMETER;
}
//
// Find the usb host controller firstly, then connect with the remaining device path
//
AtLeastOneConnected = FALSE;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiPciIoProtocolGuid,
NULL,
&HandleArrayCount,
&HandleArray
);
if (!EFI_ERROR (Status)) {
for (Index = 0; Index < HandleArrayCount; Index++) {
Status = gBS->HandleProtocol (
HandleArray[Index],
&gEfiPciIoProtocolGuid,
(VOID **)&PciIo
);
if (!EFI_ERROR (Status)) {
//
// Check whether the Pci device is the wanted usb host controller
//
Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
if (!EFI_ERROR (Status)) {
if ((PCI_CLASS_SERIAL == Class[2]) &&
(PCI_CLASS_SERIAL_USB == Class[1])) {
if (HostControllerPI == Class[0] || HostControllerPI == 0xFF) {
Status = gBS->ConnectController (
HandleArray[Index],
NULL,
RemainingDevicePath,
FALSE
);
if (!EFI_ERROR(Status)) {
AtLeastOneConnected = TRUE;
}
}
}
}
}
}
if (AtLeastOneConnected) {
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}

View File

@@ -0,0 +1,901 @@
/** @file
BDS Lib functions which contain all the code to connect console device
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
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.
**/
#include "InternalBdsLib.h"
/**
Check if we need to save the EFI variable with "ConVarName" as name
as NV type
@param ConVarName The name of the EFI variable.
@retval TRUE Set the EFI variable as NV type.
@retval FALSE EFI variable as NV type can be set NonNV.
**/
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 != L'\0') {
Ptr++;
}
if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {
return FALSE;
} else {
return TRUE;
}
}
/**
This function update console variable based on ConVarName, it can
add or remove one specific console device path from the variable
@param ConVarName Console related variable name, ConIn, ConOut,
ErrOut.
@param CustomizedConDevicePath The console device path which will be added to
the console variable ConVarName, this parameter
can not be multi-instance.
@param ExclusiveDevicePath The console device path which will be removed
from the console variable ConVarName, this
parameter can not be multi-instance.
@retval EFI_UNSUPPORTED The added device path is same to the removed one.
@retval EFI_SUCCESS Success add or remove the device path from the
console variable.
**/
EFI_STATUS
EFIAPI
BdsLibUpdateConsoleVariable (
IN CHAR16 *ConVarName,
IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
)
{
EFI_DEVICE_PATH_PROTOCOL *VarConsole;
UINTN DevicePathSize;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
UINT32 Attributes;
VarConsole = NULL;
DevicePathSize = 0;
//
// 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 _ModuleEntryPoint,
// just append current customized device path
//
TempNewDevicePath = NewDevicePath;
NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
if (TempNewDevicePath != NULL) {
FreePool(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) {
if (VarConsole != NULL) {
FreePool(VarConsole);
}
} else {
if (VarConsole != NULL) {
FreePool(VarConsole);
}
if (NewDevicePath != NULL) {
FreePool(NewDevicePath);
}
}
return EFI_SUCCESS;
}
/**
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.
@param ConVarName Console related variable name, ConIn, ConOut,
ErrOut.
@retval EFI_NOT_FOUND There is not any console devices connected
success
@retval EFI_SUCCESS Success connect any one instance of the console
device path base on the variable ConVarName.
**/
EFI_STATUS
EFIAPI
BdsLibConnectConsoleVariable (
IN CHAR16 *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);
if (Instance == NULL) {
FreePool (StartDevicePath);
return EFI_UNSUPPORTED;
}
Next = Instance;
while (!IsDevicePathEndType (Next)) {
Next = NextDevicePathNode (Next);
}
SetDevicePathEndNode (Next);
//
// Check USB1.1 console
//
if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
|| (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
)) {
//
// Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus
//
Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI, Instance);
if (!EFI_ERROR (Status)) {
DeviceExist = TRUE;
}
Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI, Instance);
if (!EFI_ERROR (Status)) {
DeviceExist = TRUE;
}
} else {
//
// 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;
}
}
FreePool(Instance);
} while (CopyOfDevicePath != NULL);
FreePool (StartDevicePath);
if (!DeviceExist) {
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}
/**
This function will search every simpletext device in current system,
and make every simpletext device as pertantial console device.
**/
VOID
EFIAPI
BdsLibConnectAllConsoles (
VOID
)
{
UINTN Index;
EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;
UINTN HandleCount;
EFI_HANDLE *HandleBuffer;
Index = 0;
HandleCount = 0;
HandleBuffer = NULL;
ConDevicePath = NULL;
//
// Update all the console variables
//
gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleTextInProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
for (Index = 0; Index < HandleCount; Index++) {
gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiDevicePathProtocolGuid,
(VOID **) &ConDevicePath
);
BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
}
if (HandleBuffer != NULL) {
FreePool(HandleBuffer);
HandleBuffer = NULL;
}
gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleTextOutProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
for (Index = 0; Index < HandleCount; Index++) {
gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiDevicePathProtocolGuid,
(VOID **) &ConDevicePath
);
BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
}
if (HandleBuffer != NULL) {
FreePool(HandleBuffer);
}
//
// Connect all console variables
//
BdsLibConnectAllDefaultConsoles ();
}
/**
This function will connect console device base on the console
device variable ConIn, ConOut and ErrOut.
@retval EFI_SUCCESS At least one of the ConIn and ConOut device have
been connected success.
@retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
**/
EFI_STATUS
EFIAPI
BdsLibConnectAllDefaultConsoles (
VOID
)
{
EFI_STATUS Status;
//
// Connect all default console variables
//
//
// 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;
}
//
// Insert the performance probe for Console Out
//
PERF_START (NULL, "ConOut", "BDS", 1);
PERF_END (NULL, "ConOut", "BDS", 0);
//
// 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");
//
// The _ModuleEntryPoint err out var is legal.
//
BdsLibConnectConsoleVariable (L"ErrOut");
return EFI_SUCCESS;
}
/**
Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer
is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
buffer is passed in it will be used if it is big enough.
@param BmpImage Pointer to BMP file
@param BmpImageSize Number of bytes in BmpImage
@param GopBlt Buffer containing GOP version of BmpImage.
@param GopBltSize Size of GopBlt in bytes.
@param PixelHeight Height of GopBlt/BmpImage in pixels
@param PixelWidth Width of GopBlt/BmpImage in pixels
@retval EFI_SUCCESS GopBlt and GopBltSize are returned.
@retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image
@retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.
GopBltSize will contain the required size.
@retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.
**/
EFI_STATUS
ConvertBmpToGopBlt (
IN VOID *BmpImage,
IN UINTN BmpImageSize,
IN OUT VOID **GopBlt,
IN OUT UINTN *GopBltSize,
OUT UINTN *PixelHeight,
OUT UINTN *PixelWidth
)
{
UINT8 *Image;
UINT8 *ImageHeader;
BMP_IMAGE_HEADER *BmpHeader;
BMP_COLOR_MAP *BmpColorMap;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
UINTN BltBufferSize;
UINTN Index;
UINTN Height;
UINTN Width;
UINTN ImageIndex;
BOOLEAN IsAllocated;
BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;
if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {
return EFI_UNSUPPORTED;
}
//
// Doesn't support compress.
//
if (BmpHeader->CompressionType != 0) {
return EFI_UNSUPPORTED;
}
//
// Calculate Color Map offset in the image.
//
Image = BmpImage;
BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));
//
// Calculate graphics image data address in the image
//
Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;
ImageHeader = Image;
//
// Calculate the BltBuffer needed size.
//
BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
IsAllocated = FALSE;
if (*GopBlt == NULL) {
//
// GopBlt is not allocated by caller.
//
*GopBltSize = BltBufferSize;
*GopBlt = AllocatePool (*GopBltSize);
IsAllocated = TRUE;
if (*GopBlt == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
//
// GopBlt has been allocated by caller.
//
if (*GopBltSize < BltBufferSize) {
*GopBltSize = BltBufferSize;
return EFI_BUFFER_TOO_SMALL;
}
}
*PixelWidth = BmpHeader->PixelWidth;
*PixelHeight = BmpHeader->PixelHeight;
//
// Convert image from BMP to Blt buffer format
//
BltBuffer = *GopBlt;
for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {
Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];
for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {
switch (BmpHeader->BitPerPixel) {
case 1:
//
// Convert 1-bit (2 colors) BMP to 24-bit color
//
for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {
Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;
Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;
Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;
Blt++;
Width++;
}
Blt--;
Width--;
break;
case 4:
//
// Convert 4-bit (16 colors) BMP Palette to 24-bit color
//
Index = (*Image) >> 4;
Blt->Red = BmpColorMap[Index].Red;
Blt->Green = BmpColorMap[Index].Green;
Blt->Blue = BmpColorMap[Index].Blue;
if (Width < (BmpHeader->PixelWidth - 1)) {
Blt++;
Width++;
Index = (*Image) & 0x0f;
Blt->Red = BmpColorMap[Index].Red;
Blt->Green = BmpColorMap[Index].Green;
Blt->Blue = BmpColorMap[Index].Blue;
}
break;
case 8:
//
// Convert 8-bit (256 colors) BMP Palette to 24-bit color
//
Blt->Red = BmpColorMap[*Image].Red;
Blt->Green = BmpColorMap[*Image].Green;
Blt->Blue = BmpColorMap[*Image].Blue;
break;
case 24:
//
// It is 24-bit BMP.
//
Blt->Blue = *Image++;
Blt->Green = *Image++;
Blt->Red = *Image;
break;
default:
//
// Other bit format BMP is not supported.
//
if (IsAllocated) {
FreePool (*GopBlt);
*GopBlt = NULL;
}
return EFI_UNSUPPORTED;
break;
};
}
ImageIndex = (UINTN) (Image - ImageHeader);
if ((ImageIndex % 4) != 0) {
//
// Bmp Image starts each row on a 32-bit boundary!
//
Image = Image + (4 - (ImageIndex % 4));
}
}
return EFI_SUCCESS;
}
/**
Use Console Control Protocol to lock the Console In Spliter virtual handle.
This is the ConInHandle and ConIn handle in the EFI system table. All key
presses will be ignored until the Password is typed in. The only way to
disable the password is to type it in to a ConIn device.
@param Password Password used to lock ConIn device.
@retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
@retval EFI_UNSUPPORTED Password not found
**/
EFI_STATUS
EFIAPI
LockKeyboards (
IN CHAR16 *Password
)
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Status = ConsoleControl->LockStdIn (ConsoleControl, Password);
return Status;
}
/**
Use Console Control to turn off UGA based Simple Text Out consoles from going
to the UGA device. Put up LogoFile on every UGA device that is a console
@param[in] LogoFile File name of logo to display on the center of the screen.
@retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.
@retval EFI_UNSUPPORTED Logo not found
**/
EFI_STATUS
EFIAPI
EnableQuietBoot (
IN EFI_GUID *LogoFile
)
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
EFI_OEM_BADGING_PROTOCOL *Badging;
UINT32 SizeOfX;
UINT32 SizeOfY;
INTN DestX;
INTN DestY;
UINT8 *ImageData;
UINTN ImageSize;
UINTN BltSize;
UINT32 Instance;
EFI_BADGING_FORMAT Format;
EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;
UINTN CoordinateX;
UINTN CoordinateY;
UINTN Height;
UINTN Width;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
EFI_UGA_DRAW_PROTOCOL *UgaDraw;
UINT32 ColorDepth;
UINT32 RefreshRate;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
UgaDraw = NULL;
//
// Try to open GOP first
//
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
GraphicsOutput = NULL;
//
// Open GOP failed, try to open UGA
//
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
}
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Badging = NULL;
Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
//
// Set console control to graphics mode.
//
Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
if (GraphicsOutput != NULL) {
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
} else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
} else {
return EFI_UNSUPPORTED;
}
Instance = 0;
while (1) {
ImageData = NULL;
ImageSize = 0;
if (Badging != NULL) {
//
// Get image from OEMBadging protocol.
//
Status = Badging->GetImage (
Badging,
&Instance,
&Format,
&ImageData,
&ImageSize,
&Attribute,
&CoordinateX,
&CoordinateY
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Currently only support BMP format.
//
if (Format != EfiBadgingFormatBMP) {
if (ImageData != NULL) {
FreePool (ImageData);
}
continue;
}
} else {
//
// Get the specified image from FV.
//
Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
CoordinateX = 0;
CoordinateY = 0;
Attribute = EfiBadgingDisplayAttributeCenter;
}
Blt = NULL;
Status = ConvertBmpToGopBlt (
ImageData,
ImageSize,
(VOID **) &Blt,
&BltSize,
&Height,
&Width
);
if (EFI_ERROR (Status)) {
FreePool (ImageData);
if (Badging == NULL) {
return Status;
} else {
continue;
}
}
//
// Calculate the display position according to Attribute.
//
switch (Attribute) {
case EfiBadgingDisplayAttributeLeftTop:
DestX = CoordinateX;
DestY = CoordinateY;
break;
case EfiBadgingDisplayAttributeCenterTop:
DestX = (SizeOfX - Width) / 2;
DestY = CoordinateY;
break;
case EfiBadgingDisplayAttributeRightTop:
DestX = (SizeOfX - Width - CoordinateX);
DestY = CoordinateY;;
break;
case EfiBadgingDisplayAttributeCenterRight:
DestX = (SizeOfX - Width - CoordinateX);
DestY = (SizeOfY - Height) / 2;
break;
case EfiBadgingDisplayAttributeRightBottom:
DestX = (SizeOfX - Width - CoordinateX);
DestY = (SizeOfY - Height - CoordinateY);
break;
case EfiBadgingDisplayAttributeCenterBottom:
DestX = (SizeOfX - Width) / 2;
DestY = (SizeOfY - Height - CoordinateY);
break;
case EfiBadgingDisplayAttributeLeftBottom:
DestX = CoordinateX;
DestY = (SizeOfY - Height - CoordinateY);
break;
case EfiBadgingDisplayAttributeCenterLeft:
DestX = CoordinateX;
DestY = (SizeOfY - Height) / 2;
break;
case EfiBadgingDisplayAttributeCenter:
DestX = (SizeOfX - Width) / 2;
DestY = (SizeOfY - Height) / 2;
break;
default:
DestX = CoordinateX;
DestY = CoordinateY;
break;
}
if ((DestX >= 0) && (DestY >= 0)) {
if (GraphicsOutput != NULL) {
Status = GraphicsOutput->Blt (
GraphicsOutput,
Blt,
EfiBltBufferToVideo,
0,
0,
(UINTN) DestX,
(UINTN) DestY,
Width,
Height,
Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
} else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
Status = UgaDraw->Blt (
UgaDraw,
(EFI_UGA_PIXEL *) Blt,
EfiUgaBltBufferToVideo,
0,
0,
(UINTN) DestX,
(UINTN) DestY,
Width,
Height,
Width * sizeof (EFI_UGA_PIXEL)
);
} else {
Status = EFI_UNSUPPORTED;
}
}
FreePool (ImageData);
if (Blt != NULL) {
FreePool (Blt);
}
if (Badging == NULL) {
break;
}
}
return Status;
}
/**
Use Console Control to turn on UGA based Simple Text Out consoles. The UGA
Simple Text Out screens will now be synced up with all non UGA output devices
@retval EFI_SUCCESS UGA devices are back in text mode and synced up.
**/
EFI_STATUS
EFIAPI
DisableQuietBoot (
VOID
)
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Set console control to text mode.
//
return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,114 @@
#/** @file
#
# General BDS defines and produce general interfaces for platform BDS driver including:
# 1) BDS boot policy interface;
# 2) BDS boot device connect interface;
# 3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
#
# Copyright (c) 2007 - 2008, Intel Corporation. <BR>
# 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 = GenericBdsLib
FILE_GUID = e405ec31-ccaa-4dd4-83e8-0aec01703f7e
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = GenericBdsLib|DXE_DRIVER UEFI_APPLICATION
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
DevicePath.c
Performance.c
BdsConnect.c
BdsMisc.c
BdsConsole.c
BdsBoot.c
InternalBdsLib.h
[Sources.IPF]
Ipf/ShadowRom.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
#
#This dependency is because of gEfiLegacyBiosProtocolGuid. It may be removed if a Library class is created to
#abstract away definition in Framework specification or PI spec incorporates the Legacy Booting Protocols.
#
IntelFrameworkPkg/IntelFrameworkPkg.dec
[LibraryClasses]
DevicePathLib
PeCoffGetEntryPointLib
BaseLib
HobLib
UefiRuntimeServicesTableLib
DxeServicesTableLib
MemoryAllocationLib
UefiLib
UefiBootServicesTableLib
BaseMemoryLib
DebugLib
PrintLib
PcdLib
PerformanceLib
TimerLib
PcdLib
DxeServicesLib
[Guids]
gEfiVT100PlusGuid # ALWAYS_CONSUMED
gEfiMemoryTypeInformationGuid # ALWAYS_CONSUMED
gEfiVTUTF8Guid # ALWAYS_CONSUMED
gEfiShellFileGuid # ALWAYS_CONSUMED
gEfiGlobalVariableGuid # ALWAYS_CONSUMED
gEfiVT100Guid # ALWAYS_CONSUMED
gEfiFileInfoGuid # ALWAYS_CONSUMED
gEfiPcAnsiGuid # ALWAYS_CONSUMED
gEfiGenericPlatformVariableGuid # ALWAYS_CONSUMED
gEfiUartDevicePathGuid # ALWAYS_CONSUMED
gEfiSasDevicePathGuid # ALWAYS_CONSUMED
[Protocols]
gEfiSimpleFileSystemProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiSimpleTextOutProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiPciIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiLoadedImageProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiDevicePathToTextProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiSimpleNetworkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiDebugPortProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiSimpleTextInProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiBlockIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiFirmwareVolume2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiLegacyBiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiFirmwareVolumeDispatchProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiAcpiS3SaveProtocolGuid
gEfiGraphicsOutputProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiUgaDrawProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiConsoleControlProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiOEMBadgingProtocolGuid # PROTOCOL ALWAYS_CONSUMED
gEfiHiiFontProtocolGuid # PROTOCOL ALWAYS_CONSUMED
[FeaturePcd.common]
gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootTimeOutDefault
gEfiMdeModulePkgTokenSpaceGuid.PcdDefaultBootFileName

View File

@@ -0,0 +1,106 @@
/** @file
BDS library definition, include the file and data structure
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
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 _INTERNAL_BDS_LIB_H_
#define _INTERNAL_BDS_LIB_H_
#include <PiDxe.h>
#include <IndustryStandard/Pci22.h>
#include <Protocol/BlockIo.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/Cpu.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/DebugPort.h>
#include <Protocol/DevicePath.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/LegacyBios.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/FirmwareVolume2.h>
#include <Protocol/PciIo.h>
#include <Protocol/AcpiS3Save.h>
#include <Protocol/Performance.h>
#include <Protocol/FirmwareVolumeDispatch.h>
#include <Protocol/OEMBadging.h>
#include <Protocol/ConsoleControl.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/UgaDraw.h>
#include <Protocol/HiiFont.h>
#include <Protocol/HiiImage.h>
#include <Guid/MemoryTypeInformation.h>
#include <Guid/FileInfo.h>
#include <Guid/GlobalVariable.h>
#include <Guid/PcAnsi.h>
#include <Guid/ShellFile.h>
#include <Guid/GenericPlatformVariable.h>
#include <Guid/Bmp.h>
#include <Library/PrintLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/HobLib.h>
#include <Library/BaseLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PerformanceLib.h>
#include <Library/PcdLib.h>
#include <Library/IfrSupportLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/GenericBdsLib.h>
#include <Library/TimerLib.h>
#include <Library/PcdLib.h>
#include <Library/DxeServicesLib.h>
#define PERFORMANCE_SIGNATURE SIGNATURE_32 ('P', 'e', 'r', 'f')
#define PERF_TOKEN_SIZE 28
#define PERF_TOKEN_LENGTH (PERF_TOKEN_SIZE - 1)
#define PERF_PEI_ENTRY_MAX_NUM 50
typedef struct {
CHAR8 Token[PERF_TOKEN_SIZE];
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;
/**
Allocates a block of memory and writes performance data of booting into it.
OS can processing these record.
**/
VOID
WriteBootToOsPerformanceData (
VOID
);
#endif // _BDS_LIB_H_

View File

@@ -0,0 +1,46 @@
/** @file
Shadow all option rom
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
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.
**/
#include "InternalBdsLib.h"
UINT8 mShadowRomFlag = 0;
/**
Shadow all opton ROM if the it is not done.
**/
VOID
ShadowAllOptionRom(
VOID
)
{
EFI_STATUS Status;
EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
//
// Rom shadow only do once.
//
if (mShadowRomFlag == 0) {
Status = gBS->LocateProtocol (
&gEfiLegacyBiosProtocolGuid,
NULL,
(VOID **) &LegacyBios
);
if (!EFI_ERROR (Status)) {
LegacyBios->PrepareToBootEfi (LegacyBios, NULL, NULL);
}
mShadowRomFlag = 1;
}
return ;
}

View File

@@ -0,0 +1,316 @@
/** @file
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.
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
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.
**/
#include "InternalBdsLib.h"
PERF_HEADER mPerfHeader;
PERF_DATA mPerfData;
/**
Get the short verion of PDB file name to be
used in performance data logging.
@param PdbFileName The long PDB file name.
@param GaugeString The output string to be logged by performance logger.
**/
VOID
GetShortPdbFileName (
IN CONST CHAR8 *PdbFileName,
OUT CHAR8 *GaugeString
)
{
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 ;
}
/**
Get the name from the Driver handle, which can be a handle with
EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
This name can be used in performance data logging.
@param Handle Driver handle.
@param GaugeString The output string to be logged by performance logger.
**/
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,
(VOID **) &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,
(VOID **) &Image
);
}
PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);
if (PdbFileName != NULL) {
GetShortPdbFileName (PdbFileName, GaugeString);
}
return ;
}
/**
Allocates a block of memory and writes performance data of booting into it.
OS can processing these record.
**/
VOID
WriteBootToOsPerformanceData (
VOID
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase;
UINT32 AcpiLowMemoryLength;
UINT32 LimitCount;
EFI_HANDLE *Handles;
UINTN NoHandles;
CHAR8 GaugeString[PERF_TOKEN_LENGTH];
UINT8 *Ptr;
UINT32 Index;
UINT64 Ticker;
UINT64 Freq;
UINT32 Duration;
UINTN LogEntryKey;
CONST VOID *Handle;
CONST CHAR8 *Token;
CONST CHAR8 *Module;
UINT64 StartTicker;
UINT64 EndTicker;
UINT64 StartValue;
UINT64 EndValue;
BOOLEAN CountUp;
//
// Retrive time stamp count as early as possilbe
//
Ticker = GetPerformanceCounter ();
Freq = GetPerformanceCounterProperties (&StartValue, &EndValue);
Freq = DivU64x32 (Freq, 1000);
mPerfHeader.CpuFreq = Freq;
//
// Record BDS raw performance data
//
if (EndValue >= StartValue) {
mPerfHeader.BDSRaw = Ticker - StartValue;
CountUp = TRUE;
} else {
mPerfHeader.BDSRaw = StartValue - Ticker;
CountUp = FALSE;
}
AcpiLowMemoryLength = 0x2000;
//
// Allocate a block of memory that contain performance data to OS
//
Status = gBS->AllocatePages (
AllocateAnyPages,
EfiACPIReclaimMemory,
EFI_SIZE_TO_PAGES (AcpiLowMemoryLength),
&AcpiLowMemoryBase
);
if (EFI_ERROR (Status)) {
return ;
}
Ptr = (UINT8 *) ((UINT32) AcpiLowMemoryBase + sizeof (PERF_HEADER));
LimitCount = (AcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
//
// Put Detailed performance data into memory
//
Handles = NULL;
Status = gBS->LocateHandleBuffer (
AllHandles,
NULL,
NULL,
&NoHandles,
&Handles
);
if (EFI_ERROR (Status)) {
gBS->FreePages (AcpiLowMemoryBase, 1);
return ;
}
//
// Get DXE drivers performance
//
for (Index = 0; Index < NoHandles; Index++) {
Ticker = 0;
LogEntryKey = 0;
while ((LogEntryKey = GetPerformanceMeasurement (
LogEntryKey,
&Handle,
&Token,
&Module,
&StartTicker,
&EndTicker)) != 0) {
if ((Handle == Handles[Index]) && (EndTicker != 0)) {
Ticker += CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
}
}
Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
if (Duration > 0) {
GetNameFromHandle (Handles[Index], 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 && EndTicker != 0) {
ZeroMem (&mPerfData, sizeof (PERF_DATA));
AsciiStrnCpy (mPerfData.Token, Token, PERF_TOKEN_LENGTH);
Ticker = CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);
mPerfData.Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);
CopyMem (Ptr, &mPerfData, sizeof (PERF_DATA));
Ptr += sizeof (PERF_DATA);
mPerfHeader.Count++;
if (mPerfHeader.Count == LimitCount) {
goto Done;
}
}
}
Done:
mPerfHeader.Signiture = PERFORMANCE_SIGNATURE;
//
// Put performance data to ACPI memory
//
CopyMem (
(UINTN *) (UINTN) AcpiLowMemoryBase,
&mPerfHeader,
sizeof (PERF_HEADER)
);
gRT->SetVariable (
L"PerfDataMemAddr",
&gEfiGenericPlatformVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof (EFI_PHYSICAL_ADDRESS),
&AcpiLowMemoryBase
);
return ;
}