Add in the 1st version of ECP.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2832 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12
2007-06-28 07:00:39 +00:00
parent 30d4a0c7ec
commit 3eb9473ea9
1433 changed files with 266617 additions and 0 deletions

View File

@@ -0,0 +1,172 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Debug.c
Abstract:
Support for Debug primatives.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "EfiPrintLib.h"
#include "EfiStatusCode.h"
#include EFI_GUID_DEFINITION (StatusCodeCallerId)
#include EFI_GUID_DEFINITION (StatusCodeDataTypeId)
#include EFI_PROTOCOL_DEFINITION (DEBUGMASK)
//
// You would think you should divid by sizeof (UINT64), but EBC does not like
// that!
//
#define EFI_STATUS_CODE_DATA_MAX_SIZE64 (EFI_STATUS_CODE_DATA_MAX_SIZE / 8)
VOID
EfiDebugAssert (
IN CHAR8 *FileName,
IN INTN LineNumber,
IN CHAR8 *Description
)
/*++
Routine Description:
Worker function for ASSERT(). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded BREAKPOINT().
We use UINT64 buffers due to IPF alignment concerns.
Arguments:
FileName - File name of failing routine.
LineNumber - Line number of failing ASSERT().
Description - Descritption, usally the assertion,
Returns:
None
--*/
{
UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
EfiDebugAssertWorker (FileName, LineNumber, Description, sizeof (Buffer), Buffer);
EfiLibReportStatusCode (
(EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),
(EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),
0,
&gEfiCallerIdGuid,
(EFI_STATUS_CODE_DATA *) Buffer
);
//
// Put break point in module that contained the error.
//
EFI_BREAKPOINT ();
}
VOID
EfiDebugVPrint (
IN UINTN ErrorLevel,
IN CHAR8 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded do nothing.
We use UINT64 buffers due to IPF alignment concerns.
Arguments:
ErrorLevel - If error level is set do the debug print.
Format - String to use for the print, followed by Print arguments.
Marker - VarArgs
Returns:
None
--*/
{
UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
UINTN ImageDebugMask;
//
// Check driver debug mask value and global mask
//
if (gDebugMaskInterface != NULL) {
gDebugMaskInterface->GetDebugMask (gDebugMaskInterface, &ImageDebugMask);
if (!(ErrorLevel & ImageDebugMask)) {
return ;
}
} else if (!(gErrorLevel & ErrorLevel)) {
return ;
}
EfiDebugVPrintWorker (ErrorLevel, Format, Marker, sizeof (Buffer), Buffer);
EfiLibReportStatusCode (
EFI_DEBUG_CODE,
(EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),
(UINT32) ErrorLevel,
&gEfiCallerIdGuid,
(EFI_STATUS_CODE_DATA *) Buffer
);
return ;
}
VOID
EfiDebugPrint (
IN UINTN ErrorLevel,
IN CHAR8 *Format,
...
)
/*++
Routine Description:
Wrapper for EfiDebugVPrint ()
Arguments:
ErrorLevel - If error level is set do the debug print.
Format - String to use for the print, followed by Print arguments.
... - Print arguments.
Returns:
None
--*/
{
VA_LIST Marker;
VA_START (Marker, Format);
EfiDebugVPrint (ErrorLevel, Format, Marker);
VA_END (Marker);
}

View File

@@ -0,0 +1,607 @@
/*++
Copyright (c) 2004 - 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:
Device Path services. The thing to remember is device paths are built out of
nodes. The device path is terminated by an end node that is length
sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
all over this file.
The only place where multi-instance device paths are supported is in
environment varibles. Multi-instance device paths should never be placed
on a Handle.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include EFI_PROTOCOL_DEFINITION (DevicePath)
EFI_DEVICE_PATH_PROTOCOL *
EfiDevicePathInstance (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT UINTN *Size
)
/*++
Routine Description:
Function retrieves the next device path instance from a device path data structure.
Arguments:
DevicePath - A pointer to a device path data structure.
Size - A pointer to the size of a device path instance in bytes.
Returns:
This function returns a pointer to the current device path instance.
In addition, it returns the size in bytes of the current device path instance in Size,
and a pointer to the next device path instance in DevicePath.
If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.
--*/
{
EFI_DEVICE_PATH_PROTOCOL *DevPath;
EFI_DEVICE_PATH_PROTOCOL *ReturnValue;
UINT8 Temp;
if (*DevicePath == NULL) {
if (Size != NULL) {
*Size = 0;
}
return NULL;
}
//
// Find the end of the device path instance
//
DevPath = *DevicePath;
while (!IsDevicePathEndType (DevPath)) {
DevPath = NextDevicePathNode (DevPath);
}
//
// Compute the size of the device path instance
//
if (Size != NULL) {
*Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
}
//
// Make a copy and return the device path instance
//
Temp = DevPath->SubType;
DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
ReturnValue = EfiDuplicateDevicePath (*DevicePath);
DevPath->SubType = Temp;
//
// If DevPath is the end of an entire device path, then another instance
// does not follow, so *DevicePath is set to NULL.
//
if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {
*DevicePath = NULL;
} else {
*DevicePath = NextDevicePathNode (DevPath);
}
return ReturnValue;
}
BOOLEAN
EfiIsDevicePathMultiInstance (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
Routine Description:
Return TRUE is this is a multi instance device path.
Arguments:
DevicePath - A pointer to a device path data structure.
Returns:
TRUE - If DevicePath is multi instance. FALSE - If DevicePath is not multi
instance.
--*/
{
EFI_DEVICE_PATH_PROTOCOL *Node;
if (DevicePath == NULL) {
return FALSE;
}
Node = DevicePath;
while (!EfiIsDevicePathEnd (Node)) {
if (EfiIsDevicePathEndInstance (Node)) {
return TRUE;
}
Node = EfiNextDevicePathNode (Node);
}
return FALSE;
}
UINTN
EfiDevicePathSize (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
Routine Description:
Calculate the space size of a device path.
Arguments:
DevicePath - A specified device path
Returns:
The size.
--*/
{
EFI_DEVICE_PATH_PROTOCOL *Start;
if (DevicePath == NULL) {
return 0;
}
//
// Search for the end of the device path structure
//
Start = DevicePath;
while (!EfiIsDevicePathEnd (DevicePath)) {
DevicePath = EfiNextDevicePathNode (DevicePath);
}
//
// Compute the size and add back in the size of the end device path structure
//
return ((UINTN) DevicePath - (UINTN) Start) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
}
EFI_DEVICE_PATH_PROTOCOL *
EfiDevicePathFromHandle (
IN EFI_HANDLE Handle
)
/*++
Routine Description:
Get the device path protocol interface installed on a specified handle.
Arguments:
Handle - a specified handle
Returns:
The device path protocol interface installed on that handle.
--*/
{
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
DevicePath = NULL;
gBS->HandleProtocol (
Handle,
&gEfiDevicePathProtocolGuid,
(VOID *) &DevicePath
);
return DevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
EfiDuplicateDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
Routine Description:
Duplicate a device path structure.
Arguments:
DevicePath - The device path to duplicated.
Returns:
The duplicated device path.
--*/
{
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
UINTN Size;
if (DevicePath == NULL) {
return NULL;
}
//
// Compute the size
//
Size = EfiDevicePathSize (DevicePath);
if (Size == 0) {
return NULL;
}
//
// Allocate space for duplicate device path
//
NewDevicePath = EfiLibAllocateCopyPool (Size, DevicePath);
return NewDevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
EfiAppendDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *Src1,
IN EFI_DEVICE_PATH_PROTOCOL *Src2
)
/*++
Routine Description:
Function is used to append a Src1 and Src2 together.
Arguments:
Src1 - A pointer to a device path data structure.
Src2 - A pointer to a device path data structure.
Returns:
A pointer to the new device path is returned.
NULL is returned if space for the new device path could not be allocated from pool.
It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.
--*/
{
UINTN Size;
UINTN Size1;
UINTN Size2;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath;
//
// If there's only 1 path, just duplicate it
//
if (!Src1) {
ASSERT (!IsDevicePathUnpacked (Src2));
return EfiDuplicateDevicePath (Src2);
}
if (!Src2) {
ASSERT (!IsDevicePathUnpacked (Src1));
return EfiDuplicateDevicePath (Src1);
}
//
// Allocate space for the combined device path. It only has one end node of
// length EFI_DEVICE_PATH_PROTOCOL
//
Size1 = EfiDevicePathSize (Src1);
Size2 = EfiDevicePathSize (Src2);
Size = Size1 + Size2 - sizeof (EFI_DEVICE_PATH_PROTOCOL);
NewDevicePath = EfiLibAllocateCopyPool (Size, Src1);
if (NewDevicePath != NULL) {
//
// Over write Src1 EndNode and do the copy
//
SecondDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath + (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL)));
EfiCopyMem (SecondDevicePath, Src2, Size2);
}
return NewDevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
EfiAppendDevicePathNode (
IN EFI_DEVICE_PATH_PROTOCOL *Src1,
IN EFI_DEVICE_PATH_PROTOCOL *Node
)
/*++
Routine Description:
Function is used to append a device path node to the end of another device path.
Arguments:
Src1 - A pointer to a device path data structure.
Node - A pointer to a device path data structure.
Returns:
This function returns a pointer to the new device path.
If there is not enough temporary pool memory available to complete this function,
then NULL is returned.
--*/
{
EFI_DEVICE_PATH_PROTOCOL *Temp;
EFI_DEVICE_PATH_PROTOCOL *NextNode;
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
UINTN NodeLength;
//
// Build a Node that has a terminator on it
//
NodeLength = DevicePathNodeLength (Node);
Temp = EfiLibAllocateCopyPool (NodeLength + sizeof (EFI_DEVICE_PATH_PROTOCOL), Node);
if (Temp == NULL) {
return NULL;
}
//
// Add and end device path node to convert Node to device path
//
NextNode = NextDevicePathNode (Temp);
SetDevicePathEndNode (NextNode);
//
// Append device paths
//
NewDevicePath = EfiAppendDevicePath (Src1, Temp);
gBS->FreePool (Temp);
return NewDevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
EfiFileDevicePath (
IN EFI_HANDLE Device OPTIONAL,
IN CHAR16 *FileName
)
/*++
Routine Description:
This function allocates a device path for a file and appends it to an existiong
device path.
Arguments:
Device - A pointer to a device handle.
FileName - A pointer to a Null-terminated Unicodestring.
Returns:
A device path contain the file name.
--*/
{
UINTN Size;
FILEPATH_DEVICE_PATH *FilePath;
EFI_DEVICE_PATH_PROTOCOL *Eop;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
for (Size = 0; FileName[Size] != 0; Size++)
;
Size = (Size + 1) * 2;
FilePath = EfiLibAllocateZeroPool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof (EFI_DEVICE_PATH_PROTOCOL));
DevicePath = NULL;
if (FilePath != NULL) {
//
// Build a file path
//
FilePath->Header.Type = MEDIA_DEVICE_PATH;
FilePath->Header.SubType = MEDIA_FILEPATH_DP;
SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
EfiCopyMem (FilePath->PathName, FileName, Size);
Eop = NextDevicePathNode (&FilePath->Header);
SetDevicePathEndNode (Eop);
//
// Append file path to device's device path
//
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) FilePath;
if (Device != NULL) {
DevicePath = EfiAppendDevicePath (
EfiDevicePathFromHandle (Device),
DevicePath
);
gBS->FreePool (FilePath);
}
}
return DevicePath;
}
EFI_DEVICE_PATH_PROTOCOL *
EfiAppendDevicePathInstance (
IN EFI_DEVICE_PATH_PROTOCOL *Src,
IN EFI_DEVICE_PATH_PROTOCOL *Instance
)
/*++
Routine Description:
Append a device path instance to another.
Arguments:
Src - The device path instance to be appended with.
Instance - The device path instance appending the other.
Returns:
The contaction of these two.
--*/
{
UINT8 *Ptr;
EFI_DEVICE_PATH_PROTOCOL *DevPath;
UINTN SrcSize;
UINTN InstanceSize;
if (Src == NULL) {
return EfiDuplicateDevicePath (Instance);
}
SrcSize = EfiDevicePathSize (Src);
InstanceSize = EfiDevicePathSize (Instance);
Ptr = EfiLibAllocateCopyPool (SrcSize + InstanceSize, Src);
if (Ptr != NULL) {
DevPath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
while (!IsDevicePathEnd (DevPath)) {
DevPath = NextDevicePathNode (DevPath);
}
//
// Convert the End to an End Instance, since we are
// appending another instacne after this one its a good
// idea.
//
DevPath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
DevPath = NextDevicePathNode (DevPath);
EfiCopyMem (DevPath, Instance, InstanceSize);
}
return (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
}
VOID
EFIAPI
EfiInitializeFwVolDevicepathNode (
IN MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
IN EFI_GUID *NameGuid
)
/*++
Routine Description:
Initialize a Firmware Volume (FV) Media Device Path node.
Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
so as we move to UEFI 2.0 support we must use a mechanism that conforms with
the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
device path is defined for PIWG extensions of device path. If the code
is compiled to conform with the UEFI 2.0 specification use the new device path
else use the old form for backwards compatability.
Arguments:
FvDevicePathNode - Pointer to a FV device path node to initialize
NameGuid - FV file name to use in FvDevicePathNode
Returns:
None
--*/
{
#if (EFI_SPECIFICATION_VERSION != 0x00020000)
//
// Use old Device Path
//
FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;
FvDevicePathNode->Header.SubType = MEDIA_FV_FILEPATH_DP;
SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
#else
//
// Use the new Device path that does not conflict with the UEFI 2.0
//
FvDevicePathNode->Piwg.Header.Type = MEDIA_DEVICE_PATH;
FvDevicePathNode->Piwg.Header.SubType = MEDIA_VENDOR_DP;
SetDevicePathNodeLength (&FvDevicePathNode->Piwg.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
//
// Add the GUID for generic PIWG device paths
//
EfiCopyMem (&FvDevicePathNode->Piwg.PiwgSpecificDevicePath, &gEfiFrameworkDevicePathGuid, sizeof(EFI_GUID));
//
// Add in the FW Vol File Path PIWG defined inforation
//
FvDevicePathNode->Piwg.Type = PIWG_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE;
#endif
EfiCopyMem (&FvDevicePathNode->NameGuid, NameGuid, sizeof(EFI_GUID));
}
EFI_GUID *
EFIAPI
EfiGetNameGuidFromFwVolDevicePathNode (
IN MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
)
/*++
Routine Description:
Check to see if the Firmware Volume (FV) Media Device Path is valid.
Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
so as we move to UEFI 2.0 support we must use a mechanism that conforms with
the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
device path is defined for PIWG extensions of device path. If the code
is compiled to conform with the UEFI 2.0 specification use the new device path
else use the old form for backwards compatability. The return value to this
function points to a location in FvDevicePathNode and it does not allocate
new memory for the GUID pointer that is returned.
Arguments:
FvDevicePathNode - Pointer to FV device path to check
Returns:
NULL - FvDevicePathNode is not valid.
Other - FvDevicePathNode is valid and pointer to NameGuid was returned.
--*/
{
#if (EFI_SPECIFICATION_VERSION != 0x00020000)
//
// Use old Device Path
//
if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH &&
DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_FV_FILEPATH_DP) {
return &FvDevicePathNode->NameGuid;
}
#else
//
// Use the new Device path that does not conflict with the UEFI 2.0
//
if (DevicePathType (&FvDevicePathNode->Piwg.Header) == MEDIA_DEVICE_PATH &&
DevicePathSubType (&FvDevicePathNode->Piwg.Header) == MEDIA_VENDOR_DP) {
if (EfiCompareGuid (&gEfiFrameworkDevicePathGuid, &FvDevicePathNode->Piwg.PiwgSpecificDevicePath)) {
if (FvDevicePathNode->Piwg.Type == PIWG_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE) {
return &FvDevicePathNode->NameGuid;
}
}
}
#endif
return NULL;
}

View File

@@ -0,0 +1,56 @@
/*++
Copyright (c) 2004, 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:
DxeDriverLib.c
Abstract:
Light weight lib to support EFI drivers.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_STATUS
DxeInitializeDriverLib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Intialize Driver Lib if it has not yet been initialized.
Arguments:
ImageHandle - Standard EFI Image entry parameter
SystemTable - Standard EFI Image entry parameter
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
{
EFI_STATUS Status;
Status = EfiInitializeDriverLib (ImageHandle, SystemTable);
if (!EFI_ERROR (Status)) {
Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);
}
return Status;
}

View File

@@ -0,0 +1,52 @@
/*++
Copyright (c) 2004, 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:
PerformancePrimitives.c
Abstract:
Support for Performance library
--*/
#include "Tiano.h" // for ASSERT macro
#include "TianoCommon.h"
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
)
/*++
Routine Description:
Set TimerValue to 0, which is not expected to be run.
Arguments:
TimerValue - Timer value for output
Returns:
EFI_SUCCESS - Should not be reached.
--*/
{
//
// Should not be used for EBC, so assert.
//
*TimerValue = 0;
ASSERT (FALSE);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,429 @@
/*++
Copyright (c) 2004 - 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:
EfiDriverLib.c
Abstract:
Light weight lib to support EFI drivers.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
//
// Global Interface for Debug Mask Protocol
//
EFI_DEBUG_MASK_PROTOCOL *gDebugMaskInterface = NULL;
EFI_STATUS
EfiInitializeDriverLib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Intialize Driver Lib if it has not yet been initialized.
Arguments:
ImageHandle - Standard EFI Image entry parameter
SystemTable - Standard EFI Image entry parameter
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
{
gST = SystemTable;
ASSERT (gST != NULL);
gBS = gST->BootServices;
gRT = gST->RuntimeServices;
ASSERT (gBS != NULL);
ASSERT (gRT != NULL);
//
// Get driver debug mask protocol interface
//
#ifdef EFI_DEBUG
gBS->HandleProtocol (
ImageHandle,
&gEfiDebugMaskProtocolGuid,
(VOID *) &gDebugMaskInterface
);
#endif
//
// Should be at EFI_D_INFO, but lets us know things are running
//
DEBUG ((EFI_D_INFO, "EfiInitializeDriverLib: Started\n"));
return EFI_SUCCESS;
}
BOOLEAN
EfiLibCompareLanguage (
IN CHAR8 *Language1,
IN CHAR8 *Language2
)
/*++
Routine Description:
Compare whether two names of languages are identical.
Arguments:
Language1 - Name of language 1
Language2 - Name of language 2
Returns:
TRUE - same
FALSE - not same
--*/
{
UINTN Index;
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
for (Index = 0; (Language1[Index] != 0) && (Language2[Index] != 0); Index++) {
if (Language1[Index] != Language2[Index]) {
return FALSE;
}
}
if (((Language1[Index] == 0) && (Language2[Index] == 0)) ||
((Language1[Index] == 0) && (Language2[Index] != ';')) ||
((Language1[Index] == ';') && (Language2[Index] != 0)) ||
((Language1[Index] == ';') && (Language2[Index] != ';'))) {
return TRUE;
}
return FALSE;
#else
for (Index = 0; Index < 3; Index++) {
if (Language1[Index] != Language2[Index]) {
return FALSE;
}
}
return TRUE;
#endif
}
STATIC
CHAR8 *
NextSupportedLanguage (
IN CHAR8 *Languages
)
{
#ifdef LANGUAGE_RFC_3066 // LANGUAGE_RFC_3066
for (; (*Languages != 0) && (*Languages != ';'); Languages++)
;
return Languages;
#else // LANGUAGE_ISO_639_2
return (Languages + 3);
#endif
}
EFI_STATUS
EfiLibLookupUnicodeString (
IN CHAR8 *Language,
IN CHAR8 *SupportedLanguages,
IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable,
OUT CHAR16 **UnicodeString
)
/*++
Routine Description:
Translate a unicode string to a specified language if supported.
Arguments:
Language - The name of language to translate to
SupportedLanguages - Supported languages set
UnicodeStringTable - Pointer of one item in translation dictionary
UnicodeString - The translated string
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_UNSUPPORTED - System not supported this language or this string translation
EFI_SUCCESS - String successfully translated
--*/
{
//
// Make sure the parameters are valid
//
if (Language == NULL || UnicodeString == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// If there are no supported languages, or the Unicode String Table is empty, then the
// Unicode String specified by Language is not supported by this Unicode String Table
//
if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure Language is in the set of Supported Languages
//
while (*SupportedLanguages != 0) {
if (EfiLibCompareLanguage (Language, SupportedLanguages)) {
//
// Search the Unicode String Table for the matching Language specifier
//
while (UnicodeStringTable->Language != NULL) {
if (EfiLibCompareLanguage (Language, UnicodeStringTable->Language)) {
//
// A matching string was found, so return it
//
*UnicodeString = UnicodeStringTable->UnicodeString;
return EFI_SUCCESS;
}
UnicodeStringTable++;
}
return EFI_UNSUPPORTED;
}
SupportedLanguages = NextSupportedLanguage(SupportedLanguages);
}
return EFI_UNSUPPORTED;
}
EFI_STATUS
EfiLibAddUnicodeString (
IN CHAR8 *Language,
IN CHAR8 *SupportedLanguages,
IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable,
IN CHAR16 *UnicodeString
)
/*++
Routine Description:
Add an translation to the dictionary if this language if supported.
Arguments:
Language - The name of language to translate to
SupportedLanguages - Supported languages set
UnicodeStringTable - Translation dictionary
UnicodeString - The corresponding string for the language to be translated to
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_UNSUPPORTED - System not supported this language
EFI_ALREADY_STARTED - Already has a translation item of this language
EFI_OUT_OF_RESOURCES - No enough buffer to be allocated
EFI_SUCCESS - String successfully translated
--*/
{
UINTN NumberOfEntries;
EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;
EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;
UINTN UnicodeStringLength;
//
// Make sure the parameter are valid
//
if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// If there are no supported languages, then a Unicode String can not be added
//
if (SupportedLanguages == NULL) {
return EFI_UNSUPPORTED;
}
//
// If the Unicode String is empty, then a Unicode String can not be added
//
if (UnicodeString[0] == 0) {
return EFI_INVALID_PARAMETER;
}
//
// Make sure Language is a member of SupportedLanguages
//
while (*SupportedLanguages != 0) {
if (EfiLibCompareLanguage (Language, SupportedLanguages)) {
//
// Determine the size of the Unicode String Table by looking for a NULL Language entry
//
NumberOfEntries = 0;
if (*UnicodeStringTable != NULL) {
OldUnicodeStringTable = *UnicodeStringTable;
while (OldUnicodeStringTable->Language != NULL) {
if (EfiLibCompareLanguage (Language, OldUnicodeStringTable->Language)) {
return EFI_ALREADY_STARTED;
}
OldUnicodeStringTable++;
NumberOfEntries++;
}
}
//
// Allocate space for a new Unicode String Table. It must hold the current number of
// entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table
// marker
//
NewUnicodeStringTable = EfiLibAllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));
if (NewUnicodeStringTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// If the current Unicode String Table contains any entries, then copy them to the
// newly allocated Unicode String Table.
//
if (*UnicodeStringTable != NULL) {
EfiCopyMem (
NewUnicodeStringTable,
*UnicodeStringTable,
NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)
);
}
//
// Allocate space for a copy of the Language specifier
//
NewUnicodeStringTable[NumberOfEntries].Language = EfiLibAllocateCopyPool (EfiAsciiStrLen(Language) + 1, Language);
if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {
gBS->FreePool (NewUnicodeStringTable);
return EFI_OUT_OF_RESOURCES;
}
//
// Compute the length of the Unicode String
//
for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)
;
//
// Allocate space for a copy of the Unicode String
//
NewUnicodeStringTable[NumberOfEntries].UnicodeString = EfiLibAllocateCopyPool (
(UnicodeStringLength + 1) * sizeof (CHAR16),
UnicodeString
);
if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {
gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);
gBS->FreePool (NewUnicodeStringTable);
return EFI_OUT_OF_RESOURCES;
}
//
// Mark the end of the Unicode String Table
//
NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;
NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;
//
// Free the old Unicode String Table
//
if (*UnicodeStringTable != NULL) {
gBS->FreePool (*UnicodeStringTable);
}
//
// Point UnicodeStringTable at the newly allocated Unicode String Table
//
*UnicodeStringTable = NewUnicodeStringTable;
return EFI_SUCCESS;
}
SupportedLanguages = NextSupportedLanguage(SupportedLanguages);
}
return EFI_UNSUPPORTED;
}
EFI_STATUS
EfiLibFreeUnicodeStringTable (
IN OUT EFI_UNICODE_STRING_TABLE *UnicodeStringTable
)
/*++
Routine Description:
Free a string table.
Arguments:
UnicodeStringTable - The string table to be freed.
Returns:
EFI_SUCCESS - The table successfully freed.
--*/
{
UINTN Index;
//
// If the Unicode String Table is NULL, then it is already freed
//
if (UnicodeStringTable == NULL) {
return EFI_SUCCESS;
}
//
// Loop through the Unicode String Table until we reach the end of table marker
//
for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {
//
// Free the Language string from the Unicode String Table
//
gBS->FreePool (UnicodeStringTable[Index].Language);
//
// Free the Unicode String from the Unicode String Table
//
if (UnicodeStringTable[Index].UnicodeString != NULL) {
gBS->FreePool (UnicodeStringTable[Index].UnicodeString);
}
}
//
// Free the Unicode String Table itself
//
gBS->FreePool (UnicodeStringTable);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,88 @@
#/*++
#
# Copyright (c) 2004 - 2006, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# EfiDriverLib.inf
#
# Abstract:
#
# Component description file for the EFI driver library.
#
#--*/
[defines]
BASE_NAME = EfiDriverLib
COMPONENT_TYPE = LIBRARY
[sources.common]
Debug.c
DevicePath.c
EfiDriverLib.c
DxeDriverLib.c
EfiGetConfigTable.c
EfiDriverModelLib.c
Event.c
Handle.c
LibGlobalSt.c
LibGlobalDs.c
LibGlobalErrorLevel.c
Lock.c
EfiLibAllocate.c
Perf.c
ReportStatusCode.c
GetImage.c
..\hob\hob.c
[sources.ia32]
ia32\PerformancePrimitives.c
[sources.x64]
x64\PerformancePrimitives.c
[sources.ipf]
ipf\PerformancePrimitives.s
[sources.ebc]
Ebc\PerformancePrimitives.c
[includes.common]
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation\Efi
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Core\Dxe
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Cpu\Pentium\Include
[libraries.common]
EdkGuidLib
EdkProtocolLib
EdkFrameworkProtocolLib
EfiGuidLib
EfiProtocolLib
ArchProtocolLib
EfiCommonLib
[libraries.ia32]
CpuIA32Lib
[libraries.x64]
CpuIA32Lib
[libraries.ipf]
CpuIA64Lib
[nmake.common]

View File

@@ -0,0 +1,289 @@
/*++
Copyright (c) 2004 - 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:
EfiDriverModelLib.c
Abstract:
Light weight lib to support EFI drivers.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_STATUS
EfiLibInstallDriverBinding (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,
IN EFI_HANDLE DriverBindingHandle
)
/*++
Routine Description:
Intialize a driver by installing the Driver Binding Protocol onto the
driver's DriverBindingHandle. This is typically the same as the driver's
ImageHandle, but it can be different if the driver produces multiple
DriverBinding Protocols. This function also initializes the EFI Driver
Library that initializes the global variables gST, gBS, gRT.
Arguments:
ImageHandle - The image handle of the driver
SystemTable - The EFI System Table that was passed to the driver's entry point
DriverBinding - A Driver Binding Protocol instance that this driver is producing
DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
parameter is NULL, then a new handle is created.
Returns:
EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle
Otherwise, then return status from gBS->InstallProtocolInterface()
--*/
{
EfiInitializeDriverLib (ImageHandle, SystemTable);
DriverBinding->ImageHandle = ImageHandle;
DriverBinding->DriverBindingHandle = DriverBindingHandle;
return gBS->InstallProtocolInterface (
&DriverBinding->DriverBindingHandle,
&gEfiDriverBindingProtocolGuid,
EFI_NATIVE_INTERFACE,
DriverBinding
);
}
EFI_STATUS
EfiLibInstallAllDriverProtocols (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE * SystemTable,
IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,
IN EFI_HANDLE DriverBindingHandle,
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName, OPTIONAL
#else
IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL
#endif
IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL
IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics OPTIONAL
)
/*++
Routine Description:
Intialize a driver by installing the Driver Binding Protocol onto the
driver's DriverBindingHandle. This is typically the same as the driver's
ImageHandle, but it can be different if the driver produces multiple
DriverBinding Protocols. This function also initializes the EFI Driver
Library that initializes the global variables gST, gBS, gRT.
Arguments:
ImageHandle - The image handle of the driver
SystemTable - The EFI System Table that was passed to the driver's entry point
DriverBinding - A Driver Binding Protocol instance that this driver is producing
DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
parameter is NULL, then a new handle is created.
ComponentName - A Component Name Protocol instance that this driver is producing
DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
Returns:
EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
Otherwise, then return status from gBS->InstallProtocolInterface()
--*/
{
EFI_STATUS Status;
Status = EfiLibInstallDriverBinding (ImageHandle, SystemTable, DriverBinding, DriverBindingHandle);
if (EFI_ERROR (Status)) {
return Status;
}
if (ComponentName != NULL) {
Status = gBS->InstallProtocolInterface (
&DriverBinding->DriverBindingHandle,
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
&gEfiComponentName2ProtocolGuid,
#else
&gEfiComponentNameProtocolGuid,
#endif
EFI_NATIVE_INTERFACE,
ComponentName
);
if (EFI_ERROR (Status)) {
return Status;
}
}
if (DriverConfiguration != NULL) {
Status = gBS->InstallProtocolInterface (
&DriverBinding->DriverBindingHandle,
&gEfiDriverConfigurationProtocolGuid,
EFI_NATIVE_INTERFACE,
DriverConfiguration
);
if (EFI_ERROR (Status)) {
return Status;
}
}
if (DriverDiagnostics != NULL) {
Status = gBS->InstallProtocolInterface (
&DriverBinding->DriverBindingHandle,
&gEfiDriverDiagnosticsProtocolGuid,
EFI_NATIVE_INTERFACE,
DriverDiagnostics
);
if (EFI_ERROR (Status)) {
return Status;
}
}
return EFI_SUCCESS;
}
EFI_STATUS
EfiLibTestManagedDevice (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE DriverBindingHandle,
IN EFI_GUID *ManagedProtocolGuid
)
/*++
Routine Description:
Test to see if the controller is managed by a specific driver.
Arguments:
ControllerHandle - Handle for controller to test
DriverBindingHandle - Driver binding handle for controller
ManagedProtocolGuid - The protocol guid the driver opens on controller
Returns:
EFI_SUCCESS - The controller is managed by the driver
EFI_UNSUPPORTED - The controller is not managed by the driver
--*/
{
EFI_STATUS Status;
VOID *ManagedInterface;
Status = gBS->OpenProtocol (
ControllerHandle,
ManagedProtocolGuid,
&ManagedInterface,
DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
ManagedProtocolGuid,
DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status != EFI_ALREADY_STARTED) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
EFI_STATUS
EfiLibTestChildHandle (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle,
IN EFI_GUID *ConsumedGuid
)
/*++
Routine Description:
Test to see if the child handle is the child of the controller
Arguments:
ControllerHandle - Handle for controller (parent)
ChildHandle - Child handle to test
ConsumsedGuid - Protocol guid consumed by child from controller
Returns:
EFI_SUCCESS - The child handle is the child of the controller
EFI_UNSUPPORTED - The child handle is not the child of the controller
--*/
{
EFI_STATUS Status;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
UINTN EntryCount;
UINTN Index;
//
// Retrieve the list of agents that are consuming one of the protocols
// on ControllerHandle that the children consume
//
Status = gBS->OpenProtocolInformation (
ControllerHandle,
ConsumedGuid,
&OpenInfoBuffer,
&EntryCount
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// See if one of the agents is ChildHandle
//
Status = EFI_UNSUPPORTED;
for (Index = 0; Index < EntryCount; Index++) {
if (OpenInfoBuffer[Index].ControllerHandle == ChildHandle &&
OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
Status = EFI_SUCCESS;
}
}
gBS->FreePool (OpenInfoBuffer);
return Status;
}

View File

@@ -0,0 +1,61 @@
/*++
Copyright (c) 2004 - 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:
EfiGetConfigTable.c
Abstract:
Light weight lib to support EFI drivers.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_STATUS
EfiLibGetSystemConfigurationTable (
IN EFI_GUID *TableGuid,
OUT VOID **Table
)
/*++
Routine Description:
Get table from configuration table by name
Arguments:
TableGuid - Table name to search
Table - Pointer to the table caller wants
Returns:
EFI_NOT_FOUND - Not found the table
EFI_SUCCESS - Found the table
--*/
{
UINTN Index;
*Table = NULL;
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
if (EfiCompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {
*Table = gST->ConfigurationTable[Index].VendorTable;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}

View File

@@ -0,0 +1,233 @@
/*++
Copyright (c) 2004 - 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:
EfiLibAllocate.c
Abstract:
Support routines for memory allocation routines for use with drivers.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
VOID *
EfiLibAllocatePool (
IN UINTN AllocationSize
)
/*++
Routine Description:
Allocate BootServicesData pool.
Arguments:
AllocationSize - The size to allocate
Returns:
Pointer of the buffer allocated.
--*/
{
VOID *Memory;
Memory = NULL;
gBS->AllocatePool (EfiBootServicesData, AllocationSize, &Memory);
return Memory;
}
VOID *
EfiLibAllocateRuntimePool (
IN UINTN AllocationSize
)
/*++
Routine Description:
Allocate RuntimeServicesData pool.
Arguments:
AllocationSize - The size to allocate
Returns:
Pointer of the buffer allocated.
--*/
{
VOID *Memory;
Memory = NULL;
gBS->AllocatePool (EfiRuntimeServicesData, AllocationSize, &Memory);
return Memory;
}
VOID *
EfiLibAllocateZeroPool (
IN UINTN AllocationSize
)
/*++
Routine Description:
Allocate BootServicesData pool and zero it.
Arguments:
AllocationSize - The size to allocate
Returns:
Pointer of the buffer allocated.
--*/
{
VOID *Memory;
Memory = EfiLibAllocatePool (AllocationSize);
if (Memory != NULL) {
gBS->SetMem (Memory, AllocationSize, 0);
}
return Memory;
}
VOID *
EfiLibAllocateRuntimeZeroPool (
IN UINTN AllocationSize
)
/*++
Routine Description:
Allocate RuntimeServicesData pool and zero it.
Arguments:
AllocationSize - The size to allocate
Returns:
Pointer of the buffer allocated.
--*/
{
VOID *Memory;
Memory = EfiLibAllocateRuntimePool (AllocationSize);
if (Memory != NULL) {
gBS->SetMem (Memory, AllocationSize, 0);
}
return Memory;
}
VOID *
EfiLibAllocateCopyPool (
IN UINTN AllocationSize,
IN VOID *Buffer
)
/*++
Routine Description:
Allocate BootServicesData pool and use a buffer provided by
caller to fill it.
Arguments:
AllocationSize - The size to allocate
Buffer - Buffer that will be filled into the buffer allocated
Returns:
Pointer of the buffer allocated.
--*/
{
VOID *Memory;
Memory = NULL;
gBS->AllocatePool (EfiBootServicesData, AllocationSize, &Memory);
if (Memory != NULL) {
gBS->CopyMem (Memory, Buffer, AllocationSize);
}
return Memory;
}
VOID *
EfiLibAllocateRuntimeCopyPool (
IN UINTN AllocationSize,
IN VOID *Buffer
)
/*++
Routine Description:
Allocate RuntimeServicesData pool and use a buffer provided by
caller to fill it.
Arguments:
AllocationSize - The size to allocate
Buffer - Buffer that will be filled into the buffer allocated
Returns:
Pointer of the buffer allocated.
--*/
{
VOID *Memory;
Memory = NULL;
gBS->AllocatePool (EfiRuntimeServicesData, AllocationSize, &Memory);
if (Memory != NULL) {
gBS->CopyMem (Memory, Buffer, AllocationSize);
}
return Memory;
}
VOID
EfiLibSafeFreePool (
IN VOID *Buffer
)
/*++
Routine Description:
Free pool safely (without setting back Buffer to NULL).
Arguments:
Buffer - The allocated pool entry to free
Returns:
Pointer of the buffer allocated.
--*/
{
if (Buffer != NULL) {
gBS->FreePool (Buffer);
}
}

View File

@@ -0,0 +1,371 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Event.c
Abstract:
Support for Event lib fucntions.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_EVENT
EfiLibCreateProtocolNotifyEvent (
IN EFI_GUID *ProtocolGuid,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT VOID **Registration
)
/*++
Routine Description:
Create a protocol notification event and return it.
Arguments:
ProtocolGuid - Protocol to register notification event on.
NotifyTpl - Maximum TPL to single the NotifyFunction.
NotifyFunction - EFI notification routine.
NotifyContext - Context passed into Event when it is created.
Registration - Registration key returned from RegisterProtocolNotify().
Returns:
The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
is added to the system.
--*/
{
EFI_STATUS Status;
EFI_EVENT Event;
//
// Create the event
//
Status = gBS->CreateEvent (
EFI_EVENT_NOTIFY_SIGNAL,
NotifyTpl,
NotifyFunction,
NotifyContext,
&Event
);
ASSERT (!EFI_ERROR (Status));
//
// Register for protocol notifactions on this event
//
Status = gBS->RegisterProtocolNotify (
ProtocolGuid,
Event,
Registration
);
ASSERT (!EFI_ERROR (Status));
//
// Kick the event so we will perform an initial pass of
// current installed drivers
//
gBS->SignalEvent (Event);
return Event;
}
EFI_STATUS
EfiLibNamedEventListen (
IN EFI_GUID * Name,
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext
)
/*++
Routine Description:
Listenes to signals on the name.
EfiLibNamedEventSignal() signals the event.
NOTE: For now, the named listening/signalling is implemented
on a protocol interface being installed and uninstalled.
In the future, this maybe implemented based on a dedicated mechanism.
Arguments:
Name - Name to register the listener on.
NotifyTpl - Maximum TPL to singnal the NotifyFunction.
NotifyFunction - The listener routine.
NotifyContext - Context passed into the listener routine.
Returns:
EFI_SUCCESS if successful.
--*/
{
EFI_STATUS Status;
EFI_EVENT Event;
VOID *RegistrationLocal;
//
// Create event
//
Status = gBS->CreateEvent (
EFI_EVENT_NOTIFY_SIGNAL,
NotifyTpl,
NotifyFunction,
NotifyContext,
&Event
);
ASSERT_EFI_ERROR (Status);
Status = gBS->RegisterProtocolNotify (
Name,
Event,
&RegistrationLocal
);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}
EFI_STATUS
EfiLibNamedEventSignal (
IN EFI_GUID *Name
)
/*++
Routine Description:
Signals a named event. All registered listeners will run.
The listeners should register using EfiLibNamedEventListen() function.
NOTE: For now, the named listening/signalling is implemented
on a protocol interface being installed and uninstalled.
In the future, this maybe implemented based on a dedicated mechanism.
Arguments:
Name - Name to perform the signaling on. The name is a GUID.
Returns:
EFI_SUCCESS if successfull.
--*/
{
EFI_STATUS Status;
EFI_HANDLE Handle;
Handle = NULL;
Status = gBS->InstallProtocolInterface (
&Handle,
Name,
EFI_NATIVE_INTERFACE,
NULL
);
ASSERT_EFI_ERROR (Status);
Status = gBS->UninstallProtocolInterface (
Handle,
Name,
NULL
);
ASSERT_EFI_ERROR (Status);
return EFI_SUCCESS;
}
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
static
VOID
EFIAPI
EventNotifySignalAllNullEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
{
//
// This null event is a size efficent way to enusre that
// EFI_EVENT_NOTIFY_SIGNAL_ALL is error checked correctly.
// EFI_EVENT_NOTIFY_SIGNAL_ALL is now mapped into
// CreateEventEx() and this function is used to make the
// old error checking in CreateEvent() for Tiano extensions
// function.
//
return;
}
#endif
EFI_STATUS
EFIAPI
EfiCreateEventLegacyBoot (
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT EFI_EVENT *LegacyBootEvent
)
/*++
Routine Description:
Create a Legacy Boot Event.
Tiano extended the CreateEvent Type enum to add a legacy boot event type.
This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
added and now it's possible to not voilate the UEFI specification by
declaring a GUID for the legacy boot event class. This library supports
the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
work both ways.
Arguments:
LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
Returns:
EFI_SUCCESS Event was created.
Other Event was not created.
--*/
{
EFI_STATUS Status;
UINT32 EventType;
EFI_EVENT_NOTIFY WorkerNotifyFunction;
#if (EFI_SPECIFICATION_VERSION < 0x00020000)
if (NotifyFunction == NULL) {
EventType = EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL;
} else {
EventType = EFI_EVENT_SIGNAL_LEGACY_BOOT;
}
WorkerNotifyFunction = NotifyFunction;
//
// prior to UEFI 2.0 use Tiano extension to EFI
//
Status = gBS->CreateEvent (
EventType,
NotifyTpl,
WorkerNotifyFunction,
NotifyContext,
LegacyBootEvent
);
#else
EventType = EFI_EVENT_NOTIFY_SIGNAL;
if (NotifyFunction == NULL) {
//
// CreatEventEx will check NotifyFunction is NULL or not
//
WorkerNotifyFunction = EventNotifySignalAllNullEvent;
} else {
WorkerNotifyFunction = NotifyFunction;
}
//
// For UEFI 2.0 and the future use an Event Group
//
Status = gBS->CreateEventEx (
EventType,
NotifyTpl,
WorkerNotifyFunction,
NotifyContext,
&gEfiEventLegacyBootGuid,
LegacyBootEvent
);
#endif
return Status;
}
EFI_STATUS
EFIAPI
EfiCreateEventReadyToBoot (
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT EFI_EVENT *ReadyToBootEvent
)
/*++
Routine Description:
Create a Read to Boot Event.
Tiano extended the CreateEvent Type enum to add a ready to boot event type.
This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
added and now it's possible to not voilate the UEFI specification and use
the ready to boot event class defined in UEFI 2.0. This library supports
the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
work both ways.
Arguments:
@param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
Return:
EFI_SUCCESS - Event was created.
Other - Event was not created.
--*/
{
EFI_STATUS Status;
UINT32 EventType;
EFI_EVENT_NOTIFY WorkerNotifyFunction;
#if (EFI_SPECIFICATION_VERSION < 0x00020000)
if (NotifyFunction == NULL) {
EventType = EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL;
} else {
EventType = EFI_EVENT_SIGNAL_READY_TO_BOOT;
}
WorkerNotifyFunction = NotifyFunction;
//
// prior to UEFI 2.0 use Tiano extension to EFI
//
Status = gBS->CreateEvent (
EventType,
NotifyTpl,
WorkerNotifyFunction,
NotifyContext,
ReadyToBootEvent
);
#else
EventType = EFI_EVENT_NOTIFY_SIGNAL;
if (NotifyFunction == NULL) {
//
// CreatEventEx will check NotifyFunction is NULL or not
//
WorkerNotifyFunction = EventNotifySignalAllNullEvent;
} else {
WorkerNotifyFunction = NotifyFunction;
}
//
// For UEFI 2.0 and the future use an Event Group
//
Status = gBS->CreateEventEx (
EventType,
NotifyTpl,
WorkerNotifyFunction,
NotifyContext,
&gEfiEventReadyToBootGuid,
ReadyToBootEvent
);
#endif
return Status;
}

View File

@@ -0,0 +1,220 @@
/*++
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:
GetImage.c
Abstract:
Image data extraction support for common use.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "EfiImageFormat.h"
#include EFI_PROTOCOL_CONSUMER (LoadedImage)
EFI_STATUS
GetImageFromFv (
#if (PI_SPECIFICATION_VERSION < 0x00010000)
IN EFI_FIRMWARE_VOLUME_PROTOCOL *Fv,
#else
IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,
#endif
IN EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
OUT VOID **Buffer,
OUT UINTN *Size
)
{
EFI_STATUS Status;
EFI_FV_FILETYPE FileType;
EFI_FV_FILE_ATTRIBUTES Attributes;
UINT32 AuthenticationStatus;
//
// Read desired section content in NameGuid file
//
*Buffer = NULL;
*Size = 0;
Status = Fv->ReadSection (
Fv,
NameGuid,
SectionType,
0,
Buffer,
Size,
&AuthenticationStatus
);
if (EFI_ERROR (Status) && (SectionType == EFI_SECTION_TE)) {
//
// Try reading PE32 section, since the TE section does not exist
//
*Buffer = NULL;
*Size = 0;
Status = Fv->ReadSection (
Fv,
NameGuid,
EFI_SECTION_PE32,
0,
Buffer,
Size,
&AuthenticationStatus
);
}
if (EFI_ERROR (Status) &&
((SectionType == EFI_SECTION_TE) || (SectionType == EFI_SECTION_PE32))) {
//
// Try reading raw file, since the desired section does not exist
//
*Buffer = NULL;
*Size = 0;
Status = Fv->ReadFile (
Fv,
NameGuid,
Buffer,
Size,
&FileType,
&Attributes,
&AuthenticationStatus
);
}
return Status;
}
EFI_STATUS
GetImage (
IN EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
OUT VOID **Buffer,
OUT UINTN *Size
)
{
return GetImageEx (NULL, NameGuid, SectionType, Buffer, Size, FALSE);
}
EFI_STATUS
GetImageEx (
IN EFI_HANDLE ImageHandle,
IN EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
OUT VOID **Buffer,
OUT UINTN *Size,
BOOLEAN WithinImageFv
)
{
EFI_STATUS Status;
EFI_HANDLE *HandleBuffer;
UINTN HandleCount;
UINTN Index;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
#if (PI_SPECIFICATION_VERSION < 0x00010000)
EFI_FIRMWARE_VOLUME_PROTOCOL *ImageFv;
EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
#else
EFI_FIRMWARE_VOLUME2_PROTOCOL *ImageFv;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
#endif
if (ImageHandle == NULL && WithinImageFv) {
return EFI_INVALID_PARAMETER;
}
Status = EFI_NOT_FOUND;
ImageFv = NULL;
if (ImageHandle != NULL) {
Status = gBS->HandleProtocol (
ImageHandle,
&gEfiLoadedImageProtocolGuid,
&LoadedImage
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->HandleProtocol (
LoadedImage->DeviceHandle,
#if (PI_SPECIFICATION_VERSION < 0x00010000)
&gEfiFirmwareVolumeProtocolGuid,
#else
&gEfiFirmwareVolume2ProtocolGuid,
#endif
&ImageFv
);
if (!EFI_ERROR (Status)) {
Status = GetImageFromFv (ImageFv, NameGuid, SectionType, Buffer, Size);
}
}
if (Status == EFI_SUCCESS || WithinImageFv) {
return Status;
}
Status = gBS->LocateHandleBuffer (
ByProtocol,
#if (PI_SPECIFICATION_VERSION < 0x00010000)
&gEfiFirmwareVolumeProtocolGuid,
#else
&gEfiFirmwareVolume2ProtocolGuid,
#endif
NULL,
&HandleCount,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Find desired image in all Fvs
//
for (Index = 0; Index < HandleCount; ++Index) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
#if (PI_SPECIFICATION_VERSION < 0x00010000)
&gEfiFirmwareVolumeProtocolGuid,
#else
&gEfiFirmwareVolume2ProtocolGuid,
#endif
(VOID**)&Fv
);
if (EFI_ERROR (Status)) {
gBS->FreePool(HandleBuffer);
return Status;
}
if (ImageFv != NULL && Fv == ImageFv) {
continue;
}
Status = GetImageFromFv (Fv, NameGuid, SectionType, Buffer, Size);
if (!EFI_ERROR (Status)) {
break;
}
}
gBS->FreePool(HandleBuffer);
//
// Not found image
//
if (Index == HandleCount) {
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,176 @@
/*++
Copyright (c) 2004, 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:
Handle.c
Abstract:
Support for Handle lib fucntions.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_STATUS
EfiLibLocateHandleProtocolByProtocols (
IN OUT EFI_HANDLE * Handle, OPTIONAL
OUT VOID **Interface, OPTIONAL
...
)
/*++
Routine Description:
Function locates Protocol and/or Handle on which all Protocols specified
as a variable list are installed.
It supports continued search. The caller must assure that no handles are added
or removed while performing continued search, by e.g., rising the TPL and not
calling any handle routines. Otherwise the behavior is undefined.
Arguments:
Handle - The address of handle to receive the handle on which protocols
indicated by the variable list are installed.
If points to NULL, all handles are searched. If pointing to a
handle returned from previous call, searches starting from next handle.
If NULL, the parameter is ignored.
Interface - The address of a pointer to a protocol interface that will receive
the interface indicated by first variable argument.
If NULL, the parameter is ignored.
... - A variable argument list containing protocol GUIDs. Must end with NULL.
Returns:
EFI_SUCCESS - All the protocols where found on same handle.
EFI_NOT_FOUND - A Handle with all the protocols installed was not found.
Other values as may be returned from LocateHandleBuffer() or HandleProtocol().
--*/
{
VA_LIST args;
EFI_STATUS Status;
EFI_GUID *Protocol;
EFI_GUID *ProtocolFirst;
EFI_HANDLE *HandleBuffer;
UINTN NumberOfHandles;
UINTN Idx;
VOID *AnInterface;
AnInterface = NULL;
VA_START (args, Interface);
ProtocolFirst = VA_ARG (args, EFI_GUID *);
//
// Get list of all handles that support the first protocol.
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
ProtocolFirst,
NULL,
&NumberOfHandles,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Check if this is a countinuation of handle searching.
//
Idx = 0;
if ((Handle != NULL) && (*Handle != NULL)) {
//
// Leave the Idx just beyond the matching handle.
//
for (; Idx < NumberOfHandles;) {
if (*Handle == HandleBuffer[Idx++]) {
break;
}
}
}
//
// Iterate handles testing for presence of remaining protocols.
//
for (; Idx < NumberOfHandles; Idx++) {
//
// Start with the second protocol, the first one is sure on this handle.
//
VA_START (args, Interface);
VA_ARG (args, EFI_GUID *);
//
// Iterate protocols from the variable list.
//
while (TRUE) {
Protocol = VA_ARG (args, EFI_GUID *);
if (Protocol == NULL) {
//
// If here, the list was iterated successfully
// finding each protocol on a single handle.
//
Status = EFI_SUCCESS;
//
// OPTIONAL parameter returning the Handle.
//
if (Handle != NULL) {
*Handle = HandleBuffer[Idx];
}
//
// OPTIONAL parameter returning the first rotocol's Interface.
//
if (Interface != NULL) {
Status = gBS->HandleProtocol (
HandleBuffer[Idx],
ProtocolFirst,
Interface
);
}
goto lbl_out;
}
Status = gBS->HandleProtocol (
HandleBuffer[Idx],
Protocol,
&AnInterface
);
if (EFI_ERROR (Status)) {
//
// This handle does not have the iterated protocol.
//
break;
}
}
}
//
// If here, no handle that bears all the protocols was found.
//
Status = EFI_NOT_FOUND;
lbl_out:
gBS->FreePool (HandleBuffer);
return Status;
}

View File

@@ -0,0 +1,61 @@
//++
// Copyright (c) 2004, 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:
//
// PerformancePrimitives.s
//
// Abstract:
//
//
// Revision History:
//
//--
.file "PerformancePrimitives.s"
#include "IpfMacro.i"
//-----------------------------------------------------------------------------
//++
// GetTimerValue
//
// Implementation of CPU-based time service
//
// On Entry :
// EFI_STATUS
// GetTimerValue (
// OUT UINT64 *TimerValue
// )
//
// Return Value:
// r8 = Status
// r9 = 0
// r10 = 0
// r11 = 0
//
// As per static calling conventions.
//
//--
//---------------------------------------------------------------------------
PROCEDURE_ENTRY (GetTimerValue)
NESTED_SETUP (1,8,0,0)
mov r8 = ar.itc;;
st8 [r32]= r8
mov r8 = r0
mov r9 = r0
mov r10 = r0
mov r11 = r0
NESTED_RETURN
PROCEDURE_EXIT (GetTimerValue)
//---------------------------------------------------------------------------

View File

@@ -0,0 +1,32 @@
/*++
Copyright (c) 2004, 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:
LibGlobalDs.c
Abstract:
Globals used in EFI Driver Lib. They are initialized in EfiDriverLib.c.
Each seperatly linked module has it's own copy of these globals.
gBS - Boot Services table pointer
gRT - Runt Time services table pointer
gST - System Table pointer
gErrorLevel - Debug error level.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_DXE_SERVICES *gDS = NULL;

View File

@@ -0,0 +1,34 @@
/*++
Copyright (c) 2004, 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:
LibGlobalErrorLevel.c
Abstract:
Globals used in EFI Driver Lib. They are initialized in EfiDriverLib.c.
Each seperatly linked module has it's own copy of these globals.
gBS - Boot Services table pointer
gRT - Runt Time services table pointer
gST - System Table pointer
gErrorLevel - Debug error level.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include EFI_GUID_DEFINITION (StatusCodeCallerId)
#include EFI_GUID_DEFINITION (StatusCodeDataTypeId)
UINTN gErrorLevel = EFI_DBUG_MASK | EFI_D_LOAD;

View File

@@ -0,0 +1,34 @@
/*++
Copyright (c) 2004, 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:
LibGlobalSt.c
Abstract:
Globals used in EFI Driver Lib. They are initialized in EfiDriverLib.c.
Each seperatly linked module has it's own copy of these globals.
gBS - Boot Services table pointer
gRT - Runt Time services table pointer
gST - System Table pointer
gErrorLevel - Debug error level.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
EFI_SYSTEM_TABLE *gST = NULL;
EFI_BOOT_SERVICES *gBS = NULL;
EFI_RUNTIME_SERVICES *gRT = NULL;

View File

@@ -0,0 +1,159 @@
/*++
Copyright (c) 2004, 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:
Lock.c
Abstract:
Support for locking lib services.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
VOID
EfiInitializeLock (
IN OUT EFI_LOCK *Lock,
IN EFI_TPL Priority
)
/*++
Routine Description:
Initialize a basic mutual exclusion lock. Each lock
provides mutual exclusion access at it's task priority
level. Since there is no-premption (at any TPL) or
multiprocessor support, acquiring the lock only consists
of raising to the locks TPL.
Note on a check build ASSERT()s are used to ensure proper
lock usage.
Arguments:
Lock - The EFI_LOCK structure to initialize
Priority - The task priority level of the lock
Returns:
An initialized Efi Lock structure.
--*/
{
Lock->Tpl = Priority;
Lock->OwnerTpl = 0;
Lock->Lock = 0;
}
EFI_STATUS
EfiAcquireLockOrFail (
IN EFI_LOCK *Lock
)
/*++
Routine Description:
Initialize a basic mutual exclusion lock. Each lock
provides mutual exclusion access at it's task priority
level. Since there is no-premption (at any TPL) or
multiprocessor support, acquiring the lock only consists
of raising to the locks TPL.
Arguments:
Lock - The EFI_LOCK structure to initialize
Returns:
EFI_SUCCESS - Lock Owned.
EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
--*/
{
if (Lock->Lock != 0) {
//
// Lock is already owned, so bail out
//
return EFI_ACCESS_DENIED;
}
Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);
Lock->Lock += 1;
return EFI_SUCCESS;
}
VOID
EfiAcquireLock (
IN EFI_LOCK *Lock
)
/*++
Routine Description:
Raising to the task priority level of the mutual exclusion
lock, and then acquires ownership of the lock.
Arguments:
Lock - The lock to acquire
Returns:
Lock owned
--*/
{
EFI_STATUS Status;
Status = EfiAcquireLockOrFail (Lock);
//
// Lock was already locked.
//
ASSERT_EFI_ERROR (Status);
}
VOID
EfiReleaseLock (
IN EFI_LOCK *Lock
)
/*++
Routine Description:
Releases ownership of the mutual exclusion lock, and
restores the previous task priority level.
Arguments:
Lock - The lock to release
Returns:
Lock unowned
--*/
{
EFI_TPL Tpl;
Tpl = Lock->OwnerTpl;
ASSERT (Lock->Lock == 1);
Lock->Lock -= 1;
gBS->RestoreTPL (Tpl);
}

View File

@@ -0,0 +1,861 @@
/*++
Copyright (c) 2004 - 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Perf.c
Abstract:
Support for Performance primatives.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include EFI_PROTOCOL_DEFINITION (Performance)
#include EFI_PROTOCOL_DEFINITION (LoadedImage)
#include EFI_GUID_DEFINITION (Hob)
#include EFI_GUID_DEFINITION (PeiPerformanceHob)
#include "linkedlist.h"
#include "EfiHobLib.h"
#include "EfiImage.h"
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
);
EFI_STATUS
GetPeiPerformance (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
IN UINT64 Ticker
);
#define EFI_PERFORMANCE_DATA_SIGNATURE EFI_SIGNATURE_32 ('P', 'E', 'D', 'A')
typedef struct {
UINT32 Signature;
EFI_LIST_ENTRY Link;
EFI_GAUGE_DATA GaugeData;
} EFI_PERF_DATA_LIST;
#define GAUGE_DATA_FROM_LINK(_link) \
CR(_link, EFI_PERF_DATA_LIST, Link, EFI_PERFORMANCE_DATA_SIGNATURE)
#define GAUGE_DATA_FROM_GAUGE(_GaugeData) \
CR(_GaugeData, EFI_PERF_DATA_LIST, GaugeData, EFI_PERFORMANCE_DATA_SIGNATURE)
#define EFI_PERFORMANCE_SIGNATURE EFI_SIGNATURE_32 ('P', 'E', 'R', 'F')
//
// Performance protocol instance data structure
//
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_PERFORMANCE_PROTOCOL Perf;
UINT8 Phase;
} EFI_PERFORMANCE_INSTANCE;
//
// Performace protocol instance containing record macro
//
#define EFI_PERFORMANCE_FROM_THIS(a) \
CR(a, EFI_PERFORMANCE_INSTANCE, Perf, EFI_PERFORMANCE_SIGNATURE)
EFI_LIST_ENTRY mPerfDataHead = INITIALIZE_LIST_HEAD_VARIABLE(mPerfDataHead);
STATIC
VOID
GetShortPdbFileName (
CHAR8 *PdbFileName,
CHAR8 *GaugeString
)
/*++
Routine Description:
Arguments:
Returns:
--*/
{
UINTN Index;
UINTN Index1;
UINTN StartIndex;
UINTN EndIndex;
if (PdbFileName == NULL) {
EfiAsciiStrCpy (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 == EFI_PERF_PDBFILENAME_LENGTH - 1) {
break;
}
}
GaugeString[Index1] = 0;
}
return ;
}
STATIC
CHAR8 *
GetPdbPath (
VOID *ImageBase
)
/*++
Routine Description:
Located PDB path name in PE image
Arguments:
ImageBase - base of PE to search
Returns:
Pointer into image at offset of PDB file name if PDB file name is found,
Otherwise a pointer to an empty string.
--*/
{
CHAR8 *PdbPath;
UINT32 DirCount;
EFI_IMAGE_DOS_HEADER *DosHdr;
EFI_IMAGE_NT_HEADERS *NtHdr;
UINT16 Magic;
EFI_IMAGE_OPTIONAL_HEADER32 *OptionalHdr32;
EFI_IMAGE_OPTIONAL_HEADER64 *OptionalHdr64;
EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
VOID *CodeViewEntryPointer;
CodeViewEntryPointer = NULL;
PdbPath = NULL;
DosHdr = ImageBase;
if (DosHdr && DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
NtHdr = (EFI_IMAGE_NT_HEADERS *) ((UINT8 *) DosHdr + DosHdr->e_lfanew);
//
// NOTE: We use Machine to identify PE32/PE32+, instead of Magic.
// It is for backward-compatibility consideration, because
// some system will generate PE32+ image with PE32 Magic.
//
if (NtHdr->FileHeader.Machine == EFI_IMAGE_MACHINE_IA32) {
Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
} else if (NtHdr->FileHeader.Machine == EFI_IMAGE_MACHINE_IA64) {
Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
} else if (NtHdr->FileHeader.Machine == EFI_IMAGE_MACHINE_X64) {
Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
} else {
Magic = NtHdr->OptionalHeader.Magic;
}
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
OptionalHdr32 = (VOID *) &NtHdr->OptionalHeader;
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHdr32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
} else {
OptionalHdr64 = (VOID *) &NtHdr->OptionalHeader;
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHdr64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
}
if (DirectoryEntry->VirtualAddress != 0) {
for (DirCount = 0;
(DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && CodeViewEntryPointer == NULL;
DirCount++
) {
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (DirectoryEntry->VirtualAddress + (UINTN) ImageBase + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageBase);
switch (*(UINT32 *) CodeViewEntryPointer) {
case CODEVIEW_SIGNATURE_NB10:
PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);
break;
case CODEVIEW_SIGNATURE_RSDS:
PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);
break;
default:
break;
}
}
}
}
}
return PdbPath;
}
STATIC
VOID
GetNameFromHandle (
IN EFI_HANDLE Handle,
OUT CHAR8 *GaugeString
)
{
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *Image;
CHAR8 *PdbFileName;
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
EfiAsciiStrCpy (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 = GetPdbPath (Image->ImageBase);
if (PdbFileName != NULL) {
GetShortPdbFileName (PdbFileName, GaugeString);
}
return ;
}
EFI_PERF_DATA_LIST *
CreateDataNode (
IN EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host
)
/*++
Routine Description:
Create a EFI_PERF_DATA_LIST data node.
Arguments:
Handle - Handle of gauge data
Token - Token of gauge data
Host - Host of gauge data
Returns:
Pointer to a data node created.
--*/
{
EFI_PERF_DATA_LIST *Node;
//
// Al\ a new image structure
//
Node = EfiLibAllocateZeroPool (sizeof (EFI_PERF_DATA_LIST));
if (Node != NULL) {
Node->Signature = EFI_PERFORMANCE_DATA_SIGNATURE;
Node->GaugeData.Handle = Handle;
if (Token != NULL) {
EfiStrCpy ((Node->GaugeData).Token, Token);
}
if (Host != NULL) {
EfiStrCpy ((Node->GaugeData).Host, Host);
}
if (Handle != NULL) {
GetNameFromHandle (Handle, Node->GaugeData.PdbFileName);
}
}
return Node;
}
EFI_PERF_DATA_LIST *
GetDataNode (
IN EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
IN EFI_GUID *GuidName,
IN EFI_GAUGE_DATA *PrevGauge
)
/*++
Routine Description:
Search gauge node list to find one node with matched handle, token, host and Guid name.
Arguments:
Handle - Handle to match
Token - Token to match
Host - Host to match
GuidName - Guid name to match
PrevGauge - Start node, start from list head if NULL
Returns:
Return pointer to the node found, NULL if not found.
--*/
{
EFI_PERF_DATA_LIST *Node;
EFI_PERF_DATA_LIST *Temp;
EFI_PERF_DATA_LIST *Temp2;
EFI_LIST_ENTRY *CurrentLink;
EFI_GUID NullGuid = EFI_NULL_GUID;
Node = NULL;
Temp = NULL;
Temp2 = NULL;
if (PrevGauge == NULL) {
CurrentLink = mPerfDataHead.ForwardLink;
} else {
Temp2 = GAUGE_DATA_FROM_GAUGE (PrevGauge);
CurrentLink = (Temp2->Link).ForwardLink;
}
while (CurrentLink && CurrentLink != &mPerfDataHead) {
Node = GAUGE_DATA_FROM_LINK (CurrentLink);
if (Handle == 0 && Token == NULL && Host == NULL && GuidName == NULL) {
return Node;
}
if (Handle != (Node->GaugeData).Handle) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
if (GuidName == NULL && !EfiCompareGuid (&((Node->GaugeData).GuidName), &NullGuid)) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
if (GuidName && !EfiCompareGuid (&((Node->GaugeData).GuidName), GuidName)) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
if (Token == NULL && EfiStrCmp (Node->GaugeData.Token, L"")) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
if (Token && EfiStrCmp (Node->GaugeData.Token, Token)) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
if (Host == NULL && EfiStrCmp (Node->GaugeData.Host, L"")) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
if (Host && EfiStrCmp (Node->GaugeData.Host, Host)) {
CurrentLink = CurrentLink->ForwardLink;
continue;
}
Temp = Node;
break;
}
return Temp;
}
EFI_STATUS
EFIAPI
StartGauge (
IN EFI_PERFORMANCE_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
IN UINT64 Ticker
)
/*++
Routine Description:
Create a guage data node and initialized it.
Arguments:
This - Calling context
Handle - Handle of gauge data
Token - Token of gauge data
Host - Host of gauge data
Ticker - Set gauge data's StartTick. If 0, StartTick is current timer.
Returns:
EFI_SUCCESS - Successfully create and initialized a guage data node.
EFI_OUT_OF_RESOURCES - No enough resource to create a guage data node.
--*/
{
EFI_PERFORMANCE_INSTANCE *PerfInstance;
EFI_PERF_DATA_LIST *Node;
UINT64 TimerValue;
TimerValue = 0;
PerfInstance = EFI_PERFORMANCE_FROM_THIS (This);
Node = CreateDataNode (Handle, Token, Host);
if (!Node) {
return EFI_OUT_OF_RESOURCES;
}
if (Ticker != 0) {
TimerValue = Ticker;
} else {
GetTimerValue (&TimerValue);
}
Node->GaugeData.StartTick = TimerValue;
if (!EfiStrCmp (Token, DXE_TOK)) {
PerfInstance->Phase = DXE_PHASE;
}
if (!EfiStrCmp (Token, SHELL_TOK)) {
PerfInstance->Phase = SHELL_PHASE;
}
Node->GaugeData.Phase = PerfInstance->Phase;
InsertTailList (&mPerfDataHead, &(Node->Link));
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
EndGauge (
IN EFI_PERFORMANCE_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
IN UINT64 Ticker
)
/*++
Routine Description:
End all unfinished gauge data node that match specified handle, token and host.
Arguments:
This - Calling context
Handle - Handle to stop
Token - Token to stop
Host - Host to stop
Ticker - End tick, if 0 then get current timer
Returns:
EFI_NOT_FOUND - Node not found
EFI_SUCCESS - Gauge data node successfully ended.
--*/
{
EFI_PERFORMANCE_INSTANCE *PerfInstance;
EFI_PERF_DATA_LIST *Node;
UINT64 TimerValue;
TimerValue = 0;
PerfInstance = EFI_PERFORMANCE_FROM_THIS (This);
Node = GetDataNode (Handle, Token, Host, NULL, NULL);
if (!Node) {
return EFI_NOT_FOUND;
}
while (Node->GaugeData.EndTick != 0) {
Node = GetDataNode (Handle, Token, Host, NULL, &(Node->GaugeData));
if (!Node) {
return EFI_NOT_FOUND;
}
}
if (Ticker != 0) {
TimerValue = Ticker;
} else {
GetTimerValue (&TimerValue);
}
Node->GaugeData.EndTick = TimerValue;
return EFI_SUCCESS;
}
EFI_GAUGE_DATA *
EFIAPI
GetGauge (
IN EFI_PERFORMANCE_PROTOCOL *This,
IN EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
IN EFI_GAUGE_DATA *PrevGauge
)
/*++
Routine Description:
Get gauge.
Arguments:
This - A pointer to the EFI_PERFORMANCE_PROTOCOL.
Handle - A pointer of a efi handle.
Token - A pointer to the token.
Host - A pointer to the host.
PrevGauge - A pointer to the EFI_GAUGE_DATA structure.
Returns:
Status code.
--*/
{
EFI_PERFORMANCE_INSTANCE *PerfInstance;
EFI_PERF_DATA_LIST *Node;
PerfInstance = EFI_PERFORMANCE_FROM_THIS (This);
Node = GetDataNode (Handle, Token, Host, NULL, PrevGauge);
if (Node != NULL) {
return &(Node->GaugeData);
} else {
return NULL;
}
}
//
// Driver entry point
//
EFI_STATUS
InitializePerformanceInfrastructure (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
IN UINT64 Ticker
)
/*++
Routine Description:
Install gEfiPerformanceProtocolGuid protocol and transfer PEI performance to gauge data nodes.
Arguments:
ImageHandle - Standard driver entry point parameter
SystemTable - Standard driver entry point parameter
Ticker - End tick for PEI performance
Returns:
EFI_OUT_OF_RESOURCES - No enough buffer to allocate
EFI_SUCCESS - Protocol installed.
--*/
{
EFI_STATUS Status;
EFI_PERFORMANCE_INSTANCE *PerfInstance;
//
// Allocate a new image structure
//
PerfInstance = EfiLibAllocateZeroPool (sizeof (EFI_PERFORMANCE_INSTANCE));
if (PerfInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
PerfInstance->Signature = EFI_PERFORMANCE_SIGNATURE;
PerfInstance->Perf.StartGauge = StartGauge;
PerfInstance->Perf.EndGauge = EndGauge;
PerfInstance->Perf.GetGauge = GetGauge;
//
// Install the protocol interfaces
//
Status = gBS->InstallProtocolInterface (
&PerfInstance->Handle,
&gEfiPerformanceProtocolGuid,
EFI_NATIVE_INTERFACE,
&PerfInstance->Perf
);
if (!EFI_ERROR (Status)) {
GetPeiPerformance (ImageHandle, SystemTable, Ticker);
}
return EFI_SUCCESS;
}
EFI_STATUS
StartMeasure (
EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
IN UINT64 Ticker
)
/*++
Routine Description:
Start to gauge on a specified handle, token and host, with Ticker as start tick.
Arguments:
Handle - Handle to measure
Token - Token to measure
Host - Host to measure
Ticker - Ticker as start tick
Returns:
Status code.
--*/
{
EFI_STATUS Status;
EFI_PERFORMANCE_PROTOCOL *Perf;
Status = gBS->LocateProtocol (&gEfiPerformanceProtocolGuid, NULL, (VOID **) &Perf);
if (EFI_ERROR (Status)) {
return Status;
}
return Perf->StartGauge (Perf, Handle, Token, Host, Ticker);
}
EFI_STATUS
EndMeasure (
EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
IN UINT64 Ticker
)
/*++
Routine Description:
End gauging on a specified handle, token and host, with Ticker as end tick.
Arguments:
Handle - Handle to stop
Token - Token to stop
Host - Host to stop
Ticker - Ticker as end tick
Returns:
Status code.
--*/
{
EFI_STATUS Status;
EFI_PERFORMANCE_PROTOCOL *Perf;
Status = gBS->LocateProtocol (&gEfiPerformanceProtocolGuid, NULL, (VOID **) &Perf);
if (Status != EFI_SUCCESS) {
return Status;
}
return (Perf->EndGauge( Perf, Handle, Token, Host, Ticker)) ;
}
EFI_STATUS
UpdateMeasure (
EFI_HANDLE Handle,
IN UINT16 *Token,
IN UINT16 *Host,
EFI_HANDLE HandleNew,
IN UINT16 *TokenNew,
IN UINT16 *HostNew
)
/*++
Routine Description:
Update measure.
Arguments:
Handle - A pointer of an efi handle.
Token - A pointer to the token.
Host - A pointer to the host.
HandleNew - A pointer of an new efi handle.
TokenNew - A pointer to the new token.
HostNew - A pointer to the new host.
Returns:
Status code.
EFI_NOT_FOUND - The speicified gauge data node not found.
EFI_SUCCESS - Update successfully.
--*/
{
EFI_STATUS Status;
EFI_GAUGE_DATA *GaugeData;
EFI_PERFORMANCE_PROTOCOL *Perf;
Status = gBS->LocateProtocol (&gEfiPerformanceProtocolGuid, NULL, (VOID **) &Perf);
if (EFI_ERROR (Status)) {
return Status;
}
GaugeData = Perf->GetGauge (Perf, Handle, Token, Host, NULL);
if (!GaugeData) {
return EFI_NOT_FOUND;
}
GaugeData->Handle = HandleNew;
if (HostNew != NULL) {
EfiStrCpy (GaugeData->Host, HostNew);
} else {
EfiStrCpy (GaugeData->Host, L"");
}
if (TokenNew != NULL) {
EfiStrCpy (GaugeData->Token, TokenNew);
} else {
EfiStrCpy (GaugeData->Token, L"");
}
return EFI_SUCCESS;
}
EFI_STATUS
GetPeiPerformance (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
IN UINT64 Ticker
)
/*++
Routine Description:
Transfer PEI performance data to gauge data node.
Arguments:
ImageHandle - Standard entry point parameter
SystemTable - Standard entry point parameter
Ticker - Start tick
Returns:
EFI_OUT_OF_RESOURCES - No enough resource to create data node.
EFI_SUCCESS - Transfer done successfully.
--*/
{
EFI_STATUS Status;
VOID *HobList;
EFI_HOB_GUID_DATA_PERFORMANCE_LOG *LogHob;
PEI_PERFORMANCE_MEASURE_LOG_ENTRY *LogEntry;
UINT32 Index;
EFI_PERF_DATA_LIST *Node;
UINT64 TimerValue;
Node = CreateDataNode (0, PEI_TOK, NULL);
if (!Node) {
return EFI_OUT_OF_RESOURCES;
}
if (Ticker != 0) {
TimerValue = Ticker;
} else {
GetTimerValue (&TimerValue);
}
(Node->GaugeData).EndTick = TimerValue;
InsertTailList (&mPerfDataHead, &(Node->Link));
EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);
do {
Status = GetNextGuidHob (&HobList, &gEfiPeiPerformanceHobGuid, (VOID **) &LogHob, NULL);
if (EFI_ERROR (Status)) {
break;
}
for (Index = 0; Index < LogHob->NumberOfEntries; Index++) {
LogEntry = &(LogHob->Log[Index]);
Node = CreateDataNode (0, LogEntry->DescriptionString, NULL);
if (!Node) {
return EFI_OUT_OF_RESOURCES;
}
(Node->GaugeData).StartTick = LogEntry->StartTimeCount;
EfiCopyMem (&(Node->GaugeData.GuidName), &LogEntry->Name, sizeof (EFI_GUID));
InsertTailList (&mPerfDataHead, &(Node->Link));
(Node->GaugeData).EndTick = LogEntry->StopTimeCount;
}
} while (!EFI_ERROR (Status));
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,141 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ReportStatusCode.c
Abstract:
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include EFI_PROTOCOL_DEFINITION (DevicePath)
#include EFI_GUID_DEFINITION (StatusCodeDataTypeId)
#include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
STATIC EFI_STATUS_CODE_PROTOCOL *gStatusCode = NULL;
#endif
EFI_STATUS
EfiLibReportStatusCode (
IN EFI_STATUS_CODE_TYPE Type,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID *CallerId OPTIONAL,
IN EFI_STATUS_CODE_DATA *Data OPTIONAL
)
/*++
Routine Description:
Report device path through status code.
Arguments:
Type - Code type
Value - Code value
Instance - Instance number
CallerId - Caller name
DevicePath - Device path that to be reported
Returns:
Status code.
EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
--*/
{
EFI_STATUS Status;
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
if (gStatusCode == NULL) {
if (gBS == NULL) {
return EFI_UNSUPPORTED;
}
Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);
if (EFI_ERROR (Status) || gStatusCode == NULL) {
return EFI_UNSUPPORTED;
}
}
Status = gStatusCode->ReportStatusCode (Type, Value, Instance, CallerId, Data);
return Status;
#else
if (gRT == NULL) {
return EFI_UNSUPPORTED;
}
//
// Check whether EFI_RUNTIME_SERVICES has Tiano Extension
//
Status = EFI_UNSUPPORTED;
if (gRT->Hdr.Revision == EFI_SPECIFICATION_VERSION &&
gRT->Hdr.HeaderSize == sizeof (EFI_RUNTIME_SERVICES) &&
gRT->ReportStatusCode != NULL) {
Status = gRT->ReportStatusCode (Type, Value, Instance, CallerId, Data);
}
return Status;
#endif
}
EFI_STATUS
ReportStatusCodeWithDevicePath (
IN EFI_STATUS_CODE_TYPE Type,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID * CallerId OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath
)
/*++
Routine Description:
Report device path through status code.
Arguments:
Type - Code type
Value - Code value
Instance - Instance number
CallerId - Caller name
DevicePath - Device path that to be reported
Returns:
Status code.
EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
--*/
{
UINT16 Size;
UINT16 DevicePathSize;
EFI_STATUS_CODE_DATA *ExtendedData;
EFI_DEVICE_PATH_PROTOCOL *ExtendedDevicePath;
EFI_STATUS Status;
DevicePathSize = (UINT16) EfiDevicePathSize (DevicePath);
Size = DevicePathSize + sizeof (EFI_STATUS_CODE_DATA);
ExtendedData = (EFI_STATUS_CODE_DATA *) EfiLibAllocatePool (Size);
if (ExtendedData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
ExtendedDevicePath = EfiConstructStatusCodeData (Size, &gEfiStatusCodeSpecificDataGuid, ExtendedData);
EfiCopyMem (ExtendedDevicePath, DevicePath, DevicePathSize);
Status = EfiLibReportStatusCode (Type, Value, Instance, CallerId, (EFI_STATUS_CODE_DATA *) ExtendedData);
gBS->FreePool (ExtendedData);
return Status;
}

View File

@@ -0,0 +1,47 @@
/*++
Copyright (c) 2004, 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:
PerformancePrimitives.c
Abstract:
Support for Performance library
--*/
#include "TianoCommon.h"
#include "CpuIA32.h"
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
)
/*++
Routine Description:
Set TimerValue with current tick.
Arguments:
TimerValue - Timer value to be set
Returns:
EFI_SUCCESS - TimerValue is set.
--*/
{
*TimerValue = EfiReadTsc ();
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,47 @@
/*++
Copyright (c) 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PerformancePrimitives.c
Abstract:
Support for Performance library
--*/
#include "TianoCommon.h"
#include "CpuIA32.h"
EFI_STATUS
GetTimerValue (
OUT UINT64 *TimerValue
)
/*++
Routine Description:
Set TimerValue with current tick.
Arguments:
TimerValue - Timer value to be set
Returns:
EFI_SUCCESS - TimerValue is set.
--*/
{
*TimerValue = EfiReadTsc ();
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,51 @@
#/*++
#
# Copyright (c) 2004, 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:
#
# EfiIfrSupportLib.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = EfiIfrSupportLib
COMPONENT_TYPE = LIBRARY
[sources.common]
IfrCommon.c
IfrOnTheFly.c
IfrOpCodeCreation.c
IfrLibrary.h
IfrVariable.c
[includes.common]
$(EDK_SOURCE)\Foundation\Efi
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Core\Dxe
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Library\Dxe\EfiDriverLib
[libraries.common]
EfiGuidLib
EdkFrameworkProtocolLib
[nmake.common]

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,974 @@
/*++
Copyright (c) 2004, 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:
IfrOnTheFly.c
Abstract:
Library Routines to create IFR on-the-fly
Revision History:
--*/
#include "IfrLibrary.h"
EFI_STATUS
CreateFormSet (
IN CHAR16 *FormSetTitle,
IN EFI_GUID *Guid,
IN UINT8 Class,
IN UINT8 SubClass,
IN OUT VOID **FormBuffer,
IN OUT VOID **StringBuffer
)
/*++
Routine Description:
Create a formset
Arguments:
FormSetTitle - Title of formset
Guid - Guid of formset
Class - Class of formset
SubClass - Sub class of formset
FormBuffer - Pointer of the formset created
StringBuffer - Pointer of FormSetTitile string created
Returns:
EFI_OUT_OF_RESOURCES - No enough buffer to allocate
EFI_SUCCESS - Formset successfully created
--*/
{
EFI_STATUS Status;
EFI_HII_IFR_PACK IfrPack;
EFI_IFR_FORM_SET FormSet;
EFI_IFR_END_FORM_SET EndFormSet;
UINT8 *Destination;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Pre-allocate a buffer sufficient for us to work from.
//
FormBuffer = EfiLibAllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE);
if (FormBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Pre-allocate a buffer sufficient for us to work from.
//
StringBuffer = EfiLibAllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE);
if (StringBuffer == NULL) {
gBS->FreePool (FormBuffer);
return EFI_OUT_OF_RESOURCES;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add the FormSetTitle to the string buffer and get the StringToken
//
Status = AddString (*StringBuffer, CurrentLanguage, FormSetTitle, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Initialize the Ifr Package header data
//
IfrPack.Header.Length = sizeof (EFI_HII_PACK_HEADER) + sizeof (EFI_IFR_FORM_SET) + sizeof (EFI_IFR_END_FORM_SET);
IfrPack.Header.Type = EFI_HII_IFR;
//
// Initialize FormSet with the appropriate information
//
FormSet.Header.OpCode = EFI_IFR_FORM_SET_OP;
FormSet.Header.Length = sizeof (EFI_IFR_FORM_SET);
FormSet.FormSetTitle = StringToken;
FormSet.Class = Class;
FormSet.SubClass = SubClass;
EfiCopyMem (&FormSet.Guid, Guid, sizeof (EFI_GUID));
//
// Initialize the end formset data
//
EndFormSet.Header.Length = sizeof (EFI_IFR_END_FORM_SET);
EndFormSet.Header.OpCode = EFI_IFR_END_FORM_SET_OP;
Destination = (CHAR8 *) *FormBuffer;
//
// Copy the formset/endformset data to the form buffer
//
EfiCopyMem (Destination, &IfrPack, sizeof (EFI_HII_PACK_HEADER));
Destination = Destination + sizeof (EFI_HII_PACK_HEADER);
EfiCopyMem (Destination, &FormSet, sizeof (EFI_IFR_FORM_SET));
Destination = Destination + sizeof (EFI_IFR_FORM_SET);
EfiCopyMem (Destination, &EndFormSet, sizeof (EFI_IFR_END_FORM_SET));
return EFI_SUCCESS;
}
EFI_STATUS
CreateForm (
IN CHAR16 *FormTitle,
IN UINT16 FormId,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a form
Arguments:
FormTitle - Title of the form
FormId - Id of the form
FormBuffer - Pointer of the form created
StringBuffer - Pointer of FormTitil string created
Returns:
EFI_SUCCESS - Form successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_FORM Form;
EFI_IFR_END_FORM EndForm;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
Status = AddString (StringBuffer, CurrentLanguage, FormTitle, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Form.Header.OpCode = EFI_IFR_FORM_OP;
Form.Header.Length = sizeof (EFI_IFR_FORM);
Form.FormId = FormId;
Form.FormTitle = StringToken;
Status = AddOpCode (FormBuffer, &Form);
if (EFI_ERROR (Status)) {
return Status;
}
EndForm.Header.OpCode = EFI_IFR_END_FORM_OP;
EndForm.Header.Length = sizeof (EFI_IFR_END_FORM);
Status = AddOpCode (FormBuffer, &EndForm);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateSubTitle (
IN CHAR16 *SubTitle,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a SubTitle
Arguments:
SubTitle - Sub title to be created
FormBuffer - Where this subtitle to add to
StringBuffer - String buffer created for subtitle
Returns:
EFI_SUCCESS - Subtitle successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_SUBTITLE Subtitle;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
Status = AddString (StringBuffer, CurrentLanguage, SubTitle, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
Subtitle.SubTitle = StringToken;
Status = AddOpCode (FormBuffer, &Subtitle);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateText (
IN CHAR16 *String,
IN CHAR16 *String2,
IN CHAR16 *String3,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a line of text
Arguments:
String - First string of the text
String2 - Second string of the text
String3 - Help string of the text
Flags - Flag of the text
Key - Key of the text
FormBuffer - The form where this text adds to
StringBuffer - String buffer created for String, String2 and String3
Returns:
EFI_SUCCESS - Text successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_TEXT Text;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, String, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Text.Header.OpCode = EFI_IFR_TEXT_OP;
Text.Header.Length = sizeof (EFI_IFR_TEXT);
Text.Text = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, String2, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Text.TextTwo = StringToken;
Text.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
Text.Key = Key;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, String3, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Text.Help = StringToken;
Status = AddOpCode (FormBuffer, &Text);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateGoto (
IN UINT16 FormId,
IN CHAR16 *Prompt,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a hyperlink
Arguments:
FormId - Form ID of the hyperlink
Prompt - Prompt of the hyperlink
FormBuffer - The form where this hyperlink adds to
StringBuffer - String buffer created for Prompt
Returns:
EFI_SUCCESS - Hyperlink successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_REF Hyperlink;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Hyperlink.Header.OpCode = EFI_IFR_REF_OP;
Hyperlink.Header.Length = sizeof (EFI_IFR_REF);
Hyperlink.FormId = FormId;
Hyperlink.Prompt = StringToken;
Status = AddOpCode (FormBuffer, &Hyperlink);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateOneOf (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a one-of question with a set of options to choose from. The
OptionsList is a pointer to a null-terminated list of option descriptions.
Arguments:
QuestionId - Question ID of the one-of box
DataWidth - DataWidth of the one-of box
Prompt - Prompt of the one-of box
Help - Help of the one-of box
OptionsList - Each string in it is an option of the one-of box
OptionCount - Option string count
FormBuffer - The form where this one-of box adds to
StringBuffer - String buffer created for Prompt, Help and Option strings
Returns:
EFI_DEVICE_ERROR - DataWidth > 2
EFI_SUCCESS - One-Of box successfully created.
--*/
{
EFI_STATUS Status;
UINTN Index;
EFI_IFR_ONE_OF OneOf;
EFI_IFR_ONE_OF_OPTION OneOfOption;
EFI_IFR_END_ONE_OF EndOneOf;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// We do not create op-code storage widths for one-of in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;
OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);
OneOf.QuestionId = QuestionId;
OneOf.Width = DataWidth;
OneOf.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OneOf.Help = StringToken;
Status = AddOpCode (FormBuffer, &OneOf);
if (EFI_ERROR (Status)) {
return Status;
}
for (Index = 0; Index < OptionCount; Index++) {
OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
//
// Add string and get token back
//
Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
OneOfOption.Option = StringToken;
OneOfOption.Value = OptionsList[Index].Value;
OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);
OneOfOption.Key = OptionsList[Index].Key;
Status = AddOpCode (FormBuffer, &OneOfOption);
if (EFI_ERROR (Status)) {
return Status;
}
}
EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
Status = AddOpCode (FormBuffer, &EndOneOf);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateOrderedList (
IN UINT16 QuestionId,
IN UINT8 MaxEntries,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a one-of question with a set of options to choose from. The
OptionsList is a pointer to a null-terminated list of option descriptions.
Arguments:
QuestionId - Question ID of the ordered list
MaxEntries - MaxEntries of the ordered list
Prompt - Prompt of the ordered list
Help - Help of the ordered list
OptionsList - Each string in it is an option of the ordered list
OptionCount - Option string count
FormBuffer - The form where this ordered list adds to
StringBuffer - String buffer created for Prompt, Help and Option strings
Returns:
EFI_SUCCESS - Ordered list successfully created.
--*/
{
EFI_STATUS Status;
UINTN Index;
EFI_IFR_ORDERED_LIST OrderedList;
EFI_IFR_ONE_OF_OPTION OrderedListOption;
EFI_IFR_END_ONE_OF EndOrderedList;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;
OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);
OrderedList.QuestionId = QuestionId;
OrderedList.MaxEntries = MaxEntries;
OrderedList.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OrderedList.Help = StringToken;
Status = AddOpCode (FormBuffer, &OrderedList);
if (EFI_ERROR (Status)) {
return Status;
}
for (Index = 0; Index < OptionCount; Index++) {
OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
//
// Add string and get token back
//
Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
OrderedListOption.Option = StringToken;
OrderedListOption.Value = OptionsList[Index].Value;
OrderedListOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);
OrderedListOption.Key = OptionsList[Index].Key;
Status = AddOpCode (FormBuffer, &OrderedListOption);
if (EFI_ERROR (Status)) {
return Status;
}
}
EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
Status = AddOpCode (FormBuffer, &EndOrderedList);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateCheckBox (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN UINT8 Flags,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a checkbox
Arguments:
QuestionId - Question ID of the check box
DataWidth - DataWidth of the check box
Prompt - Prompt of the check box
Help - Help of the check box
Flags - Flags of the check box
FormBuffer - The form where this check box adds to
StringBuffer - String buffer created for Prompt and Help.
Returns:
EFI_DEVICE_ERROR - DataWidth > 1
EFI_SUCCESS - Check box successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_CHECK_BOX CheckBox;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// We do not create op-code storage widths for checkbox in excess of 8 bits for now
//
if (DataWidth > 1) {
return EFI_DEVICE_ERROR;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;
CheckBox.Header.Length = sizeof (EFI_IFR_CHECK_BOX);
CheckBox.QuestionId = QuestionId;
CheckBox.Width = DataWidth;
CheckBox.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
CheckBox.Help = StringToken;
CheckBox.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
Status = AddOpCode (FormBuffer, &CheckBox);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateNumeric (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN UINT16 Minimum,
IN UINT16 Maximum,
IN UINT16 Step,
IN UINT16 Default,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a numeric
Arguments:
QuestionId - Question ID of the numeric
DataWidth - DataWidth of the numeric
Prompt - Prompt of the numeric
Help - Help of the numeric
Minimum - Minumun boundary of the numeric
Maximum - Maximum boundary of the numeric
Step - Step of the numeric
Default - Default value
Flags - Flags of the numeric
Key - Key of the numeric
FormBuffer - The form where this numeric adds to
StringBuffer - String buffer created for Prompt and Help.
Returns:
EFI_DEVICE_ERROR - DataWidth > 2
EFI_SUCCESS - Numeric is successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_NUMERIC Numeric;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// We do not create op-code storage widths for numerics in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;
Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);
Numeric.QuestionId = QuestionId;
Numeric.Width = DataWidth;
Numeric.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Numeric.Help = StringToken;
Numeric.Minimum = Minimum;
Numeric.Maximum = Maximum;
Numeric.Step = Step;
Numeric.Default = Default;
Numeric.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
Numeric.Key = Key;
Status = AddOpCode (FormBuffer, &Numeric);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateString (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN UINT8 MinSize,
IN UINT8 MaxSize,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a string
Arguments:
QuestionId - Question ID of the string
DataWidth - DataWidth of the string
Prompt - Prompt of the string
Help - Help of the string
MinSize - Min size boundary of the string
MaxSize - Max size boundary of the string
Flags - Flags of the string
Key - Key of the string
FormBuffer - The form where this string adds to
StringBuffer - String buffer created for Prompt and Help.
Returns:
EFI_SUCCESS - String successfully created.
--*/
{
EFI_STATUS Status;
EFI_IFR_STRING String;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
String.Header.OpCode = EFI_IFR_STRING_OP;
String.Header.Length = sizeof (EFI_IFR_STRING);
String.QuestionId = QuestionId;
String.Width = DataWidth;
String.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
String.Help = StringToken;
String.MinSize = MinSize;
String.MaxSize = MaxSize;
String.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
String.Key = Key;
Status = AddOpCode (FormBuffer, &String);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,615 @@
/*++
Copyright (c) 2004, 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:
IfrOpCodeCreation.c
Abstract:
Library Routines to create IFR independent of string data - assume tokens already exist
Primarily to be used for exporting op-codes at a label in pre-defined forms.
Revision History:
--*/
#include "IfrLibrary.h"
EFI_STATUS
CreateSubTitleOpCode (
IN STRING_REF StringToken,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a SubTitle opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
StringToken - StringToken of the subtitle
FormBuffer - Output of subtitle as a form
Returns:
EFI_SUCCESS - Subtitle created to be a form
--*/
{
EFI_IFR_SUBTITLE Subtitle;
Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
Subtitle.SubTitle = StringToken;
EfiCopyMem (FormBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE));
return EFI_SUCCESS;
}
EFI_STATUS
CreateTextOpCode (
IN STRING_REF StringToken,
IN STRING_REF StringTokenTwo,
IN STRING_REF StringTokenThree,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a Text opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
StringToken - First string token of the text
StringTokenTwo - Second string token of the text
StringTokenThree - Help string token of the text
Flags - Flag of the text
Key - Key of the text
FormBuffer - Output of text as a form
Returns:
EFI_SUCCESS - Text created to be a form
--*/
{
EFI_IFR_TEXT Text;
Text.Header.OpCode = EFI_IFR_TEXT_OP;
Text.Header.Length = sizeof (EFI_IFR_TEXT);
Text.Text = StringToken;
Text.TextTwo = StringTokenTwo;
Text.Help = StringTokenThree;
Text.Flags = Flags;
Text.Key = Key;
EfiCopyMem (FormBuffer, &Text, sizeof (EFI_IFR_TEXT));
return EFI_SUCCESS;
}
EFI_STATUS
CreateGotoOpCode (
IN UINT16 FormId,
IN STRING_REF StringToken,
IN STRING_REF StringTokenTwo,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a hyperlink opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
FormId - Form ID of the hyperlink
StringToken - Prompt string token of the hyperlink
StringTokenTwo - Help string token of the hyperlink
Flags - Flags of the hyperlink
Key - Key of the hyperlink
FormBuffer - Output of hyperlink as a form
Returns:
EFI_SUCCESS - Hyperlink created to be a form
--*/
{
EFI_IFR_REF Hyperlink;
Hyperlink.Header.OpCode = EFI_IFR_REF_OP;
Hyperlink.Header.Length = sizeof (EFI_IFR_REF);
Hyperlink.FormId = FormId;
Hyperlink.Prompt = StringToken;
Hyperlink.Help = StringTokenTwo;
Hyperlink.Key = Key;
Hyperlink.Flags = Flags;
EfiCopyMem (FormBuffer, &Hyperlink, sizeof (EFI_IFR_REF));
return EFI_SUCCESS;
}
EFI_STATUS
CreateOneOfOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a one-of opcode with a set of option op-codes to choose from independent of string creation.
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
has been filled in since this routine will not generate StringToken values.
Arguments:
QuestionId - Question ID of the one-of box
DataWidth - DataWidth of the one-of box
PromptToken - Prompt string token of the one-of box
HelpToken - Help string token of the one-of box
OptionsList - Each string in it is an option of the one-of box
OptionCount - Option string count
FormBuffer - Output of One-Of box as a form
Returns:
EFI_SUCCESS - One-Of box created to be a form
EFI_DEVICE_ERROR - DataWidth > 2
--*/
{
UINTN Index;
EFI_IFR_ONE_OF OneOf;
EFI_IFR_ONE_OF_OPTION OneOfOption;
EFI_IFR_END_ONE_OF EndOneOf;
UINT8 *LocalBuffer;
//
// We do not create op-code storage widths for one-of in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;
OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);
OneOf.QuestionId = QuestionId;
OneOf.Width = DataWidth;
OneOf.Prompt = PromptToken;
OneOf.Help = HelpToken;
LocalBuffer = (CHAR8 *) FormBuffer;
EfiCopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF));
LocalBuffer = (CHAR8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF));
for (Index = 0; Index < OptionCount; Index++) {
OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
OneOfOption.Option = OptionsList[Index].StringToken;
OneOfOption.Value = OptionsList[Index].Value;
OneOfOption.Flags = OptionsList[Index].Flags;
OneOfOption.Key = OptionsList[Index].Key;
EfiCopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION));
LocalBuffer = (CHAR8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));
}
EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
EfiCopyMem (LocalBuffer, &EndOneOf, sizeof (EFI_IFR_END_ONE_OF));
LocalBuffer = (CHAR8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));
return EFI_SUCCESS;
}
EFI_STATUS
CreateOrderedListOpCode (
IN UINT16 QuestionId,
IN UINT8 MaxEntries,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a ordered list opcode with a set of option op-codes to choose from independent of string creation.
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
has been filled in since this routine will not generate StringToken values.
Arguments:
QuestionId - Question ID of the ordered list
MaxEntries - MaxEntries of the ordered list
PromptToken - Prompt string token of the ordered list
HelpToken - Help string token of the ordered list
OptionsList - Each string in it is an option of the ordered list
OptionCount - Option string count
FormBuffer - Output of ordered list as a form
Returns:
EFI_SUCCESS - Ordered list created to be a form
--*/
{
UINTN Index;
EFI_IFR_ORDERED_LIST OrderedList;
EFI_IFR_ONE_OF_OPTION OrderedListOption;
EFI_IFR_END_ONE_OF EndOrderedList;
UINT8 *LocalBuffer;
OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;
OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);
OrderedList.QuestionId = QuestionId;
OrderedList.MaxEntries = MaxEntries;
OrderedList.Prompt = PromptToken;
OrderedList.Help = HelpToken;
LocalBuffer = (CHAR8 *) FormBuffer;
EfiCopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST));
LocalBuffer = (CHAR8 *) (LocalBuffer + sizeof (EFI_IFR_ORDERED_LIST));
for (Index = 0; Index < OptionCount; Index++) {
OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
OrderedListOption.Option = OptionsList[Index].StringToken;
OrderedListOption.Value = OptionsList[Index].Value;
OrderedListOption.Flags = OptionsList[Index].Flags;
OrderedListOption.Key = OptionsList[Index].Key;
EfiCopyMem (LocalBuffer, &OrderedListOption, sizeof (EFI_IFR_ONE_OF_OPTION));
LocalBuffer = (CHAR8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));
}
EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
EfiCopyMem (LocalBuffer, &EndOrderedList, sizeof (EFI_IFR_END_ONE_OF));
LocalBuffer = (CHAR8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));
return EFI_SUCCESS;
}
EFI_STATUS
CreateCheckBoxOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a checkbox opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
QuestionId - Question ID of the check box
DataWidth - DataWidth of the check box
PromptToken - Prompt string token of the check box
HelpToken - Help string token of the check box
Flags - Flags of the check box
Key - Key of the check box
FormBuffer - Output of the check box as a form
Returns:
EFI_SUCCESS - Checkbox created to be a form
EFI_DEVICE_ERROR - DataWidth > 1
--*/
{
EFI_IFR_CHECK_BOX CheckBox;
//
// We do not create op-code storage widths for checkbox in excess of 8 bits for now
//
if (DataWidth > 1) {
return EFI_DEVICE_ERROR;
}
CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;
CheckBox.Header.Length = sizeof (EFI_IFR_CHECK_BOX);
CheckBox.QuestionId = QuestionId;
CheckBox.Width = DataWidth;
CheckBox.Prompt = PromptToken;
CheckBox.Help = HelpToken;
CheckBox.Flags = Flags;
CheckBox.Key = Key;
EfiCopyMem (FormBuffer, &CheckBox, sizeof (EFI_IFR_CHECK_BOX));
return EFI_SUCCESS;
}
EFI_STATUS
CreateNumericOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN UINT16 Minimum,
IN UINT16 Maximum,
IN UINT16 Step,
IN UINT16 Default,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a numeric opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
QuestionId - Question ID of the numeric
DataWidth - DataWidth of the numeric
PromptToken - Prompt string token of the numeric
HelpToken - Help string token of the numeric
Minimum - Minumun boundary of the numeric
Maximum - Maximum boundary of the numeric
Step - Step of the numeric
Default - Default value of the numeric
Flags - Flags of the numeric
Key - Key of the numeric
FormBuffer - Output of the numeric as a form
Returns:
EFI_SUCCESS - The numeric created to be a form.
EFI_DEVICE_ERROR - DataWidth > 2
--*/
{
EFI_IFR_NUMERIC Numeric;
//
// We do not create op-code storage widths for numerics in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;
Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);
Numeric.QuestionId = QuestionId;
Numeric.Width = DataWidth;
Numeric.Prompt = PromptToken;
Numeric.Help = HelpToken;
Numeric.Minimum = Minimum;
Numeric.Maximum = Maximum;
Numeric.Step = Step;
Numeric.Default = Default;
Numeric.Flags = Flags;
Numeric.Key = Key;
EfiCopyMem (FormBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC));
return EFI_SUCCESS;
}
EFI_STATUS
CreateStringOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN UINT8 MinSize,
IN UINT8 MaxSize,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a numeric opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
QuestionId - Question ID of the string
DataWidth - DataWidth of the string
PromptToken - Prompt token of the string
HelpToken - Help token of the string
MinSize - Min size boundary of the string
MaxSize - Max size boundary of the string
Flags - Flags of the string
Key - Key of the string
FormBuffer - Output of the string as a form
Returns:
EFI_SUCCESS - String created to be a form.
--*/
{
EFI_IFR_STRING String;
String.Header.OpCode = EFI_IFR_STRING_OP;
String.Header.Length = sizeof (EFI_IFR_STRING);
String.QuestionId = QuestionId;
String.Width = DataWidth;
String.Prompt = PromptToken;
String.Help = HelpToken;
String.MinSize = MinSize;
String.MaxSize = MaxSize;
String.Flags = Flags;
String.Key = Key;
EfiCopyMem (FormBuffer, &String, sizeof (EFI_IFR_STRING));
return EFI_SUCCESS;
}
EFI_STATUS
CreateBannerOpCode (
IN UINT16 Title,
IN UINT16 LineNumber,
IN UINT8 Alignment,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.
Arguments:
Title - Title of the banner
LineNumber - LineNumber of the banner
Alignment - Alignment of the banner
FormBuffer - Output of banner as a form
Returns:
EFI_SUCCESS - Banner created to be a form.
--*/
{
EFI_IFR_BANNER Banner;
Banner.Header.OpCode = EFI_IFR_BANNER_OP;
Banner.Header.Length = sizeof (EFI_IFR_BANNER);
EfiCopyMem (&Banner.Title, &Title, sizeof (UINT16));
EfiCopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));
Banner.Alignment = Alignment;
EfiCopyMem (FormBuffer, &Banner, sizeof (EFI_IFR_BANNER));
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,488 @@
/*++
Copyright (c) 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
IfrVariable.c
Abstract:
Variable/Map manipulations routines
--*/
#include "IfrLibrary.h"
VOID
EfiLibHiiVariablePackGetMap (
IN EFI_HII_VARIABLE_PACK *Pack,
OUT CHAR16 **Name, OPTIONAL
OUT EFI_GUID **Guid, OPTIONAL
OUT UINT16 *Id, OPTIONAL
OUT VOID **Var, OPTIONAL
OUT UINTN *Size OPTIONAL
)
/*++
Routine Description:
Extracts a variable form a Pack.
Arguments:
Pack - List of variables
Name - Name of the variable/map
Guid - GUID of the variable/map
Var - Pointer to the variable/map
Size - Size of the variable/map in bytes
Returns:
VOID
--*/
{
if (NULL != Name) {
*Name = (VOID *) (Pack + 1);
}
if (NULL != Guid) {
*Guid = &Pack->VariableGuid;
}
if (NULL != Id) {
*Id = Pack->VariableId;
}
if (NULL != Var) {
*Var = (VOID *) ((CHAR8 *) (Pack + 1) + Pack->VariableNameLength);
}
if (NULL != Size) {
*Size = Pack->Header.Length - sizeof (*Pack) - Pack->VariableNameLength;
}
}
UINTN
EfiLibHiiVariablePackListGetMapCnt (
IN EFI_HII_VARIABLE_PACK_LIST *List
)
/*++
Routine Description:
Finds a count of the variables/maps in the List.
Arguments:
List - List of variables
Returns:
UINTN - The number of map count.
--*/
{
UINTN Cnt = 0;
while (NULL != List) {
Cnt++;
List = List->NextVariablePack;
}
return Cnt;
}
VOID
EfiLibHiiVariablePackListForEachVar (
IN EFI_HII_VARIABLE_PACK_LIST *List,
IN EFI_LIB_HII_VARIABLE_PACK_LIST_CALLBACK *Callback
)
/*++
Routine Description:
Will iterate all variable/maps as appearing
in List and for each, it will call the Callback.
Arguments:
List - List of variables
Callback - Routine to be called for each iterated variable.
Returns:
VOID
--*/
{
CHAR16 *MapName;
EFI_GUID *MapGuid;
UINT16 MapId;
VOID *Map;
UINTN MapSize;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
//
// call the callback
//
Callback (MapName, MapGuid, MapId, Map, MapSize);
List = List->NextVariablePack;
}
}
EFI_STATUS
EfiLibHiiVariablePackListGetMapByIdx (
IN UINTN Idx,
IN EFI_HII_VARIABLE_PACK_LIST *List,
OUT CHAR16 **Name, OPTIONAL
OUT EFI_GUID **Guid, OPTIONAL
OUT UINT16 *Id, OPTIONAL
OUT VOID **Var,
OUT UINTN *Size
)
/*++
Routine Description:
Finds a variable form List given
the order number as appears in the List.
Arguments:
Idx - The index of the variable/map to retrieve
List - List of variables
Name - Name of the variable/map
Guid - GUID of the variable/map
Var - Pointer to the variable/map
Size - Size of the variable/map in bytes
Returns:
EFI_SUCCESS - Variable is found, OUT parameters are valid
EFI_NOT_FOUND - Variable is not found, OUT parameters are not valid
--*/
{
CHAR16 *MapName;
EFI_GUID *MapGuid;
UINT16 MapId;
VOID *Map;
UINTN MapSize;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
if (0 == Idx--) {
*Var = Map;
*Size = MapSize;
if (NULL != Name) {
*Name = MapName;
}
if (NULL != Guid) {
*Guid = MapGuid;
}
if (NULL != Id) {
*Id = MapId;
}
return EFI_SUCCESS; // Map found
}
List = List->NextVariablePack;
}
//
// If here, the map is not found
//
return EFI_NOT_FOUND;
}
EFI_STATUS
EfiLibHiiVariablePackListGetMapById (
IN UINT16 Id,
IN EFI_HII_VARIABLE_PACK_LIST *List,
OUT CHAR16 **Name, OPTIONAL
OUT EFI_GUID **Guid, OPTIONAL
OUT VOID **Var,
OUT UINTN *Size
)
/*++
Routine Description:
Finds a variable form List given the
order number as appears in the List.
Arguments:
Id - The ID of the variable/map to retrieve
List - List of variables
Name - Name of the variable/map
Guid - GUID of the variable/map
Var - Pointer to the variable/map
Size - Size of the variable/map in bytes
Returns:
EFI_SUCCESS - Variable is found, OUT parameters are valid
EFI_NOT_FOUND - Variable is not found, OUT parameters are not valid
--*/
{
CHAR16 *MapName;
EFI_GUID *MapGuid;
UINT16 MapId;
VOID *Map;
UINTN MapSize;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
if (MapId == Id) {
*Var = Map;
*Size = MapSize;
if (NULL != Name) {
*Name = MapName;
}
if (NULL != Guid) {
*Guid = MapGuid;
}
//
// Map found
//
return EFI_SUCCESS;
}
List = List->NextVariablePack;
}
//
// If here, the map is not found
//
return EFI_NOT_FOUND;
}
EFI_STATUS
EfiLibHiiVariablePackListGetMap (
IN EFI_HII_VARIABLE_PACK_LIST *List,
IN CHAR16 *Name,
IN EFI_GUID *Guid,
OUT UINT16 *Id,
OUT VOID **Var,
OUT UINTN *Size
)
/*++
Routine Description:
Finds a variable form EFI_HII_VARIABLE_PACK_LIST given name and GUID.
Arguments:
List - List of variables
Name - Name of the variable/map to be found
Guid - GUID of the variable/map to be found
Var - Pointer to the variable/map found
Size - Size of the variable/map in bytes found
Returns:
EFI_SUCCESS - variable is found, OUT parameters are valid
EFI_NOT_FOUND - variable is not found, OUT parameters are not valid
--*/
{
VOID *Map;
UINTN MapSize;
UINT16 MapId;
CHAR16 *MapName;
EFI_GUID *MapGuid;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
if ((0 == EfiStrCmp (Name, MapName)) && EfiCompareGuid (Guid, MapGuid)) {
*Id = MapId;
*Var = Map;
*Size = MapSize;
return EFI_SUCCESS;
}
List = List->NextVariablePack;
}
//
// If here, the map is not found
//
return EFI_NOT_FOUND;
}
EFI_STATUS
EfiLibHiiVariableRetrieveFromNv (
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN UINTN Size,
OUT VOID **Var
)
/*++
Routine Description:
Finds out if a variable of specific Name/Guid/Size exists in NV.
If it does, it will retrieve it into the Var.
Arguments:
Name, Guid, Size - Parameters of the variable to retrieve. Must match exactly.
Var - Variable will be retrieved into buffer pointed by this pointer.
If pointing to NULL, the buffer will be allocated. Caller is responsible for releasing the buffer.
Returns:
EFI_SUCCESS - The variable of exact Name/Guid/Size parameters was retrieved and written to Var.
EFI_NOT_FOUND - The variable of this Name/Guid was not found in the NV.
EFI_LOAD_ERROR - The variable in the NV was of different size, or NV API returned error.
--*/
{
EFI_STATUS Status;
UINTN SizeNv;
//
// Test for existence of the variable.
//
SizeNv = 0;
Status = gRT->GetVariable (Name, Guid, NULL, &SizeNv, NULL);
if (EFI_BUFFER_TOO_SMALL != Status) {
ASSERT (EFI_SUCCESS != Status);
return EFI_NOT_FOUND;
}
if (SizeNv != Size) {
//
// The variable is considered corrupt, as it has different size from expected.
//
return EFI_LOAD_ERROR;
}
if (NULL == *Var) {
*Var = EfiLibAllocatePool (Size);
ASSERT (NULL != *Var);
}
SizeNv = Size;
//
// Final read into the Var
//
Status = gRT->GetVariable (Name, Guid, NULL, &SizeNv, *Var);
//
// No tolerance for random failures. Such behavior is undetermined and not validated.
//
ASSERT_EFI_ERROR (Status);
ASSERT (SizeNv == Size);
return EFI_SUCCESS;
}
EFI_STATUS
EfiLibHiiVariableOverrideIfSuffix (
IN CHAR16 *Suffix,
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN UINTN Size,
OUT VOID *Var
)
/*++
Routine Description:
Overrrides the variable with NV data if found.
But it only does it if the Name ends with specified Suffix.
For example, if Suffix="MyOverride" and the Name="XyzSetupMyOverride",
the Suffix matches the end of Name, so the variable will be loaded from NV
provided the variable exists and the GUID and Size matches.
Arguments:
Suffix - Suffix the Name should end with.
Name, Guid, Size - Parameters of the variable to retrieve. Must match exactly.
Var - Variable will be retrieved into this buffer.
Caller is responsible for providing storage of exactly Size size in bytes.
Returns:
EFI_SUCCESS - The variable was overriden with NV variable of same Name/Guid/Size.
EFI_INVALID_PARAMETER - The name of the variable does not end with <Suffix>.
EFI_NOT_FOUND - The variable of this Name/Guid was not found in the NV.
EFI_LOAD_ERROR - The variable in the NV was of different size, or NV API returned error.
--*/
{
UINTN StrLen;
UINTN StrLenSuffix;
StrLen = EfiStrLen (Name);
StrLenSuffix = EfiStrLen (Suffix);
if ((StrLen <= StrLenSuffix) || (0 != EfiStrCmp (Suffix, &Name[StrLen - StrLenSuffix]))) {
//
// Not ending with <Suffix>.
//
return EFI_INVALID_PARAMETER;
}
return EfiLibHiiVariableRetrieveFromNv (Name, Guid, Size, &Var);
}
EFI_STATUS
EfiLibHiiVariableOverrideBySuffix (
IN CHAR16 *Suffix,
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN UINTN Size,
OUT VOID *Var
)
/*++
Routine Description:
Overrrides the variable with NV data if found.
But it only does it if the NV contains the same variable with Name is appended with Suffix.
For example, if Suffix="MyOverride" and the Name="XyzSetup",
the Suffix will be appended to the end of Name, and the variable with Name="XyzSetupMyOverride"
will be loaded from NV provided the variable exists and the GUID and Size matches.
Arguments:
Suffix - Suffix the variable will be appended with.
Name, Guid, Size - Parameters of the variable to retrieve. Must match exactly.
Var - Variable will be retrieved into this buffer.
Caller is responsible for providing storage of exactly Size size in bytes.
Returns:
EFI_SUCCESS - The variable was overriden with NV variable of same Name/Guid/Size.
EFI_NOT_FOUND - The variable of this Name/Guid was not found in the NV.
EFI_LOAD_ERROR - The variable in the NV was of different size, or NV API returned error.
--*/
{
EFI_STATUS Status;
CHAR16 *NameSuffixed;
//
// enough to concatenate both strings.
//
NameSuffixed = EfiLibAllocateZeroPool ((EfiStrLen (Name) + EfiStrLen (Suffix) + 1) * sizeof (CHAR16));
EfiStrCpy (NameSuffixed, Name);
EfiStrCat (NameSuffixed, Suffix);
Status = EfiLibHiiVariableRetrieveFromNv (NameSuffixed, Guid, Size, &Var);
gBS->FreePool (NameSuffixed);
return Status;
}

View File

@@ -0,0 +1,597 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiScriptLib.c
Abstract:
Support for EFI script.
--*/
#include "EfiScriptLib.h"
EFI_BOOT_SCRIPT_SAVE_PROTOCOL *mBootScriptSave;
EFI_STATUS
BootScriptSaveInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Intialize Boot Script Lib if it has not yet been initialized.
Arguments:
(Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
// GC_TODO: ImageHandle - add argument and description to function comment
// GC_TODO: SystemTable - add argument and description to function comment
{
EFI_STATUS Status;
EFI_BOOT_SERVICES *BS;
BS = SystemTable->BootServices;
Status = BS->LocateProtocol (&gEfiBootScriptSaveGuid, NULL, &mBootScriptSave);
if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
mBootScriptSave = NULL;
}
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveIoWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI IO write script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Width - add argument and description to function comment
// GC_TODO: Address - add argument and description to function comment
// GC_TODO: Count - add argument and description to function comment
// GC_TODO: Buffer - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_IO_WRITE_OPCODE,
Width,
Address,
Count,
Buffer
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveIoReadWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN VOID *Data,
IN VOID *DataMask
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI IO read write script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Width - add argument and description to function comment
// GC_TODO: Address - add argument and description to function comment
// GC_TODO: Data - add argument and description to function comment
// GC_TODO: DataMask - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE,
Width,
Address,
Data,
DataMask
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveMemWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI MEM write script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Width - add argument and description to function comment
// GC_TODO: Address - add argument and description to function comment
// GC_TODO: Count - add argument and description to function comment
// GC_TODO: Buffer - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE,
Width,
Address,
Count,
Buffer
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveMemReadWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN VOID *Data,
IN VOID *DataMask
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI MEM read write script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Width - add argument and description to function comment
// GC_TODO: Address - add argument and description to function comment
// GC_TODO: Data - add argument and description to function comment
// GC_TODO: DataMask - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE,
Width,
Address,
Data,
DataMask
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSavePciCfgWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI PCI write script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Width - add argument and description to function comment
// GC_TODO: Address - add argument and description to function comment
// GC_TODO: Count - add argument and description to function comment
// GC_TODO: Buffer - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE,
Width,
Address,
Count,
Buffer
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSavePciCfgReadWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN VOID *Data,
IN VOID *DataMask
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI PCI read write script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Width - add argument and description to function comment
// GC_TODO: Address - add argument and description to function comment
// GC_TODO: Data - add argument and description to function comment
// GC_TODO: DataMask - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE,
Width,
Address,
Data,
DataMask
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveSmbusExecute (
IN UINT16 TableName,
IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
IN EFI_SMBUS_DEVICE_COMMAND Command,
IN EFI_SMBUS_OPERATION Operation,
IN BOOLEAN PecCheck,
IN UINTN *Length,
IN VOID *Buffer
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI Smbus execute script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: SlaveAddress - add argument and description to function comment
// GC_TODO: Command - add argument and description to function comment
// GC_TODO: Operation - add argument and description to function comment
// GC_TODO: PecCheck - add argument and description to function comment
// GC_TODO: Length - add argument and description to function comment
// GC_TODO: Buffer - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE,
SlaveAddress,
Command,
Operation,
PecCheck,
Length,
Buffer
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveStall (
IN UINT16 TableName,
IN UINTN Duration
)
/*++
Routine Description:
Save I/O write to boot script
Arguments:
TableName - Desired boot script table
(Standard EFI stall script parameter)
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
// GC_TODO: Duration - add argument and description to function comment
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_STALL_OPCODE,
Duration
);
return EFI_SUCCESS;
}
EFI_STATUS
BootScriptSaveDispatch (
IN UINT16 TableName,
IN EFI_PHYSICAL_ADDRESS EntryPoint
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
TableName - GC_TODO: add argument description
EntryPoint - GC_TODO: add argument description
Returns:
EFI_NOT_FOUND - GC_TODO: Add description for return value
EFI_SUCCESS - GC_TODO: Add description for return value
--*/
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_DISPATCH_OPCODE,
EntryPoint
);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
BootScriptSaveInformation (
IN UINT16 TableName,
IN UINT32 Length,
IN EFI_PHYSICAL_ADDRESS Buffer
)
/*++
Routine Description:
Save a Information Opcode record in table specified with TableName
Arguments:
TableName - Desired boot script table
Length - Length of information in bytes
Buffer - Content of information that will be saved in script table
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
{
if (mBootScriptSave == NULL) {
return EFI_NOT_FOUND;
}
mBootScriptSave->Write (
mBootScriptSave,
TableName,
EFI_BOOT_SCRIPT_INFORMATION_OPCODE,
Length,
Buffer
);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
BootScriptSaveInformationUnicodeString (
IN UINT16 TableName,
IN CHAR16 *String
)
/*++
Routine Description:
Save a Information Opcode record in table specified with TableName, the information
is a unicode string.
Arguments:
TableName - Desired boot script table
String - The string that will be saved in script table
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
{
return BootScriptSaveInformation (
TableName,
(UINT32) EfiStrLen (String) * 2 + 2,
(EFI_PHYSICAL_ADDRESS)String
);
}
EFI_STATUS
EFIAPI
BootScriptSaveInformationAsciiString (
IN UINT16 TableName,
IN CHAR8 *String
)
/*++
Routine Description:
Save a Information Opcode record in table specified with TableName, the information
is a ascii string.
Arguments:
TableName - Desired boot script table
String - The string that will be saved in script table
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
{
return BootScriptSaveInformation (
TableName,
(UINT32) EfiAsciiStrLen (String) + 1,
(EFI_PHYSICAL_ADDRESS)String
);
}

View File

@@ -0,0 +1,46 @@
#/*++
#
# Copyright (c) 2006, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
# Module Name:
#
# EfiScriptLib.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = EfiScriptLib
COMPONENT_TYPE = LIBRARY
[sources.common]
EfiScriptLib.c
[includes.common]
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation\Efi
$(EFI_SOURCE)\Framework
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EFI_SOURCE)
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
EdkFrameworkProtocolLib
[nmake.common]

View File

@@ -0,0 +1,492 @@
/*++
Copyright (c) 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:
EfiUiLib.c
Abstract:
Collection of usefull UI functions.
Revision History:
--*/
#include "EfiUiLib.h"
#define IS_DIGIT(Ch) (((Ch) >= L'0') && ((Ch) <= L'9'))
STATIC
EFI_STATUS
EfiStringToValue (
OUT UINT64 *Val,
IN CHAR16 *String,
OUT UINT8 *EndIdx OPTIONAL
)
/*++
Routine Description:
Parses and converts Unicode string to decimal value.
The returned value is 64-bit.
The string is expected in decimal format,
the string is parsed and format verified.
This function is missing from the libs. One day it maybe
replaced with a lib function when it'll become available.
Arguments:
Val - pointer to the variable to store the value to
String - string that contains the value to parse and convert
EndIdx - index on which the parsing stopped. It points to the
first character that was not part of the returned Val.
It's valid only if the function returns success.
It's optional and it could be NULL.
Returns:
EFI_SUCCESS - if successful
EFI_INVALID_PARAMETER - if String is in unexpected format
--*/
{
UINT8 i;
UINT64 TempVal;
TempVal = 0;
//
// Iterate upto 20 digits, only so many could fit in the UINT64
//
for (i = 0; i <= 20; i++) {
//
// test if the next character is not a digit
//
if (!IS_DIGIT (String[i])) {
//
// If here, there is no more digits,
// return with success if there was at least one to process
//
if (i == 0) {
break;
}
*Val = TempVal;
if (EndIdx != NULL) {
*EndIdx = i;
}
return EFI_SUCCESS;
}
//
// If here, there is a digit to process
//
TempVal = MultU64x32 (TempVal, 10) + String[i] - L'0';
}
//
// if here, there was some sort of format error
//
return EFI_INVALID_PARAMETER;
}
CHAR16 *
StrHzToString (
OUT CHAR16 *String,
IN UINT64 Val
)
/*++
Routine Description:
Converts frequency in Hz to Unicode string.
Three significant digits are delivered.
Used for things like processor info display.
Arguments:
String - string that will contain the frequency.
Val - value to convert, minimum is 100000 i.e., 0.1 MHz.
--*/
// GC_TODO: function comment is missing 'Returns:'
{
CHAR16 HlpStr[8];
UINT32 i;
UINT32 IdxPoint;
UINT32 IdxUnits;
static CHAR16 *FreqUnits[] = { L" Hz", L" kHz", L" MHz", L" GHz", L" THz", L" PHz" };
//
// Normalize to 9999 or less.
//
i = 0;
while (Val >= 10000) {
Val = DivU64x32 (Val, 10, NULL);
i++;
}
//
// Make it rounded to the nearest, but only by
// a .3. This assures that .6 is not rounded.
//
if (Val >= 1000) {
Val += 3;
Val = DivU64x32 (Val, 10, NULL);
i++;
}
EfiValueToString (String, Val, 0, 0);
//
// Get rid of that cursed number!
//
if (!EfiStrCmp (&String[1], L"66")) {
String[2] = L'7';
}
//
// Compute index to the units substrings.
//
IdxUnits = (i + 2) / 3;
if (IdxUnits >= (sizeof (FreqUnits) / sizeof (FreqUnits)[0])) {
//
// Frequency is too high.
//
EfiStrCpy (String, L"OVERFLOW");
return String;
}
//
// Compute the position of the decimal point.
//
IdxPoint = i % 3;
//
// Test if decimal point needs to be inserted.
//
if (IdxPoint != 0) {
//
// Save the part after decimal point.
//
EfiStrCpy (HlpStr, &String[IdxPoint]);
//
// Insert the point.
//
String[IdxPoint] = L'.';
//
// Reattach the saved part.
//
EfiStrCpy (&String[IdxPoint + 1], HlpStr);
//
// Clear the insignificant zero.
//
if (String[3] == L'0') {
String[4 - IdxPoint] = L'\0';
}
}
//
// Attach units.
//
EfiStrCat (String, FreqUnits[IdxUnits]);
return String;
}
CHAR16 *
StrBytesToString (
OUT CHAR16 *String,
IN UINT64 Val
)
/*++
Routine Description:
Converts size in bytes to Unicode string.
Used for memory/cache size display.
Arguments:
String - string that will contain the value
Val - value to convert in bytes
--*/
// GC_TODO: function comment is missing 'Returns:'
{
UINTN i;
UINTN Rem;
static CHAR16 *SizeUnits[] = { L" B", L" kB", L" MB", L" GB", L" TB", L" PB" };
for (i = 0; i < (sizeof (SizeUnits) / sizeof (SizeUnits)[0]); i++) {
DivU64x32 (Val, 1024, &Rem);
//
// Done if:
// 1. less than 1k
// 2. less than 8k and there are fractions of 1k
//
if ((Val < 1024) || ((Val < 8192) && (Rem != 0))) {
EfiValueToString (String, Val, 0, 0);
//
// attach units
//
EfiStrCat (String, SizeUnits[i]);
return String;
}
//
// prescale down by 1k with rounding to the nearest
//
Val = DivU64x32 (Val + 511, 1024, NULL);
}
EfiStrCpy (String, L"OVERFLOW");
return String;
}
CHAR16 *
StrVersionToString (
OUT CHAR16 *String,
IN UINT8 Version
)
/*++
Routine Description:
Converts 8 bit version value to Unicode string.
The upper nibble contains the upper part, the lower nibble contains the minor part.
The output format is <major>.<minor>.
Arguments:
String - string that will contain the value
Version - value to convert
--*/
// GC_TODO: function comment is missing 'Returns:'
{
CHAR16 HlpStr[4];
EfiValueToString (String, 0x0F & Version, 0, 0);
EfiStrCat (String, L".");
EfiValueToString (HlpStr, 0x0F & (Version >> 4), 0, 0);
EfiStrCat (String, HlpStr);
return String;
}
CHAR16 *
StrMacToString (
OUT CHAR16 *String,
IN EFI_MAC_ADDRESS *MacAddr,
IN UINT32 AddrSize
)
/*++
Routine Description:
Converts MAC address to Unicode string.
The value is 64-bit and the resulting string will be 12
digit hex number in pairs of digits separated by dashes.
Arguments:
String - string that will contain the value
Val - value to convert
--*/
// GC_TODO: function comment is missing 'Returns:'
// GC_TODO: MacAddr - add argument and description to function comment
// GC_TODO: AddrSize - add argument and description to function comment
{
UINT32 i;
for (i = 0; i < AddrSize; i++) {
EfiValueToHexStr (
&String[2 * i],
MacAddr->Addr[i] & 0xFF,
PREFIX_ZERO,
2
);
}
//
// Terminate the string.
//
String[2 * AddrSize] = L'\0';
return String;
}
CHAR16 *
StrIp4AdrToString (
OUT CHAR16 *String,
IN EFI_IPv4_ADDRESS *Ip4Addr
)
/*++
Routine Description:
Converts IP v4 address to Unicode string.
The value is 64-bit and the resulting string will
be four decimal values 0-255 separated by dots.
Arguments:
String - string that will contain the value
Ip4Addr - value to convert from
--*/
// GC_TODO: function comment is missing 'Returns:'
{
INT32 i;
CHAR16 HlpStr[4];
String[0] = L'\0';
for (i = 0; i < 4; i++) {
EfiValueToString (HlpStr, Ip4Addr->Addr[i], 0, 0);
EfiStrCat (String, HlpStr);
if (i < 3) {
EfiStrCat (String, L".");
}
}
return String;
}
EFI_STATUS
StrStringToIp4Adr (
OUT EFI_IPv4_ADDRESS *Ip4Addr,
IN CHAR16 *String
)
/*++
Routine Description:
Parses and converts Unicode string to IP v4 address.
The value will 64-bit.
The string must be four decimal values 0-255 separated by dots.
The string is parsed and format verified.
Arguments:
Ip4Addr - pointer to the variable to store the value to
String - string that contains the value to parse and convert
Returns:
EFI_SUCCESS - if successful
EFI_INVALID_PARAMETER - if String contains invalid IP v4 format
--*/
{
EFI_STATUS Status;
EFI_IPv4_ADDRESS RetVal;
UINT64 TempVal;
UINT8 Idx;
UINT8 i;
//
// Iterate the decimal values separated by dots
//
for (i = 0; i < 4; i++) {
//
// get the value of a decimal
//
Status = EfiStringToValue (&TempVal, String, &Idx);
if ((EFI_ERROR (Status)) || (TempVal > 255)) {
break;
}
RetVal.Addr[i] = (UINT8) TempVal;
String += Idx;
//
// test if it is the last decimal value
//
if (i == 3) {
if (String[0] != L'\0') {
//
// the string must end with string termination character
//
break;
}
*Ip4Addr = RetVal;
return EFI_SUCCESS;
}
//
// Test for presence of a dot, it is required between the values
//
if (String++[0] != L'.') {
break;
}
}
return EFI_INVALID_PARAMETER;
}
CHAR16 *
Ascii2Unicode (
OUT CHAR16 *UnicodeStr,
IN CHAR8 *AsciiStr
)
/*++
Routine Description:
Converts ASCII characters to Unicode.
Arguments:
UnicodeStr - the Unicode string to be written to. The buffer must be large enough.
AsciiStr - The ASCII string to be converted.
Returns:
The address to the Unicode string - same as UnicodeStr.
--*/
{
CHAR16 *Str;
Str = UnicodeStr;
while (TRUE) {
*(UnicodeStr++) = (CHAR16) *AsciiStr;
if (*(AsciiStr++) == '\0') {
return Str;
}
}
}
CHAR8 *
Unicode2Ascii (
OUT CHAR8 *AsciiStr,
IN CHAR16 *UnicodeStr
)
/*++
Routine Description:
Converts ASCII characters to Unicode.
Assumes that the Unicode characters are only these defined in the ASCII set.
Arguments:
AsciiStr - The ASCII string to be written to. The buffer must be large enough.
UnicodeStr - the Unicode string to be converted.
Returns:
The address to the ASCII string - same as AsciiStr.
--*/
{
CHAR8 *Str;
Str = AsciiStr;
while (TRUE) {
*AsciiStr = (CHAR8) *(UnicodeStr++);
if (*(AsciiStr++) == '\0') {
return Str;
}
}
}

View File

@@ -0,0 +1,43 @@
#/*++
#
# Copyright (c) 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:
#
# EfiUiLib.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = EfiUiLib
COMPONENT_TYPE = LIBRARY
[sources.common]
EfiUiLib.c
[includes.common]
$(EDK_SOURCE)\Foundation\Efi
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
[nmake.common]

View File

@@ -0,0 +1,88 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Ascii
STRING_W is ""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR8 CHAR_W;
#define STRING_W(_s) _s
#define ASPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define AvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
UINTN
UvSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN StrLen,
IN CONST CHAR16 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
StartOfBuffer - Wide char buffer to print the results of the parsing of Format into.
StrLen - Maximum number of characters to put into buffer.
Format - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
UvSPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
AsciiFormat[Index] = (CHAR8) FormatString[Index];
}
AsciiFormat[Index] = '\0';
Index = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR16) AsciiResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,619 @@
/*++
Copyright (c) 2004 - 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:
Graphics.c
Abstract:
Support for Basic Graphics operations.
BugBug: Currently *.BMP files are supported. This will be replaced
when Tiano graphics format is supported.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "GraphicsLib.h"
EFI_STATUS
GetGraphicsBitMapFromFV (
IN EFI_GUID *FileNameGuid,
OUT VOID **Image,
OUT UINTN *ImageSize
)
/*++
Routine Description:
Return the graphics image file named FileNameGuid into Image and return it's
size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
file name.
Arguments:
FileNameGuid - File Name of graphics file in the FV(s).
Image - Pointer to pointer to return graphics image. If NULL, a
buffer will be allocated.
ImageSize - Size of the graphics Image in bytes. Zero if no image found.
Returns:
EFI_SUCCESS - Image and ImageSize are valid.
EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
EFI_NOT_FOUND - FileNameGuid not found
--*/
{
return GetGraphicsBitMapFromFVEx (NULL, FileNameGuid, Image, ImageSize);
}
EFI_STATUS
GetGraphicsBitMapFromFVEx (
IN EFI_HANDLE ImageHandle,
IN EFI_GUID *FileNameGuid,
OUT VOID **Image,
OUT UINTN *ImageSize
)
/*++
Routine Description:
Return the graphics image file named FileNameGuid into Image and return it's
size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
file name.
Arguments:
ImageHandle - The driver image handle of the caller. The parameter is used to
optimize the loading of the image file so that the FV from which
the driver image is loaded will be tried first.
FileNameGuid - File Name of graphics file in the FV(s).
Image - Pointer to pointer to return graphics image. If NULL, a
buffer will be allocated.
ImageSize - Size of the graphics Image in bytes. Zero if no image found.
Returns:
EFI_SUCCESS - Image and ImageSize are valid.
EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
EFI_NOT_FOUND - FileNameGuid not found
--*/
{
return GetImageEx (
ImageHandle,
&gEfiDefaultBmpLogoGuid,
EFI_SECTION_RAW,
Image,
ImageSize,
FALSE
);
}
EFI_STATUS
ConvertBmpToGopBlt (
IN VOID *BmpImage,
IN UINTN BmpImageSize,
IN OUT VOID **GopBlt,
IN OUT UINTN *GopBltSize,
OUT UINTN *PixelHeight,
OUT UINTN *PixelWidth
)
/*++
Routine Description:
Convert a *.BMP graphics image to a GOP/UGA 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.
Arguments:
BmpImage - Pointer to BMP file
BmpImageSize - Number of bytes in BmpImage
GopBlt - Buffer containing GOP version of BmpImage.
GopBltSize - Size of GopBlt in bytes.
PixelHeight - Height of GopBlt/BmpImage in pixels
PixelWidth - Width of GopBlt/BmpImage in pixels
Returns:
EFI_SUCCESS - GopBlt and GopBltSize are returned.
EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
EFI_BUFFER_TOO_SMALL - The passed in GopBlt buffer is not big enough.
GopBltSize will contain the required size.
EFI_OUT_OF_RESOURCES - No enough buffer to allocate
--*/
{
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;
}
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;
BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
IsAllocated = FALSE;
if (*GopBlt == NULL) {
*GopBltSize = BltBufferSize;
*GopBlt = EfiLibAllocatePool (*GopBltSize);
IsAllocated = TRUE;
if (*GopBlt == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
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 1bit 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 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 BMP Palette to 24-bit color
//
Blt->Red = BmpColorMap[*Image].Red;
Blt->Green = BmpColorMap[*Image].Green;
Blt->Blue = BmpColorMap[*Image].Blue;
break;
case 24:
Blt->Blue = *Image++;
Blt->Green = *Image++;
Blt->Red = *Image;
break;
default:
if (IsAllocated) {
gBS->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;
}
EFI_STATUS
LockKeyboards (
IN CHAR16 *Password
)
/*++
Routine Description:
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.
Arguments:
Password - Password used to lock ConIn device
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
{
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;
}
EFI_STATUS
EnableQuietBoot (
IN EFI_GUID *LogoFile
)
/*++
Routine Description:
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
Arguments:
LogoFile - File name of logo to display on the center of the screen.
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
{
return EnableQuietBootEx (LogoFile, NULL);
}
EFI_STATUS
EnableQuietBootEx (
IN EFI_GUID *LogoFile,
IN EFI_HANDLE ImageHandle
)
/*++
Routine Description:
Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
Arguments:
LogoFile - File name of logo to display on the center of the screen.
ImageHandle - The driver image handle of the caller. The parameter is used to
optimize the loading of the logo file so that the FV from which
the driver image is loaded will be tried first.
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
{
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)) {
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);
ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);
if (GraphicsOutput != NULL) {
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
} else {
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
}
Instance = 0;
while (1) {
ImageData = NULL;
ImageSize = 0;
if (Badging != NULL) {
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) {
gBS->FreePool (ImageData);
continue;
}
} else {
Status = GetGraphicsBitMapFromFVEx (ImageHandle, LogoFile, &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)) {
gBS->FreePool (ImageData);
if (Badging == NULL) {
return Status;
} else {
continue;
}
}
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 {
Status = UgaDraw->Blt (
UgaDraw,
(EFI_UGA_PIXEL *) Blt,
EfiUgaBltBufferToVideo,
0,
0,
(UINTN) DestX,
(UINTN) DestY,
Width,
Height,
Width * sizeof (EFI_UGA_PIXEL)
);
}
}
gBS->FreePool (ImageData);
gBS->FreePool (Blt);
if (Badging == NULL) {
break;
}
}
return Status;
}
EFI_STATUS
DisableQuietBoot (
VOID
)
/*++
Routine Description:
Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
Simple Text Out screens will now be synced up with all non GOP/UGA output devices
Arguments:
NONE
Returns:
EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
EFI_UNSUPPORTED - Logo not found
--*/
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);
}

View File

@@ -0,0 +1,50 @@
#/*++
#
# Copyright (c) 2004, 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:
#
# Graphics.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = Graphics
COMPONENT_TYPE = LIBRARY
[sources.common]
Graphics.c
Print.c
Print.h
Unicode\PrintWidth.h
Unicode\Sprint.c
[includes.common]
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Efi
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Library\Dxe\Graphics\Unicode
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
EfiDriverLib
[nmake.common]

View File

@@ -0,0 +1,889 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Print.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "TianoCommon.h"
#include "EfiCommonLib.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
#include EFI_PROTOCOL_DEFINITION (Hii)
STATIC
CHAR_W *
GetFlagsAndWidth (
IN CHAR_W *Format,
OUT UINTN *Flags,
OUT UINTN *Width,
IN OUT VA_LIST *Marker
);
STATIC
UINTN
GuidToString (
IN EFI_GUID *Guid,
IN OUT CHAR_W *Buffer,
IN UINTN BufferSize
);
STATIC
UINTN
TimeToString (
IN EFI_TIME *Time,
IN OUT CHAR_W *Buffer,
IN UINTN BufferSize
);
STATIC
UINTN
EfiStatusToString (
IN EFI_STATUS Status,
OUT CHAR_W *Buffer,
IN UINTN BufferSize
);
static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
0x00, 0x00, 0x00, 0x00,
0x98, 0x00, 0x00, 0x00,
0x00, 0x98, 0x00, 0x00,
0x98, 0x98, 0x00, 0x00,
0x00, 0x00, 0x98, 0x00,
0x98, 0x00, 0x98, 0x00,
0x00, 0x98, 0x98, 0x00,
0x98, 0x98, 0x98, 0x00,
0x10, 0x10, 0x10, 0x00,
0xff, 0x10, 0x10, 0x00,
0x10, 0xff, 0x10, 0x00,
0xff, 0xff, 0x10, 0x00,
0x10, 0x10, 0xff, 0x00,
0xf0, 0x10, 0xff, 0x00,
0x10, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0x00,
};
UINTN
_IPrint (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto,
IN UINTN X,
IN UINTN Y,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,
IN CHAR16 *fmt,
IN VA_LIST args
)
/*++
Routine Description:
Display string worker for: Print, PrintAt, IPrint, IPrintAt
Arguments:
GraphicsOutput - Graphics output protocol interface
UgaDraw - UGA draw protocol interface
Sto - Simple text out protocol interface
X - X coordinate to start printing
Y - Y coordinate to start printing
Foreground - Foreground color
Background - Background color
fmt - Format string
args - Print arguments
Returns:
EFI_SUCCESS - success
EFI_OUT_OF_RESOURCES - out of resources
--*/
{
VOID *Buffer;
EFI_STATUS Status;
UINT16 GlyphWidth;
UINT32 GlyphStatus;
UINT16 StringIndex;
UINTN Index;
CHAR16 *UnicodeWeight;
EFI_NARROW_GLYPH *Glyph;
EFI_HII_PROTOCOL *Hii;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINT32 ColorDepth;
UINT32 RefreshRate;
UINTN BufferLen;
UINTN LineBufferLen;
GlyphStatus = 0;
//
// For now, allocate an arbitrarily long buffer
//
Buffer = EfiLibAllocateZeroPool (0x10000);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (GraphicsOutput != NULL) {
HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
} else {
UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);
}
ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));
LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_HEIGHT;
LineBuffer = EfiLibAllocatePool (LineBufferLen);
if (LineBuffer == NULL) {
gBS->FreePool (Buffer);
return EFI_OUT_OF_RESOURCES;
}
Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID**)&Hii);
if (EFI_ERROR (Status)) {
goto Error;
}
VSPrint (Buffer, 0x10000, fmt, args);
UnicodeWeight = (CHAR16 *) Buffer;
for (Index = 0; UnicodeWeight[Index] != 0; Index++) {
if (UnicodeWeight[Index] == CHAR_BACKSPACE ||
UnicodeWeight[Index] == CHAR_LINEFEED ||
UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {
UnicodeWeight[Index] = 0;
}
}
BufferLen = EfiStrLen (Buffer);
if (GLYPH_WIDTH * GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {
Status = EFI_INVALID_PARAMETER;
goto Error;
}
for (Index = 0; Index < BufferLen; Index++) {
StringIndex = (UINT16) Index;
Status = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);
if (EFI_ERROR (Status)) {
goto Error;
}
if (Foreground == NULL || Background == NULL) {
Status = Hii->GlyphToBlt (
Hii,
(UINT8 *) Glyph,
mEfiColors[Sto->Mode->Attribute & 0x0f],
mEfiColors[Sto->Mode->Attribute >> 4],
BufferLen,
GlyphWidth,
GLYPH_HEIGHT,
&LineBuffer[Index * GLYPH_WIDTH]
);
} else {
Status = Hii->GlyphToBlt (
Hii,
(UINT8 *) Glyph,
*Foreground,
*Background,
BufferLen,
GlyphWidth,
GLYPH_HEIGHT,
&LineBuffer[Index * GLYPH_WIDTH]
);
}
}
//
// Blt a character to the screen
//
if (GraphicsOutput != NULL) {
Status = GraphicsOutput->Blt (
GraphicsOutput,
LineBuffer,
EfiBltBufferToVideo,
0,
0,
X,
Y,
GLYPH_WIDTH * BufferLen,
GLYPH_HEIGHT,
GLYPH_WIDTH * BufferLen * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
} else {
Status = UgaDraw->Blt (
UgaDraw,
(EFI_UGA_PIXEL *) LineBuffer,
EfiUgaBltBufferToVideo,
0,
0,
X,
Y,
GLYPH_WIDTH * BufferLen,
GLYPH_HEIGHT,
GLYPH_WIDTH * BufferLen * sizeof (EFI_UGA_PIXEL)
);
}
Error:
gBS->FreePool (LineBuffer);
gBS->FreePool (Buffer);
return Status;
}
UINTN
PrintXY (
IN UINTN X,
IN UINTN Y,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL
IN CHAR_W *Fmt,
...
)
/*++
Routine Description:
Prints a formatted unicode string to the default console
Arguments:
X - X coordinate to start printing
Y - Y coordinate to start printing
ForeGround - Foreground color
BackGround - Background color
Fmt - Format string
... - Print arguments
Returns:
Length of string printed to the console
--*/
{
EFI_HANDLE Handle;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto;
EFI_STATUS Status;
VA_LIST Args;
VA_START (Args, Fmt);
Handle = gST->ConsoleOutHandle;
Status = gBS->HandleProtocol (
Handle,
&gEfiGraphicsOutputProtocolGuid,
(VOID**)&GraphicsOutput
);
UgaDraw = NULL;
if (EFI_ERROR (Status)) {
GraphicsOutput = NULL;
Status = gBS->HandleProtocol (
Handle,
&gEfiUgaDrawProtocolGuid,
(VOID**)&UgaDraw
);
if (EFI_ERROR (Status)) {
return Status;
}
}
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleTextOutProtocolGuid,
(VOID**)&Sto
);
if (EFI_ERROR (Status)) {
return Status;
}
return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);
}
UINTN
SPrint (
OUT CHAR_W *Buffer,
IN UINTN BufferSize,
IN CONST CHAR_W *Format,
...
)
/*++
Routine Description:
SPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = VSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
VSPrint (
OUT CHAR_W *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR_W *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
VSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine
Arguments:
StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means
no limit.
FormatString - Unicode format string see file header for more details.
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
CHAR_W *Buffer;
CHAR8 *AsciiStr;
CHAR16 *UnicodeStr;
CHAR_W *Format;
UINTN Index;
UINTN Flags;
UINTN Width;
UINTN Count;
UINTN NumberOfCharacters;
UINTN BufferLeft;
UINT64 Value;
EFI_GUID *TmpGUID;
//
// Process the format string. Stop if Buffer is over run.
//
Buffer = StartOfBuffer;
Format = (CHAR_W *) FormatString;
NumberOfCharacters = BufferSize / sizeof (CHAR_W);
BufferLeft = BufferSize;
for (Index = 0; (*Format != '\0') && (Index < NumberOfCharacters - 1); Format++) {
if (*Format != '%') {
if ((*Format == '\n') && (Index < NumberOfCharacters - 2)) {
//
// If carage return add line feed
//
Buffer[Index++] = '\r';
BufferLeft -= sizeof (CHAR_W);
}
Buffer[Index++] = *Format;
BufferLeft -= sizeof (CHAR_W);
} else {
//
// Now it's time to parse what follows after %
//
Format = GetFlagsAndWidth (Format, &Flags, &Width, &Marker);
switch (*Format) {
case 'X':
Flags |= PREFIX_ZERO;
Width = sizeof (UINT64) * 2;
//
// break skiped on purpose
//
case 'x':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = VA_ARG (Marker, UINTN);
}
EfiValueToHexStr (TempBuffer, Value, Flags, Width);
UnicodeStr = TempBuffer;
for (; (*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) {
Buffer[Index++] = *UnicodeStr;
}
break;
case 'd':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = (UINTN) VA_ARG (Marker, UINTN);
}
EfiValueToString (TempBuffer, Value, Flags, Width);
UnicodeStr = TempBuffer;
for (; (*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) {
Buffer[Index++] = *UnicodeStr;
}
break;
case 's':
case 'S':
UnicodeStr = (CHAR16 *) VA_ARG (Marker, CHAR_W *);
if (UnicodeStr == NULL) {
UnicodeStr = L"<null string>";
}
for (Count = 0; (*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++, Count++) {
Buffer[Index++] = *UnicodeStr;
}
//
// Add padding if needed
//
for (; (Count < Width) && (Index < NumberOfCharacters - 1); Count++) {
Buffer[Index++] = ' ';
}
break;
case 'a':
AsciiStr = (CHAR8 *) VA_ARG (Marker, CHAR8 *);
if (AsciiStr == NULL) {
AsciiStr = "<null string>";
}
for (Count = 0; (*AsciiStr != '\0') && (Index < NumberOfCharacters - 1); AsciiStr++, Count++) {
Buffer[Index++] = (CHAR_W) * AsciiStr;
}
//
// Add padding if needed
//
for (; (Count < Width) && (Index < NumberOfCharacters - 1); Count++) {
Buffer[Index++] = ' ';
}
break;
case 'c':
Buffer[Index++] = (CHAR_W) VA_ARG (Marker, UINTN);
break;
case 'g':
TmpGUID = VA_ARG (Marker, EFI_GUID *);
if (TmpGUID != NULL) {
Index += GuidToString (
TmpGUID,
&Buffer[Index],
BufferLeft
);
}
break;
case 't':
Index += TimeToString (
VA_ARG (Marker, EFI_TIME *),
&Buffer[Index],
BufferLeft
);
break;
case 'r':
Index += EfiStatusToString (
VA_ARG (Marker, EFI_STATUS),
&Buffer[Index],
BufferLeft
);
break;
case '%':
Buffer[Index++] = *Format;
break;
default:
//
// if the type is unknown print it to the screen
//
Buffer[Index++] = *Format;
}
BufferLeft = BufferSize - Index * sizeof (CHAR_W);
}
}
Buffer[Index++] = '\0';
return &Buffer[Index] - StartOfBuffer;
}
STATIC
CHAR_W *
GetFlagsAndWidth (
IN CHAR_W *Format,
OUT UINTN *Flags,
OUT UINTN *Width,
IN OUT VA_LIST *Marker
)
/*++
Routine Description:
VSPrint worker function that parses flag and width information from the
Format string and returns the next index into the Format string that needs
to be parsed. See file headed for details of Flag and Width.
Arguments:
Format - Current location in the VSPrint format string.
Flags - Returns flags
Width - Returns width of element
Marker - Vararg list that may be paritally consumed and returned.
Returns:
Pointer indexed into the Format string for all the information parsed
by this routine.
--*/
{
UINTN Count;
BOOLEAN Done;
*Flags = 0;
*Width = 0;
for (Done = FALSE; !Done;) {
Format++;
switch (*Format) {
case '-':
*Flags |= LEFT_JUSTIFY;
break;
case '+':
*Flags |= PREFIX_SIGN;
break;
case ' ':
*Flags |= PREFIX_BLANK;
break;
case ',':
*Flags |= COMMA_TYPE;
break;
case 'L':
case 'l':
*Flags |= LONG_TYPE;
break;
case '*':
*Width = VA_ARG (*Marker, UINTN);
break;
case '0':
*Flags |= PREFIX_ZERO;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
Count = 0;
do {
Count = (Count * 10) +*Format - '0';
Format++;
} while ((*Format >= '0') && (*Format <= '9'));
Format--;
*Width = Count;
break;
default:
Done = TRUE;
}
}
return Format;
}
STATIC
UINTN
GuidToString (
IN EFI_GUID *Guid,
IN CHAR_W *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
VSPrint worker function that prints an EFI_GUID.
Arguments:
Guid - Pointer to GUID to print.
Buffer - Buffe to print Guid into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
Size = SPrint (
Buffer,
BufferSize,
STRING_W ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
(UINTN)Guid->Data1,
(UINTN)Guid->Data2,
(UINTN)Guid->Data3,
(UINTN)Guid->Data4[0],
(UINTN)Guid->Data4[1],
(UINTN)Guid->Data4[2],
(UINTN)Guid->Data4[3],
(UINTN)Guid->Data4[4],
(UINTN)Guid->Data4[5],
(UINTN)Guid->Data4[6],
(UINTN)Guid->Data4[7]
);
//
// SPrint will null terminate the string. The -1 skips the null
//
return Size - 1;
}
STATIC
UINTN
TimeToString (
IN EFI_TIME *Time,
OUT CHAR_W *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
VSPrint worker function that prints EFI_TIME.
Arguments:
Time - Pointer to EFI_TIME sturcture to print.
Buffer - Buffer to print Time into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
Size = SPrint (
Buffer,
BufferSize,
STRING_W ("%02d/%02d/%04d %02d:%02d"),
(UINTN)Time->Month,
(UINTN)Time->Day,
(UINTN)Time->Year,
(UINTN)Time->Hour,
(UINTN)Time->Minute
);
//
// SPrint will null terminate the string. The -1 skips the null
//
return Size - 1;
}
STATIC
UINTN
EfiStatusToString (
IN EFI_STATUS Status,
OUT CHAR_W *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
VSPrint worker function that prints EFI_STATUS as a string. If string is
not known a hex value will be printed.
Arguments:
Status - EFI_STATUS sturcture to print.
Buffer - Buffer to print EFI_STATUS message string into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
CHAR8 *Desc;
Desc = NULL;
//
// Can't use global Status String Array as UINTN is not constant for EBC
//
if (Status == EFI_SUCCESS) { Desc = "Success"; } else
if (Status == EFI_LOAD_ERROR) { Desc = "Load Error"; } else
if (Status == EFI_INVALID_PARAMETER) { Desc = "Invalid Parameter"; } else
if (Status == EFI_UNSUPPORTED) { Desc = "Unsupported"; } else
if (Status == EFI_BAD_BUFFER_SIZE) { Desc = "Bad Buffer Size"; } else
if (Status == EFI_BUFFER_TOO_SMALL) { Desc = "Buffer Too Small"; } else
if (Status == EFI_NOT_READY) { Desc = "Not Ready"; } else
if (Status == EFI_DEVICE_ERROR) { Desc = "Device Error"; } else
if (Status == EFI_WRITE_PROTECTED) { Desc = "Write Protected"; } else
if (Status == EFI_OUT_OF_RESOURCES) { Desc = "Out of Resources"; } else
if (Status == EFI_VOLUME_CORRUPTED) { Desc = "Volume Corrupt"; } else
if (Status == EFI_VOLUME_FULL) { Desc = "Volume Full"; } else
if (Status == EFI_NO_MEDIA) { Desc = "No Media"; } else
if (Status == EFI_MEDIA_CHANGED) { Desc = "Media changed"; } else
if (Status == EFI_NOT_FOUND) { Desc = "Not Found"; } else
if (Status == EFI_ACCESS_DENIED) { Desc = "Access Denied"; } else
if (Status == EFI_NO_RESPONSE) { Desc = "No Response"; } else
if (Status == EFI_NO_MAPPING) { Desc = "No mapping"; } else
if (Status == EFI_TIMEOUT) { Desc = "Time out"; } else
if (Status == EFI_NOT_STARTED) { Desc = "Not started"; } else
if (Status == EFI_ALREADY_STARTED) { Desc = "Already started"; } else
if (Status == EFI_ABORTED) { Desc = "Aborted"; } else
if (Status == EFI_ICMP_ERROR) { Desc = "ICMP Error"; } else
if (Status == EFI_TFTP_ERROR) { Desc = "TFTP Error"; } else
if (Status == EFI_PROTOCOL_ERROR) { Desc = "Protocol Error"; } else
if (Status == EFI_WARN_UNKNOWN_GLYPH) { Desc = "Warning Unknown Glyph"; } else
if (Status == EFI_WARN_DELETE_FAILURE) { Desc = "Warning Delete Failure"; } else
if (Status == EFI_WARN_WRITE_FAILURE) { Desc = "Warning Write Failure"; } else
if (Status == EFI_WARN_BUFFER_TOO_SMALL) { Desc = "Warning Buffer Too Small"; }
//
// If we found a match, copy the message to the user's buffer. Otherwise
// sprint the hex status code to their buffer.
//
if (Desc != NULL) {
Size = SPrint (Buffer, BufferSize, STRING_W ("%a"), Desc);
} else {
Size = SPrint (Buffer, BufferSize, STRING_W ("%X"), Status);
}
return Size - 1;
}

View File

@@ -0,0 +1,37 @@
/*++
Copyright (c) 2004, 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:
Print.h
Abstract:
Private data for Print.c
--*/
#ifndef _PRINT_H_
#define _PRINT_H_
#define LEFT_JUSTIFY 0x01
#define PREFIX_SIGN 0x02
#define PREFIX_BLANK 0x04
#define COMMA_TYPE 0x08
#define LONG_TYPE 0x10
#define PREFIX_ZERO 0x20
//
// Largest number of characters that can be printed out.
//
#define EFI_DRIVER_LIB_MAX_PRINT_BUFFER (80 * 4)
#endif

View File

@@ -0,0 +1,34 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Unicode
STRING_W is L""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR16 CHAR_W;
#define STRING_W(_s) L##_s
#define USPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define UvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
#include "EfiCommonLib.h"
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
ASPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = AvSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
AvSPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of ASPrint.
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
}
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,88 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Ascii
STRING_W is ""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR8 CHAR_W;
#define STRING_W(_s) _s
#define ASPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define AvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
UINTN
UvSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN StrLen,
IN CONST CHAR16 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
StartOfBuffer - Wide char buffer to print the results of the parsing of Format into.
StrLen - Maximum number of characters to put into buffer.
Format - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
UvSPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
AsciiFormat[Index] = (CHAR8) FormatString[Index];
}
AsciiFormat[Index] = '\0';
Index = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR16) AsciiResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,618 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Graphics.c
Abstract:
Support for Basic Graphics operations.
BugBug: Currently *.BMP files are supported. This will be replaced
when Tiano graphics format is supported.
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "GraphicsLib.h"
EFI_STATUS
GetGraphicsBitMapFromFV (
IN EFI_GUID *FileNameGuid,
OUT VOID **Image,
OUT UINTN *ImageSize
)
/*++
Routine Description:
Return the graphics image file named FileNameGuid into Image and return it's
size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
file name.
Arguments:
FileNameGuid - File Name of graphics file in the FV(s).
Image - Pointer to pointer to return graphics image. If NULL, a
buffer will be allocated.
ImageSize - Size of the graphics Image in bytes. Zero if no image found.
Returns:
EFI_SUCCESS - Image and ImageSize are valid.
EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
EFI_NOT_FOUND - FileNameGuid not found
--*/
{
return GetGraphicsBitMapFromFVEx (NULL, FileNameGuid, Image, ImageSize);
}
EFI_STATUS
GetGraphicsBitMapFromFVEx (
IN EFI_HANDLE ImageHandle,
IN EFI_GUID *FileNameGuid,
OUT VOID **Image,
OUT UINTN *ImageSize
)
/*++
Routine Description:
Return the graphics image file named FileNameGuid into Image and return it's
size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
file name.
Arguments:
ImageHandle - The driver image handle of the caller. The parameter is used to
optimize the loading of the image file so that the FV from which
the driver image is loaded will be tried first.
FileNameGuid - File Name of graphics file in the FV(s).
Image - Pointer to pointer to return graphics image. If NULL, a
buffer will be allocated.
ImageSize - Size of the graphics Image in bytes. Zero if no image found.
Returns:
EFI_SUCCESS - Image and ImageSize are valid.
EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
EFI_NOT_FOUND - FileNameGuid not found
--*/
{
return GetImageEx (
ImageHandle,
&gEfiDefaultBmpLogoGuid,
EFI_SECTION_RAW,
Image,
ImageSize,
FALSE
);
}
EFI_STATUS
ConvertBmpToGopBlt (
IN VOID *BmpImage,
IN UINTN BmpImageSize,
IN OUT VOID **GopBlt,
IN OUT UINTN *GopBltSize,
OUT UINTN *PixelHeight,
OUT UINTN *PixelWidth
)
/*++
Routine Description:
Convert a *.BMP graphics image to a GOP/UGA 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.
Arguments:
BmpImage - Pointer to BMP file
BmpImageSize - Number of bytes in BmpImage
GopBlt - Buffer containing GOP version of BmpImage.
GopBltSize - Size of GopBlt in bytes.
PixelHeight - Height of GopBlt/BmpImage in pixels
PixelWidth - Width of GopBlt/BmpImage in pixels
Returns:
EFI_SUCCESS - GopBlt and GopBltSize are returned.
EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
EFI_BUFFER_TOO_SMALL - The passed in GopBlt buffer is not big enough.
GopBltSize will contain the required size.
EFI_OUT_OF_RESOURCES - No enough buffer to allocate
--*/
{
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;
}
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;
BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
IsAllocated = FALSE;
if (*GopBlt == NULL) {
*GopBltSize = BltBufferSize;
*GopBlt = EfiLibAllocatePool (*GopBltSize);
IsAllocated = TRUE;
if (*GopBlt == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
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 1bit 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 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 BMP Palette to 24-bit color
//
Blt->Red = BmpColorMap[*Image].Red;
Blt->Green = BmpColorMap[*Image].Green;
Blt->Blue = BmpColorMap[*Image].Blue;
break;
case 24:
Blt->Blue = *Image++;
Blt->Green = *Image++;
Blt->Red = *Image;
break;
default:
if (IsAllocated) {
gBS->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;
}
EFI_STATUS
LockKeyboards (
IN CHAR16 *Password
)
/*++
Routine Description:
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.
Arguments:
Password - Password used to lock ConIn device
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, &ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Status = ConsoleControl->LockStdIn (ConsoleControl, Password);
return Status;
}
EFI_STATUS
EnableQuietBoot (
IN EFI_GUID *LogoFile
)
/*++
Routine Description:
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
Arguments:
LogoFile - File name of logo to display on the center of the screen.
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
{
return EnableQuietBootEx (LogoFile, NULL);
}
EFI_STATUS
EnableQuietBootEx (
IN EFI_GUID *LogoFile,
IN EFI_HANDLE ImageHandle
)
/*++
Routine Description:
Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
Arguments:
LogoFile - File name of logo to display on the center of the screen.
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
{
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, &ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
UgaDraw = NULL;
//
// Try to open GOP first
//
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, &GraphicsOutput);
if (EFI_ERROR (Status)) {
GraphicsOutput = NULL;
//
// Open GOP failed, try to open UGA
//
Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, &UgaDraw);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
}
Badging = NULL;
Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, &Badging);
ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);
if (GraphicsOutput != NULL) {
SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
} else {
Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
}
Instance = 0;
while (1) {
ImageData = NULL;
ImageSize = 0;
if (Badging != NULL) {
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) {
gBS->FreePool (ImageData);
continue;
}
} else {
Status = GetGraphicsBitMapFromFVEx (ImageHandle, LogoFile, &ImageData, &ImageSize);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
CoordinateX = 0;
CoordinateY = 0;
Attribute = EfiBadgingDisplayAttributeCenter;
}
Blt = NULL;
Status = ConvertBmpToGopBlt (
ImageData,
ImageSize,
&Blt,
&BltSize,
&Height,
&Width
);
if (EFI_ERROR (Status)) {
gBS->FreePool (ImageData);
if (Badging == NULL) {
return Status;
} else {
continue;
}
}
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 {
Status = UgaDraw->Blt (
UgaDraw,
(EFI_UGA_PIXEL *) Blt,
EfiUgaBltBufferToVideo,
0,
0,
(UINTN) DestX,
(UINTN) DestY,
Width,
Height,
Width * sizeof (EFI_UGA_PIXEL)
);
}
}
gBS->FreePool (ImageData);
gBS->FreePool (Blt);
if (Badging == NULL) {
break;
}
}
return Status;
}
EFI_STATUS
DisableQuietBoot (
VOID
)
/*++
Routine Description:
Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
Simple Text Out screens will now be synced up with all non GOP/UGA output devices
Arguments:
NONE
Returns:
EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
EFI_UNSUPPORTED - Logo not found
--*/
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, &ConsoleControl);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);
}

View File

@@ -0,0 +1,50 @@
#/*++
#
# Copyright (c) 2004, 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:
#
# Graphics.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = GraphicsLite
COMPONENT_TYPE = LIBRARY
[sources.common]
Graphics.c
Print.c
Print.h
Unicode\PrintWidth.h
Unicode\Sprint.c
[includes.common]
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Efi
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Library\Dxe\Graphics\Unicode
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
EfiDriverLib
[nmake.common]

View File

@@ -0,0 +1,436 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Print.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "TianoCommon.h"
#include "EfiCommonLib.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
#include EFI_PROTOCOL_DEFINITION (Hii)
static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
0x00, 0x00, 0x00, 0x00,
0x98, 0x00, 0x00, 0x00,
0x00, 0x98, 0x00, 0x00,
0x98, 0x98, 0x00, 0x00,
0x00, 0x00, 0x98, 0x00,
0x98, 0x00, 0x98, 0x00,
0x00, 0x98, 0x98, 0x00,
0x98, 0x98, 0x98, 0x00,
0x10, 0x10, 0x10, 0x00,
0xff, 0x10, 0x10, 0x00,
0x10, 0xff, 0x10, 0x00,
0xff, 0xff, 0x10, 0x00,
0x10, 0x10, 0xff, 0x00,
0xf0, 0x10, 0xff, 0x00,
0x10, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0x00,
};
UINTN
_IPrint (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,
IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto,
IN UINTN X,
IN UINTN Y,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,
IN CHAR16 *fmt,
IN VA_LIST args
)
/*++
Routine Description:
Display string worker for: Print, PrintAt, IPrint, IPrintAt
Arguments:
GraphicsOutput - Graphics output protocol interface
UgaDraw - UGA draw protocol interface
Sto - Simple text out protocol interface
X - X coordinate to start printing
Y - Y coordinate to start printing
Foreground - Foreground color
Background - Background color
fmt - Format string
args - Print arguments
Returns:
EFI_SUCCESS - success
EFI_OUT_OF_RESOURCES - out of resources
--*/
{
VOID *Buffer;
EFI_STATUS Status;
UINT16 GlyphWidth;
UINT32 GlyphStatus;
UINT16 StringIndex;
UINTN Index;
CHAR16 *UnicodeWeight;
EFI_NARROW_GLYPH *Glyph;
EFI_HII_PROTOCOL *Hii;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINT32 ColorDepth;
UINT32 RefreshRate;
UINTN BufferLen;
UINTN LineBufferLen;
GlyphStatus = 0;
//
// For now, allocate an arbitrarily long buffer
//
Buffer = EfiLibAllocateZeroPool (0x10000);
if (Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (GraphicsOutput != NULL) {
HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
} else {
UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);
}
ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));
LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_HEIGHT;
LineBuffer = EfiLibAllocatePool (LineBufferLen);
if (LineBuffer == NULL) {
gBS->FreePool (Buffer);
return EFI_OUT_OF_RESOURCES;
}
Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, &Hii);
if (EFI_ERROR (Status)) {
goto Error;
}
VSPrint (Buffer, 0x10000, fmt, args);
UnicodeWeight = (CHAR16 *) Buffer;
for (Index = 0; UnicodeWeight[Index] != 0; Index++) {
if (UnicodeWeight[Index] == CHAR_BACKSPACE ||
UnicodeWeight[Index] == CHAR_LINEFEED ||
UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {
UnicodeWeight[Index] = 0;
}
}
BufferLen = EfiStrLen (Buffer);
if (GLYPH_WIDTH * GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {
Status = EFI_INVALID_PARAMETER;
goto Error;
}
for (Index = 0; Index < BufferLen; Index++) {
StringIndex = (UINT16) Index;
Status = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);
if (EFI_ERROR (Status)) {
goto Error;
}
if (Foreground == NULL || Background == NULL) {
Status = Hii->GlyphToBlt (
Hii,
(UINT8 *) Glyph,
mEfiColors[Sto->Mode->Attribute & 0x0f],
mEfiColors[Sto->Mode->Attribute >> 4],
BufferLen,
GlyphWidth,
GLYPH_HEIGHT,
&LineBuffer[Index * GLYPH_WIDTH]
);
} else {
Status = Hii->GlyphToBlt (
Hii,
(UINT8 *) Glyph,
*Foreground,
*Background,
BufferLen,
GlyphWidth,
GLYPH_HEIGHT,
&LineBuffer[Index * GLYPH_WIDTH]
);
}
}
//
// Blt a character to the screen
//
if (GraphicsOutput != NULL) {
Status = GraphicsOutput->Blt (
GraphicsOutput,
LineBuffer,
EfiBltBufferToVideo,
0,
0,
X,
Y,
GLYPH_WIDTH * BufferLen,
GLYPH_HEIGHT,
GLYPH_WIDTH * BufferLen * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
);
} else {
Status = UgaDraw->Blt (
UgaDraw,
(EFI_UGA_PIXEL *) LineBuffer,
EfiUgaBltBufferToVideo,
0,
0,
X,
Y,
GLYPH_WIDTH * BufferLen,
GLYPH_HEIGHT,
GLYPH_WIDTH * BufferLen * sizeof (EFI_UGA_PIXEL)
);
}
Error:
gBS->FreePool (LineBuffer);
gBS->FreePool (Buffer);
return Status;
}
UINTN
PrintXY (
IN UINTN X,
IN UINTN Y,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL
IN CHAR_W *Fmt,
...
)
/*++
Routine Description:
Prints a formatted unicode string to the default console
Arguments:
X - X coordinate to start printing
Y - Y coordinate to start printing
ForeGround - Foreground color
BackGround - Background color
Fmt - Format string
... - Print arguments
Returns:
Length of string printed to the console
--*/
{
EFI_HANDLE Handle;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
EFI_UGA_DRAW_PROTOCOL *UgaDraw;
EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto;
EFI_STATUS Status;
VA_LIST Args;
VA_START (Args, Fmt);
Handle = gST->ConsoleOutHandle;
Status = gBS->HandleProtocol (
Handle,
&gEfiGraphicsOutputProtocolGuid,
&GraphicsOutput
);
UgaDraw = NULL;
if (EFI_ERROR (Status)) {
GraphicsOutput = NULL;
Status = gBS->HandleProtocol (
Handle,
&gEfiUgaDrawProtocolGuid,
&UgaDraw
);
if (EFI_ERROR (Status)) {
return Status;
}
}
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleTextOutProtocolGuid,
&Sto
);
if (EFI_ERROR (Status)) {
return Status;
}
return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);
}
UINTN
SPrint (
OUT CHAR_W *Buffer,
IN UINTN BufferSize,
IN CONST CHAR_W *Format,
...
)
/*++
Routine Description:
SPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = VSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
VSPrint (
OUT CHAR_W *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR_W *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
VSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine
Arguments:
StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means
no limit.
FormatString - Unicode format string see file header for more details.
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
EFI_STATUS Status;
EFI_PRINT_PROTOCOL *PrintProtocol;
Status = gBS->LocateProtocol (
&gEfiPrintProtocolGuid,
NULL,
&PrintProtocol
);
if (EFI_ERROR (Status)) {
return 0;
} else {
return PrintProtocol->VSPrint (
StartOfBuffer,
BufferSize,
FormatString,
Marker
);
}
}

View File

@@ -0,0 +1,37 @@
/*++
Copyright (c) 2004, 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:
Print.h
Abstract:
Private data for Print.c
--*/
#ifndef _PRINT_H_
#define _PRINT_H_
#define LEFT_JUSTIFY 0x01
#define PREFIX_SIGN 0x02
#define PREFIX_BLANK 0x04
#define COMMA_TYPE 0x08
#define LONG_TYPE 0x10
#define PREFIX_ZERO 0x20
//
// Largest number of characters that can be printed out.
//
#define EFI_DRIVER_LIB_MAX_PRINT_BUFFER (80 * 4)
#endif

View File

@@ -0,0 +1,35 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Unicode
STRING_W is L""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR16 CHAR_W;
#define STRING_W(_s) L##_s
#define USPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define UvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
#include "EfiCommonLib.h"
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
ASPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = AvSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
AvSPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of ASPrint.
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
}
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,46 @@
#/*++
#
# Copyright (c) 2004, 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:
#
# HobLib.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = HobLib
COMPONENT_TYPE = LIBRARY
[sources.common]
Hob.c
[includes.common]
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation\Efi
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
EdkGuidLib
EdkFrameworkGuidLib
[nmake.common]

View File

@@ -0,0 +1,521 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
hob.c
Abstract:
Support for hob operation
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "PeiHob.h"
#include EFI_GUID_DEFINITION (IoBaseHob)
#include EFI_GUID_DEFINITION (MemoryAllocationHob)
VOID *
GetHob (
IN UINT16 Type,
IN VOID *HobStart
)
/*++
Routine Description:
This function returns the first instance of a HOB type in a HOB list.
Arguments:
Type The HOB type to return.
HobStart The first HOB in the HOB list.
Returns:
HobStart There were no HOBs found with the requested type.
else Returns the first HOB with the matching type.
--*/
{
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = HobStart;
//
// Return input if not found
//
if (HobStart == NULL) {
return HobStart;
}
//
// Parse the HOB list, stop if end of list or matching type found.
//
while (!END_OF_HOB_LIST (Hob)) {
if (Hob.Header->HobType == Type) {
break;
}
Hob.Raw = GET_NEXT_HOB (Hob);
}
//
// Return input if not found
//
if (END_OF_HOB_LIST (Hob)) {
return HobStart;
}
return (VOID *) (Hob.Raw);
}
UINTN
GetHobListSize (
IN VOID *HobStart
)
/*++
Routine Description:
Get size of hob list.
Arguments:
HobStart - Start pointer of hob list
Returns:
Size of hob list.
--*/
{
EFI_PEI_HOB_POINTERS Hob;
UINTN Size;
Hob.Raw = HobStart;
Size = 0;
while (Hob.Header->HobType != EFI_HOB_TYPE_END_OF_HOB_LIST) {
Size += Hob.Header->HobLength;
Hob.Raw += Hob.Header->HobLength;
}
Size += Hob.Header->HobLength;
return Size;
}
UINT32
GetHobVersion (
IN VOID *HobStart
)
/*++
Routine Description:
Get hob version.
Arguments:
HobStart - Start pointer of hob list
Returns:
Hob version.
--*/
{
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = HobStart;
return Hob.HandoffInformationTable->Version;
}
EFI_STATUS
GetHobBootMode (
IN VOID *HobStart,
OUT EFI_BOOT_MODE *BootMode
)
/*++
Routine Description:
Get current boot mode.
Arguments:
HobStart - Start pointer of hob list
BootMode - Current boot mode recorded in PHIT hob
Returns:
EFI_NOT_FOUND - Invalid hob header
EFI_SUCCESS - Boot mode found
--*/
{
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = HobStart;
if (Hob.Header->HobType != EFI_HOB_TYPE_HANDOFF) {
return EFI_NOT_FOUND;
}
*BootMode = Hob.HandoffInformationTable->BootMode;
return EFI_SUCCESS;
}
EFI_STATUS
GetCpuHobInfo (
IN VOID *HobStart,
OUT UINT8 *SizeOfMemorySpace,
OUT UINT8 *SizeOfIoSpace
)
/*++
Routine Description:
Get information recorded in CPU hob (Memory space size, Io space size)
Arguments:
HobStart - Start pointer of hob list
SizeOfMemorySpace - Size of memory size
SizeOfIoSpace - Size of IO size
Returns:
EFI_NOT_FOUND - CPU hob not found
EFI_SUCCESS - CPU hob found and information got.
--*/
{
EFI_PEI_HOB_POINTERS CpuHob;
CpuHob.Raw = HobStart;
CpuHob.Raw = GetHob (EFI_HOB_TYPE_CPU, CpuHob.Raw);
if (CpuHob.Header->HobType != EFI_HOB_TYPE_CPU) {
return EFI_NOT_FOUND;
}
*SizeOfMemorySpace = CpuHob.Cpu->SizeOfMemorySpace;
*SizeOfIoSpace = CpuHob.Cpu->SizeOfIoSpace;
return EFI_SUCCESS;
}
EFI_STATUS
GetDxeCoreHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length,
OUT VOID **EntryPoint,
OUT EFI_GUID **FileName
)
/*++
Routine Description:
Get memory allocation hob created for DXE core and extract its information
Arguments:
HobStart - Start pointer of the hob list
BaseAddress - Start address of memory allocated for DXE core
Length - Length of memory allocated for DXE core
EntryPoint - DXE core file name
FileName - File Name
Returns:
EFI_NOT_FOUND - DxeCoreHob not found
EFI_SUCCESS - DxeCoreHob found and information got
--*/
{
EFI_PEI_HOB_POINTERS DxeCoreHob;
DxeCoreHob.Raw = HobStart;
DxeCoreHob.Raw = GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw);
while (DxeCoreHob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION &&
!EfiCompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name,
&gEfiHobMemeryAllocModuleGuid)) {
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
DxeCoreHob.Raw = GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw);
}
if (DxeCoreHob.Header->HobType != EFI_HOB_TYPE_MEMORY_ALLOCATION) {
return EFI_NOT_FOUND;
}
*BaseAddress = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
*Length = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength;
*EntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint;
*FileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
return EFI_SUCCESS;
}
EFI_STATUS
GetNextFirmwareVolumeHob (
IN OUT VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
)
/*++
Routine Description:
Get next firmware volume hob from HobStart
Arguments:
HobStart - Start pointer of hob list
BaseAddress - Start address of next firmware volume
Length - Length of next firmware volume
Returns:
EFI_NOT_FOUND - Next firmware volume not found
EFI_SUCCESS - Next firmware volume found with address information
--*/
{
EFI_PEI_HOB_POINTERS FirmwareVolumeHob;
FirmwareVolumeHob.Raw = *HobStart;
if (END_OF_HOB_LIST (FirmwareVolumeHob)) {
return EFI_NOT_FOUND;
}
FirmwareVolumeHob.Raw = GetHob (EFI_HOB_TYPE_FV, *HobStart);
if (FirmwareVolumeHob.Header->HobType != EFI_HOB_TYPE_FV) {
return EFI_NOT_FOUND;
}
*BaseAddress = FirmwareVolumeHob.FirmwareVolume->BaseAddress;
*Length = FirmwareVolumeHob.FirmwareVolume->Length;
*HobStart = GET_NEXT_HOB (FirmwareVolumeHob);
return EFI_SUCCESS;
}
#if (PI_SPECIFICATION_VERSION >= 0x00010000)
EFI_STATUS
GetNextFirmwareVolume2Hob (
IN OUT VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length,
OUT EFI_GUID *FileName
)
/*++
Routine Description:
Get next firmware volume2 hob from HobStart
Arguments:
HobStart - Start pointer of hob list
BaseAddress - Start address of next firmware volume
Length - Length of next firmware volume
Returns:
EFI_NOT_FOUND - Next firmware volume not found
EFI_SUCCESS - Next firmware volume found with address information
--*/
{
EFI_PEI_HOB_POINTERS FirmwareVolumeHob;
FirmwareVolumeHob.Raw = *HobStart;
if (END_OF_HOB_LIST (FirmwareVolumeHob)) {
return EFI_NOT_FOUND;
}
FirmwareVolumeHob.Raw = GetHob (EFI_HOB_TYPE_FV2, *HobStart);
if (FirmwareVolumeHob.Header->HobType != EFI_HOB_TYPE_FV2) {
return EFI_NOT_FOUND;
}
*BaseAddress = FirmwareVolumeHob.FirmwareVolume2->BaseAddress;
*Length = FirmwareVolumeHob.FirmwareVolume2->Length;
EfiCommonLibCopyMem(FileName,&FirmwareVolumeHob.FirmwareVolume2->FileName,sizeof(EFI_GUID));
*HobStart = GET_NEXT_HOB (FirmwareVolumeHob);
return EFI_SUCCESS;
}
#endif
EFI_STATUS
GetNextGuidHob (
IN OUT VOID **HobStart,
IN EFI_GUID * Guid,
OUT VOID **Buffer,
OUT UINTN *BufferSize OPTIONAL
)
/*++
Routine Description:
Get the next guid hob.
Arguments:
HobStart A pointer to the start hob.
Guid A pointer to a guid.
Buffer A pointer to the buffer.
BufferSize Buffer size.
Returns:
Status code.
EFI_NOT_FOUND - Next Guid hob not found
EFI_SUCCESS - Next Guid hob found and data for this Guid got
EFI_INVALID_PARAMETER - invalid parameter
--*/
{
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS GuidHob;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {
GuidHob.Raw = *HobStart;
if (END_OF_HOB_LIST (GuidHob)) {
return EFI_NOT_FOUND;
}
GuidHob.Raw = GetHob (EFI_HOB_TYPE_GUID_EXTENSION, *HobStart);
if (GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
if (EfiCompareGuid (Guid, &GuidHob.Guid->Name)) {
Status = EFI_SUCCESS;
*Buffer = (VOID *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID));
if (BufferSize != NULL) {
*BufferSize = GuidHob.Header->HobLength - sizeof (EFI_HOB_GUID_TYPE);
}
}
}
*HobStart = GET_NEXT_HOB (GuidHob);
}
return Status;
}
#define PAL_ENTRY_HOB {0xe53cb8cc, 0xd62c, 0x4f74, 0xbd, 0xda, 0x31, 0xe5, 0x8d, 0xe5, 0x3e, 0x2}
EFI_GUID gPalEntryHob = PAL_ENTRY_HOB;
EFI_STATUS
GetPalEntryHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *PalEntry
)
/*++
Routine Description:
Get PAL entry from PalEntryHob
Arguments:
HobStart - Start pointer of hob list
PalEntry - Pointer to PAL entry
Returns:
Status code.
--*/
{
VOID *Buffer;
UINTN BufferSize;
EFI_STATUS Status;
VOID *HobStart2;
HobStart2 = HobStart;
Status = GetNextGuidHob (
&HobStart2,
&gPalEntryHob,
&Buffer,
&BufferSize
);
*PalEntry = *((EFI_PHYSICAL_ADDRESS *) Buffer);
return Status;
}
EFI_STATUS
GetIoPortSpaceAddressHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *IoPortSpaceAddress
)
/*++
Routine Description:
Get IO port space address from IoBaseHob.
Arguments:
HobStart - Start pointer of hob list
IoPortSpaceAddress - IO port space address
Returns:
Status code
--*/
{
VOID *Buffer;
UINTN BufferSize;
EFI_STATUS Status;
VOID *HobStart2;
HobStart2 = HobStart;
Status = GetNextGuidHob (
&HobStart2,
&gEfiIoBaseHobGuid,
&Buffer,
&BufferSize
);
*IoPortSpaceAddress = *((EFI_PHYSICAL_ADDRESS *) Buffer);
return Status;
}

View File

@@ -0,0 +1,26 @@
/*++
Copyright (c) 2004, 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:
ProcDep.h
Abstract:
EBC- specific runtime lib. Only used to get a clean build of
EFI libraries.
--*/
#ifndef _PROC_DEP_H_
#define _PROC_DEP_H_
#endif

View File

@@ -0,0 +1,294 @@
/*++
Copyright (c) 2004, 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:
EfiCombinationLib.h
Abstract:
Library functions that can be called in both PEI and DXE phase
--*/
#ifndef _EFI_COMBINATION_LIB_H_
#define _EFI_COMBINATION_LIB_H_
EFI_STATUS
EfiInitializeCommonDriverLib (
IN EFI_HANDLE ImageHandle,
IN VOID *SystemTable
)
/*++
Routine Description:
Initialize lib function calling phase: PEI or DXE
Arguments:
ImageHandle - The firmware allocated handle for the EFI image.
SystemTable - A pointer to the EFI System Table.
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
;
EFI_STATUS
EfiCommonIoRead (
IN UINT8 Width,
IN UINTN Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Io read operation.
Arguments:
Width - Width of read operation
Address - Start IO address to read
Count - Read count
Buffer - Buffer to store result
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonIoWrite (
IN UINT8 Width,
IN UINTN Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Io write operation.
Arguments:
Width - Width of write operation
Address - Start IO address to write
Count - Write count
Buffer - Buffer to write to the address
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonPciRead (
IN UINT8 Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Pci read operation
Arguments:
Width - Width of PCI read
Address - PCI address to read
Count - Read count
Buffer - Output buffer for the read
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonPciWrite (
IN UINT8 Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Pci write operation
Arguments:
Width - Width of PCI write
Address - PCI address to write
Count - Write count
Buffer - Buffer to write to the address
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonStall (
IN UINTN Microseconds
)
/*++
Routine Description:
Induces a fine-grained stall.
Arguments:
Microseconds - The number of microseconds to stall execution.
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonCopyMem (
IN VOID *Destination,
IN VOID *Source,
IN UINTN Length
)
/*++
Routine Description:
Copy Length bytes from Source to Destination.
Arguments:
Destination - Target of copy
Source - Place to copy from
Length - Number of bytes to copy
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonAllocatePages (
IN EFI_ALLOCATE_TYPE Type,
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN Pages,
IN OUT EFI_PHYSICAL_ADDRESS *Memory
)
/*++
Routine Description:
Allocates memory pages from the system.
Arguments:
Type - The type of allocation to perform.
MemoryType - The type of memory to allocate.
Pages - The number of contiguous pages to allocate.
Memory - Pointer to a physical address.
Returns:
EFI_OUT_OF_RESOURCES - The pages could not be allocated.
EFI_INVALID_PARAMETER - Invalid parameter
EFI_NOT_FOUND - The requested pages could not be found.
EFI_SUCCESS - The requested pages were allocated.
--*/
;
EFI_STATUS
EfiCommonLocateInterface (
IN EFI_GUID *Guid,
OUT VOID **Interface
)
/*++
Routine Description:
Returns the first protocol instance that matches the given protocol.
Arguments:
Guid - Provides the protocol to search for.
Interface - On return, a pointer to the first interface that matches Protocol
Returns:
Status code
--*/
;
EFI_STATUS
EfiCommonReportStatusCode (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
IN EFI_GUID * CallerId,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
)
/*++
Routine Description:
Status Code reporter
Arguments:
CodeType - Type of Status Code.
Value - Value to output for Status Code.
Instance - Instance Number of this status code.
CallerId - ID of the caller of this status code.
Data - Optional data associated with this status code.
Returns:
Status code
--*/
;
#endif

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,298 @@
/*++
Copyright (c) 2004, 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:
EfiHobLib.h
Abstract:
--*/
#ifndef _EFI_HOB_LIB_H_
#define _EFI_HOB_LIB_H_
#include "PeiHob.h"
VOID *
GetHob (
IN UINT16 Type,
IN VOID *HobStart
)
/*++
Routine Description:
This function returns the first instance of a HOB type in a HOB list.
Arguments:
Type The HOB type to return.
HobStart The first HOB in the HOB list.
Returns:
HobStart There were no HOBs found with the requested type.
else Returns the first HOB with the matching type.
--*/
;
UINTN
GetHobListSize (
IN VOID *HobStart
)
/*++
Routine Description:
Get size of hob list.
Arguments:
HobStart - Start pointer of hob list
Returns:
Size of hob list.
--*/
;
UINT32
GetHobVersion (
IN VOID *HobStart
)
/*++
Routine Description:
Get hob version.
Arguments:
HobStart - Start pointer of hob list
Returns:
Hob version.
--*/
;
EFI_STATUS
GetHobBootMode (
IN VOID *HobStart,
OUT EFI_BOOT_MODE *BootMode
)
/*++
Routine Description:
Get current boot mode.
Arguments:
HobStart - Start pointer of hob list
BootMode - Current boot mode recorded in PHIT hob
Returns:
EFI_NOT_FOUND - Invalid hob header
EFI_SUCCESS - Boot mode found
--*/
;
EFI_STATUS
GetCpuHobInfo (
IN VOID *HobStart,
OUT UINT8 *SizeOfMemorySpace,
OUT UINT8 *SizeOfIoSpace
)
/*++
Routine Description:
Get information recorded in CPU hob (Memory space size, Io space size)
Arguments:
HobStart - Start pointer of hob list
SizeOfMemorySpace - Size of memory size
SizeOfIoSpace - Size of IO size
Returns:
EFI_NOT_FOUND - CPU hob not found
EFI_SUCCESS - CPU hob found and information got.
--*/
;
EFI_STATUS
GetDxeCoreHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length,
OUT VOID **EntryPoint,
OUT EFI_GUID **FileName
)
/*++
Routine Description:
Get memory allocation hob created for DXE core and extract its information
Arguments:
HobStart - Start pointer of the hob list
BaseAddress - Start address of memory allocated for DXE core
Length - Length of memory allocated for DXE core
EntryPoint - DXE core file name
FileName - FileName
Returns:
EFI_NOT_FOUND - DxeCoreHob not found
EFI_SUCCESS - DxeCoreHob found and information got
--*/
;
EFI_STATUS
GetNextFirmwareVolumeHob (
IN OUT VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
)
/*++
Routine Description:
Get next firmware volume hob from HobStart
Arguments:
HobStart - Start pointer of hob list
BaseAddress - Start address of next firmware volume
Length - Length of next firmware volume
Returns:
EFI_NOT_FOUND - Next firmware volume not found
EFI_SUCCESS - Next firmware volume found with address information
--*/
;
#if (PI_SPECIFICATION_VERSION >= 0x00010000)
EFI_STATUS
GetNextFirmwareVolume2Hob (
IN OUT VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length,
OUT EFI_GUID *FileName
)
;
#endif
EFI_STATUS
GetNextGuidHob (
IN OUT VOID **HobStart,
IN EFI_GUID * Guid,
OUT VOID **Buffer,
OUT UINTN *BufferSize OPTIONAL
)
/*++
Routine Description:
Get the next guid hob.
Arguments:
HobStart A pointer to the start hob.
Guid A pointer to a guid.
Buffer A pointer to the buffer.
BufferSize Buffer size.
Returns:
Status code.
EFI_NOT_FOUND - Next Guid hob not found
EFI_SUCCESS - Next Guid hob found and data for this Guid got
--*/
;
EFI_STATUS
GetPalEntryHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *PalEntry
)
/*++
Routine Description:
Get PAL entry from PalEntryHob
Arguments:
HobStart - Start pointer of hob list
PalEntry - Pointer to PAL entry
Returns:
Status code.
--*/
;
EFI_STATUS
GetIoPortSpaceAddressHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *IoPortSpaceAddress
)
/*++
Routine Description:
Get IO port space address from IoBaseHob.
Arguments:
HobStart - Start pointer of hob list
IoPortSpaceAddress - IO port space address
Returns:
Status code
--*/
;
#endif

View File

@@ -0,0 +1,429 @@
/*++
Copyright (c) 2004, 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:
EfiMgmtModeRuntimeLib.h
Abstract:
Light weight lib to support EFI drivers.
--*/
#ifndef _EFI_RT_SUPPORT_LIB_H_
#define _EFI_RT_SUPPORT_LIB_H_
#ifndef EFI_LOAD_IMAGE_SMM
#define EFI_LOAD_DRIVER_SMM FALSE
#else
#define EFI_LOAD_DRIVER_SMM TRUE
#endif
#ifndef EFI_NO_LOAD_IMAGE_RT
#define EFI_NO_LOAD_DRIVER_RT FALSE
#else
#define EFI_NO_LOAD_DRIVER_RT TRUE
#endif
#include "EfiCommonLib.h"
#include "LinkedList.h"
#include "ProcDep.h"
#include EFI_PROTOCOL_DEFINITION (CpuIo)
#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)
//
// Driver Lib Globals.
//
extern EFI_BOOT_SERVICES *gBS;
extern EFI_SYSTEM_TABLE *gST;
extern UINTN gRtErrorLevel;
extern BOOLEAN mEfiLoadDriverSmm;
extern BOOLEAN mEfiNoLoadDriverRt;
extern EFI_DEVICE_PATH_PROTOCOL *mFilePath;
//
// Runtime Memory Allocation/De-Allocation tools (Should be used in Boot Phase only)
//
EFI_STATUS
EfiAllocateRuntimeMemoryPool (
IN UINTN Size,
OUT VOID **Buffer
)
/*++
Routine Description:
Allocate EfiRuntimeServicesData pool of specified size.
Arguments:
Size - Pool size
Buffer - Memory pointer for output
Returns:
Status code
--*/
;
EFI_STATUS
EfiFreeRuntimeMemoryPool (
IN VOID *Buffer
)
/*++
Routine Description:
Free allocated pool
Arguments:
Buffer - Pool to be freed
Returns:
Status code
--*/
;
EFI_STATUS
EfiLocateProtocolHandleBuffers (
IN EFI_GUID *Protocol,
IN OUT UINTN *NumberHandles,
OUT EFI_HANDLE **Buffer
)
/*++
Routine Description:
Returns an array of handles that support the requested protocol in a buffer allocated from pool.
Arguments:
Protocol - Provides the protocol to search by.
NumberHandles - The number of handles returned in Buffer.
Buffer - A pointer to the buffer to return the requested array of handles that
support Protocol.
Returns:
Status code
--*/
;
EFI_STATUS
EfiHandleProtocol (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface
)
/*++
Routine Description:
Queries a handle to determine if it supports a specified protocol.
Arguments:
Handle - The handle being queried.
Protocol - The published unique identifier of the protocol.
Interface - Supplies the address where a pointer to the corresponding Protocol
Interface is returned. NULL will be returned in *Interface if a
structure is not associated with Protocol.
Returns:
Status code
--*/
;
EFI_STATUS
EfiInstallProtocolInterface (
IN OUT EFI_HANDLE *Handle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface
)
/*++
Routine Description:
Installs a protocol interface on a device handle. If the handle does not exist, it is created and added
to the list of handles in the system.
Arguments:
Handle - A pointer to the EFI_HANDLE on which the interface is to be installed.
Protocol - The numeric ID of the protocol interface.
InterfaceType - Indicates whether Interface is supplied in native form.
Interface - A pointer to the protocol interface.
Returns:
Status code
--*/
;
EFI_STATUS
EfiReinstallProtocolInterface (
IN EFI_HANDLE SmmProtocolHandle,
IN EFI_GUID *Protocol,
IN VOID *OldInterface,
IN VOID *NewInterface
)
/*++
Routine Description:
Reinstalls a protocol interface on a device handle.
Arguments:
SmmProtocolHandle - Handle on which the interface is to be reinstalled.
Protocol - The numeric ID of the interface.
OldInterface - A pointer to the old interface.
NewInterface - A pointer to the new interface.
Returns:
Status code
--*/
;
EFI_STATUS
EfiLocateProtocolInterface (
EFI_GUID *Protocol,
VOID *Registration, OPTIONAL
VOID **Interface
)
/*++
Routine Description:
Returns the first protocol instance that matches the given protocol.
Arguments:
Protocol - Provides the protocol to search for.
Registration - Optional registration key returned from
RegisterProtocolNotify(). If Registration is NULL, then
it is ignored.
Interface - On return, a pointer to the first interface that matches Protocol and
Registration.
Returns:
Status code
--*/
;
EFI_STATUS
UninstallProtocolInterface (
IN EFI_HANDLE SmmProtocolHandle,
IN EFI_GUID *Protocol,
IN VOID *Interface
)
/*++
Routine Description:
Removes a protocol interface from a device handle.
Arguments:
SmmProtocolHandle - The handle on which the interface was installed.
Protocol - The numeric ID of the interface.
Interface - A pointer to the interface.
Returns:
Status code
--*/
;
EFI_STATUS
EfiRegisterProtocolCallback (
IN EFI_EVENT_NOTIFY CallbackFunction,
IN VOID *Context,
IN EFI_GUID *ProtocolGuid,
IN EFI_TPL NotifyTpl,
OUT VOID **Registeration,
OUT EFI_EVENT *Event
)
/*++
Routine Description:
Register a callback function to be signaled whenever an interface is installed for
a specified protocol.
Arguments:
CallbackFunction - Call back function
Context - Context of call back function
ProtocolGuid - The numeric ID of the protocol for which the callback function
is to be registered.
NotifyTpl - Notify tpl of callback function
Registeration - A pointer to a memory location to receive the registration value.
Event - Event that is to be signaled whenever a protocol interface is registered
for Protocol.
Returns:
Status code
--*/
;
EFI_STATUS
EfiSignalProtocolEvent (
EFI_EVENT Event
)
/*++
Routine Description:
Signals an event.
Arguments:
Event - The event to signal.
Returns:
Status code
--*/
;
EFI_STATUS
EfiInstallVendorConfigurationTable (
IN EFI_GUID *Guid,
IN VOID *Table
)
/*++
Routine Description:
Adds, updates, or removes a configuration table entry from the EFI System Table.
Arguments:
Guid - A pointer to the GUID for the entry to add, update, or remove.
Table - A pointer to the configuration table for the entry to add, update, or
remove. May be NULL.
Returns:
Status code
--*/
;
EFI_STATUS
EfiGetVendorConfigurationTable (
IN EFI_GUID *Guid,
OUT VOID **Table
)
/*++
Routine Description:
Return the EFI 1.0 System Tabl entry with TableGuid
Arguments:
Guid - Name of entry to return in the system table
Table - Pointer in EFI system table associated with TableGuid
Returns:
EFI_SUCCESS - Table returned;
EFI_NOT_FOUND - TableGuid not in EFI system table
--*/
;
EFI_STATUS
EfiInitializeUtilsRuntimeDriverLib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
IN EFI_EVENT_NOTIFY GoVirtualChildEvent
)
/*++
Routine Description:
Intialize runtime Driver Lib if it has not yet been initialized.
Arguments:
ImageHandle - The firmware allocated handle for the EFI image.
SystemTable - A pointer to the EFI System Table.
GoVirtualChildEvent - Caller can register a virtual notification event.
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
;
BOOLEAN
EfiInManagementInterrupt (
VOID
)
/*++
Routine Description:
Indicate whether the caller is already in SMM or not.
Arguments:
None
Returns:
TRUE - In SMM
FALSE - Not in SMM
--*/
;
//
// This MACRO initializes the RUNTIME invironment and optionally loads Image to SMM or Non-SMM space
// based upon the presence of build flags EFI_LOAD_DRIVER_SMM and EFI_NO_LOAD_DRIVER_RT.
//
#define EFI_INITIALIZE_RUNTIME_DRIVER_LIB(ImageHandle, SystemTable, GoVirtualChildEvent, FilePath) \
mEfiLoadDriverSmm = EFI_LOAD_DRIVER_SMM; \
mEfiNoLoadDriverRt = EFI_NO_LOAD_DRIVER_RT; \
mFilePath = (EFI_DEVICE_PATH_PROTOCOL*) FilePath; \
EfiInitializeUtilsRuntimeDriverLib ((EFI_HANDLE) ImageHandle, (EFI_SYSTEM_TABLE*) SystemTable, (EFI_EVENT_NOTIFY) GoVirtualChildEvent); \
if (!EfiInManagementInterrupt()) { \
if (mEfiNoLoadDriverRt) { \
return EFI_SUCCESS; \
} \
}
#endif

View File

@@ -0,0 +1,326 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
EfiPrintLib.h
Abstract:
Light weight lib to support EFI drivers.
--*/
#ifndef _EFI_PRINT_LIB_H_
#define _EFI_PRINT_LIB_H_
#include EFI_PROTOCOL_DEFINITION(GraphicsOutput)
#include EFI_PROTOCOL_DEFINITION(UgaDraw)
#include EFI_PROTOCOL_DEFINITION(Print)
UINTN
ErrorPrint (
IN CONST CHAR16 *ErrorString,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
ErrorString - Error message printed first
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
VOID
ErrorDumpHex (
IN UINTN Indent,
IN UINTN Offset,
IN UINTN DataSize,
IN VOID *UserData
)
/*++
Routine Description:
Dump error info by hex.
Arguments:
Indent - Indent number
Offset - Offset number
DataSize - Size of user data
UserData - User data to dump
Returns:
None
--*/
;
UINTN
Print (
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Prints a formatted unicode string to the default console
Arguments:
fmt - Format string
Returns:
Length of string printed to the console
--*/
;
UINTN
PrintXY (
IN UINTN X,
IN UINTN Y,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground, OPTIONAL
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background, OPTIONAL
IN CHAR16 *Fmt,
...
)
/*++
Routine Description:
Prints a formatted unicode string to the default console
Arguments:
X - X coordinate to start printing
Y - Y coordinate to start printing
ForeGround - Foreground color
BackGround - Background color
Fmt - Format string
... - Print arguments
Returns:
Length of string printed to the console
--*/
;
UINTN
Aprint (
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
UPrint (
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
VSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN StrLen,
IN CONST CHAR16 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Prints a formatted unicode string to a buffer
Arguments:
StartOfBuffer - Output buffer to print the formatted string into
StrLen - Size of Str. String is truncated to this size.
A size of 0 means there is no limit
Format - The format string
Marker - Vararg list consumed by processing Format.
Returns:
String length returned in buffer
--*/
;
UINTN
SPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
SPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
//
// BoxDraw support
//
BOOLEAN
IsValidEfiCntlChar (
IN CHAR16 CharC
)
/*++
Routine Description:
Test whether a wide char is a valid control char.
Arguments:
CharC - A char
Returns:
TRUE - A control char
FALSE - Not a control char
--*/
;
BOOLEAN
IsValidAscii (
IN CHAR16 Ascii
)
/*++
Routine Description:
Test whether a wide char is a normal printable char
Arguments:
Ascii - A char
Returns:
True - A normal, printable char
FALSE - Not a normal, printable char
--*/
;
BOOLEAN
LibIsValidTextGraphics (
IN CHAR16 Graphic,
OUT CHAR8 *PcAnsi, OPTIONAL
OUT CHAR8 *Ascii OPTIONAL
)
/*++
Routine Description:
Detects if a Unicode char is for Box Drawing text graphics.
Arguments:
Graphic - Unicode char to test.
PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
Ascii - Optional pointer to return Ascii equivalent of Graphic.
Returns:
TRUE if Gpaphic is a supported Unicode Box Drawing character.
--*/
;
#endif

View File

@@ -0,0 +1,205 @@
/*++
Copyright (c) 2004, 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:
EfiRegTableLib.h
Abstract:
Definitions and macros for building register tables for chipset
initialization..
Components linking this lib must include CpuIo, PciRootBridgeIo, and
BootScriptSave protocols in their DPX.
Revision History:
--*/
#ifndef EFI_REG_TABLE_H
#define EFI_REG_TABLE_H
#include "Tiano.h"
#include "EfiScriptLib.h"
#include EFI_PROTOCOL_CONSUMER (CpuIo)
#include EFI_PROTOCOL_CONSUMER (PciRootBridgeIo)
//
// RegTable OpCodes are encoded as follows:
//
// |31----------------------------16|15---------8|7-------0|
// \ \ \
// \ \ \
// 31:16 defined by Base OpCode---+ \ \
// Opcode Flags---+ \
// Base OpCode---+
//
#define OPCODE_BASE(OpCode) ((UINT8)((OpCode) & 0xFF))
#define OPCODE_FLAGS(OpCode) ((UINT8)(((OpCode) >> 8) & 0xFF))
#define OPCODE_EXTRA_DATA(OpCode) ((UINT16)((OpCode) >> 16))
//
// RegTable Base OpCodes
//
#define OP_TERMINATE_TABLE 0
#define OP_MEM_WRITE 1
#define OP_MEM_READ_MODIFY_WRITE 2
#define OP_IO_WRITE 3
#define OP_IO_READ_MODIFY_WRITE 4
#define OP_PCI_WRITE 5
#define OP_PCI_READ_MODIFY_WRITE 6
#define OP_STALL 7
//
// RegTable OpCode Flags
//
#define OPCODE_FLAG_S3SAVE 1
#define TERMINATE_TABLE { (UINT32) OP_TERMINATE_TABLE, (UINT32) 0, (UINT32) 0 }
//
// REG_TABLE_ENTRY_PCI_WRITE encodes the width in the upper bits of the OpCode
// as one of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH values
//
typedef struct {
UINT32 OpCode;
UINT32 PciAddress;
UINT32 Data;
} EFI_REG_TABLE_PCI_WRITE;
#define PCI_WRITE(Bus, Dev, Fnc, Reg, Width, Data, S3Flag) \
{ \
(UINT32) (OP_PCI_WRITE | ((S3Flag) << 8) | ((Width) << 16)), \
(UINT32) (EFI_PCI_ADDRESS ((Bus), (Dev), (Fnc), (Reg))), \
(UINT32) (Data), \
(UINT32) (0) \
}
typedef struct {
UINT32 OpCode;
UINT32 PciAddress;
UINT32 OrMask;
UINT32 AndMask;
} EFI_REG_TABLE_PCI_READ_MODIFY_WRITE;
#define PCI_READ_MODIFY_WRITE(Bus, Dev, Fnc, Reg, Width, OrMask, AndMask, S3Flag) \
{ \
(UINT32) (OP_PCI_READ_MODIFY_WRITE | ((S3Flag) << 8) | ((Width) << 16)), \
(UINT32) (EFI_PCI_ADDRESS ((Bus), (Dev), (Fnc), (Reg))), \
(UINT32) (OrMask), \
(UINT32) (AndMask) \
}
typedef struct {
UINT32 OpCode;
UINT32 MemAddress;
UINT32 OrMask;
UINT32 AndMask;
} EFI_REG_TABLE_MEM_READ_MODIFY_WRITE;
#define MEM_READ_MODIFY_WRITE(Address, Width, OrMask, AndMask, S3Flag) \
{ \
(UINT32) (OP_MEM_READ_MODIFY_WRITE | ((S3Flag) << 8) | ((Width) << 16)), \
(UINT32) (Address), \
(UINT32) (OrMask), \
(UINT32) (AndMask) \
}
typedef struct {
UINT32 OpCode;
UINT32 Field2;
UINT32 Field3;
UINT32 Field4;
} EFI_REG_TABLE_GENERIC;
typedef union {
EFI_REG_TABLE_GENERIC Generic;
EFI_REG_TABLE_PCI_WRITE PciWrite;
EFI_REG_TABLE_PCI_READ_MODIFY_WRITE PciReadModifyWrite;
EFI_REG_TABLE_MEM_READ_MODIFY_WRITE MemReadModifyWrite;
} EFI_REG_TABLE;
VOID
ProcessRegTablePci (
EFI_REG_TABLE * RegTableEntry,
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * PciRootBridgeIo,
EFI_CPU_IO_PROTOCOL * CpuIo
)
/*++
Routine Description:
Processes register table assuming which may contain PCI, IO, MEM, and STALL
entries.
No parameter checking is done so the caller must be careful about omitting
values for PciRootBridgeIo or CpuIo parameters. If the regtable does
not contain any PCI accesses, it is safe to omit the PciRootBridgeIo (supply
NULL). If the regtable does not contain any IO or Mem entries, it is safe to
omit the CpuIo (supply NULL).
The RegTableEntry parameter is not checked, but is required.
gBS is assumed to have been defined and is used when processing stalls.
The function processes each entry sequentially until an OP_TERMINATE_TABLE
entry is encountered.
Arguments:
RegTableEntry - A pointer to the register table to process
PciRootBridgeIo - A pointer to the instance of PciRootBridgeIo that is used
when processing PCI table entries
CpuIo - A pointer to the instance of CpuIo that is used when processing IO and
MEM table entries
Returns:
Nothing.
--*/
;
VOID
ProcessRegTableCpu (
EFI_REG_TABLE * RegTableEntry,
EFI_CPU_IO_PROTOCOL * CpuIo
)
/*++
Routine Description:
Processes register table assuming which may contain IO, MEM, and STALL
entries, but must NOT contain any PCI entries. Any PCI entries cause an
ASSERT in a DEBUG build and are skipped in a free build.
No parameter checking is done. Both RegTableEntry and CpuIo parameters are
required.
gBS is assumed to have been defined and is used when processing stalls.
The function processes each entry sequentially until an OP_TERMINATE_TABLE
entry is encountered.
Arguments:
RegTableEntry - A pointer to the register table to process
CpuIo - A pointer to the instance of CpuIo that is used when processing IO and
MEM table entries
Returns:
Nothing.
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,517 @@
/*++
Copyright (c) 2004, 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:
EfiScriptLib.h
Abstract:
--*/
#ifndef _EFI_SCRIPT_LIB_H_
#define _EFI_SCRIPT_LIB_H_
#include "Tiano.h"
#include "EfiCommonLib.h"
#include "EfiBootScript.h"
#include EFI_PROTOCOL_DEFINITION (BootScriptSave)
EFI_STATUS
BootScriptSaveInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Intialize Boot Script Lib if it has not yet been initialized.
Arguments:
ImageHandle - The firmware allocated handle for the EFI image.
SystemTable - A pointer to the EFI System Table.
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSaveIoWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer
)
/*++
Routine Description:
Save I/O write to boot script with opcode EFI_BOOT_SCRIPT_IO_WRITE_OPCODE
Arguments:
TableName - Desired boot script table
Width - The width of the I/O operations.
Address - The base address of the I/O operations.
Count - The number of I/O operations to perform.
Buffer - The source buffer from which to write data.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSaveIoReadWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN VOID *Data,
IN VOID *DataMask
)
/*++
Routine Description:
Save I/O modify to boot script with opcode EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE
Arguments:
TableName - Desired boot script table
Width - The width of the I/O operations.
Address - The base address of the I/O operations.
Data - A pointer to the data to be OR-ed.
DataMask - A pointer to the data mask to be AND-ed with the data read from the register.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSaveMemWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer
)
/*++
Routine Description:
Save memory write to boot script with opcode EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE
Arguments:
TableName - Desired boot script table
Width - The width of the memory operations.
Address - The base address of the memory operations.
Count - The number of memory operations to perform.
Buffer - The source buffer from which to write the data.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSaveMemReadWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN VOID *Data,
IN VOID *DataMask
)
/*++
Routine Description:
Save memory modify to boot script with opcode EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE
Arguments:
TableName - Desired boot script table
Width - The width of the memory operations.
Address - The base address of the memory operations.
Data - A pointer to the data to be OR-ed.
DataMask - A pointer to the data mask to be AND-ed with the data read from the register.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSavePciCfgWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN VOID *Buffer
)
/*++
Routine Description:
Save PCI configuration space write operation to boot script with opcode
EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE
Arguments:
TableName - Desired boot script table
Width - The width of the PCI operations
Address - The address within the PCI configuration space.
Count - The number of PCI operations to perform.
Buffer - The source buffer from which to write the data.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSavePciCfgReadWrite (
IN UINT16 TableName,
IN EFI_BOOT_SCRIPT_WIDTH Width,
IN UINT64 Address,
IN VOID *Data,
IN VOID *DataMask
)
/*++
Routine Description:
Save PCI configuration space modify operation to boot script with opcode
EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE
Arguments:
TableName - Desired boot script table
Width - The width of the PCI operations
Address - The address within the PCI configuration space.
Data - A pointer to the data to be OR-ed.
DataMask - A pointer to the data mask to be AND-ed with the data read from the register.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
;
EFI_STATUS
BootScriptSaveSmbusExecute (
IN UINT16 TableName,
IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
IN EFI_SMBUS_DEVICE_COMMAND Command,
IN EFI_SMBUS_OPERATION Operation,
IN BOOLEAN PecCheck,
IN UINTN *Length,
IN VOID *Buffer
)
/*++
Routine Description:
Save SMBus command execution to boot script with opcode
EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE
Arguments:
TableName - Desired boot script table
SlaveAddress - The SMBus address for the slave device that the operation is targeting.
Command - The command that is transmitted by the SMBus host controller to the
SMBus slave device.
Operation - Indicates which particular SMBus protocol it will use to execute the
SMBus transactions.
PecCheck - Defines if Packet Error Code (PEC) checking is required for this operation.
Length - A pointer to signify the number of bytes that this operation will do.
Buffer - Contains the value of data to execute to the SMBUS slave device.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSaveStall (
IN UINT16 TableName,
IN UINTN Duration
)
/*++
Routine Description:
Save execution stall on the processor to boot script with opcode
EFI_BOOT_SCRIPT_STALL_OPCODE
Arguments:
TableName - Desired boot script table
Duration - Duration in microseconds of the stall.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
BootScriptSaveDispatch (
IN UINT16 TableName,
IN EFI_PHYSICAL_ADDRESS EntryPoint
)
/*++
Routine Description:
Save dispatching specified arbitrary code to boot script with opcode
EFI_BOOT_SCRIPT_DISPATCH_OPCODE
Arguments:
TableName - Desired boot script table
EntryPoint - Entry point of the code to be dispatched.
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
EFIAPI
BootScriptSaveInformation (
IN UINT16 TableName,
IN UINT32 Length,
IN EFI_PHYSICAL_ADDRESS Buffer
)
/*++
Routine Description:
Save a Information Opcode record in table specified with TableName
Arguments:
TableName - Desired boot script table
Length - Length of information in bytes
Buffer - Content of information that will be saved in script table
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
EFIAPI
BootScriptSaveInformationUnicodeString (
IN UINT16 TableName,
IN CHAR16 *String
)
/*++
Routine Description:
Save a Information Opcode record in table specified with TableName, the information
is a unicode string.
Arguments:
TableName - Desired boot script table
String - The string that will be saved in script table
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
EFI_STATUS
EFIAPI
BootScriptSaveInformationAsciiString (
IN UINT16 TableName,
IN CHAR8 *String
)
/*++
Routine Description:
Save a Information Opcode record in table specified with TableName, the information
is a ascii string.
Arguments:
TableName - Desired boot script table
String - The string that will be saved in script table
Returns:
EFI_NOT_FOUND - BootScriptSave Protocol not exist.
EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
--*/
;
#ifdef EFI_S3_RESUME
#define INITIALIZE_SCRIPT(ImageHandle, SystemTable) \
BootScriptSaveInitialize(ImageHandle, SystemTable)
#define SCRIPT_IO_WRITE(TableName, Width, Address, Count, Buffer) \
BootScriptSaveIoWrite(TableName, Width, Address, Count, Buffer)
#define SCRIPT_IO_READ_WRITE(TableName, Width, Address, Data, DataMask) \
BootScriptSaveIoReadWrite(TableName, Width, Address, Data, DataMask)
#define SCRIPT_MEM_WRITE(TableName, Width, Address, Count, Buffer) \
BootScriptSaveMemWrite(TableName, Width, Address, Count, Buffer)
#define SCRIPT_MEM_WRITE_THIS(TableName, Width, Address, Count) \
BootScriptSaveMemWrite(TableName, Width, Address, Count, (VOID*)(UINTN)Address)
#define SCRIPT_MEM_READ_WRITE(TableName, Width, Address, Data, DataMask) \
BootScriptSaveMemReadWrite(TableName, Width, Address, Data, DataMask)
#define SCRIPT_PCI_CFG_WRITE(TableName, Width, Address, Count, Buffer) \
BootScriptSavePciCfgWrite(TableName, Width, Address, Count, Buffer)
#define SCRIPT_PCI_CFG_READ_WRITE(TableName, Width, Address, Data, DataMask) \
BootScriptSavePciCfgReadWrite(TableName, Width, Address, Data, DataMask)
#define SCRIPT_SMBUS_EXECUTE(TableName, SlaveAddress, Command, Operation, PecCheck, Length, Buffer) \
BootScriptSaveSmbusExecute(TableName, SlaveAddress, Command, Operation, PecCheck, Length, Buffer)
#define SCRIPT_STALL(TableName, Duration) \
BootScriptSaveStall(TableName, Duration)
#define SCRIPT_DISPATCH(TableName, EntryPoint) \
BootScriptSaveDispatch(TableName, EntryPoint)
#define SCRIPT_INOFRMATION(TableName, Length, Buffer) \
BootScriptSaveInformation(TableName, Length, Buffer)
#define SCRIPT_INOFRMATION_UNICODE_STRING(TableName, String) \
BootScriptSaveInformationUnicodeString(TableName, String)
#define SCRIPT_INOFRMATION_ASCII_STRING(TableName, String) \
BootScriptSaveInformationAsciiString(TableName, String)
#else
#define INITIALIZE_SCRIPT(ImageHandle, SystemTable)
#define SCRIPT_IO_WRITE(TableName, Width, Address, Count, Buffer)
#define SCRIPT_IO_READ_WRITE(TableName, Width, Address, Data, DataMask)
#define SCRIPT_MEM_WRITE(TableName, Width, Address, Count, Buffer)
#define SCRIPT_MEM_WRITE_THIS(TableName, Width, Address, Count)
#define SCRIPT_MEM_READ_WRITE(TableName, Width, Address, Data, DataMask)
#define SCRIPT_PCI_CFG_WRITE(TableName, Width, Address, Count, Buffer)
#define SCRIPT_PCI_CFG_READ_WRITE(TableName, Width, Address, Data, DataMask)
#define SCRIPT_SMBUS_EXECUTE(TableName, SlaveAddress, Command, Operation, PecCheck, Length, Buffer)
#define SCRIPT_STALL(TableName, Duration)
#define SCRIPT_DISPATCH(TableName, EntryPoint)
#define SCRIPT_INOFRMATION(TableName, Length, Buffer)
#define SCRIPT_INOFRMATION_UNICODE_STRING(TableName, String)
#define SCRIPT_INOFRMATION_ASCII_STRING(TableName, String)
#endif
#endif

View File

@@ -0,0 +1,220 @@
/*++
Copyright (c) 2004 - 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:
EfiSmmDriverLib.h
Abstract:
Light weight lib to support EFI Smm drivers.
--*/
#ifndef _EFI_SMM_DRIVER_LIB_H_
#define _EFI_SMM_DRIVER_LIB_H_
#include "Tiano.h"
#include "GetImage.h"
#include "EfiCommonLib.h"
#include EFI_GUID_DEFINITION (EventLegacyBios)
#include EFI_GUID_DEFINITION (EventGroup)
#include EFI_PROTOCOL_DEFINITION (FirmwareVolume)
#include EFI_PROTOCOL_DEFINITION (FirmwareVolume2)
#include EFI_PROTOCOL_DEFINITION (SmmBase)
#include EFI_PROTOCOL_DEFINITION (SmmStatusCode)
//
// Driver Lib Globals.
//
extern EFI_BOOT_SERVICES *gBS;
extern EFI_SYSTEM_TABLE *gST;
extern EFI_RUNTIME_SERVICES *gRT;
extern EFI_SMM_BASE_PROTOCOL *gSMM;
extern EFI_SMM_STATUS_CODE_PROTOCOL *mSmmDebug;
extern UINTN gErrorLevel;
#define EfiCopyMem EfiCommonLibCopyMem
#define EfiSetMem EfiCommonLibSetMem
#define EfiZeroMem EfiCommonLibZeroMem
EFI_STATUS
EfiInitializeSmmDriverLib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
IN OUT BOOLEAN *InSmm
)
/*++
Routine Description:
Intialize Smm Driver Lib if it has not yet been initialized.
Arguments:
ImageHandle - The firmware allocated handle for the EFI image.
SystemTable - A pointer to the EFI System Table.
InSmm - If InSmm is NULL, it will not register Image to SMM.
If InSmm is not NULL, it will register Image to SMM and
return information on currently in SMM mode or not.
Returns:
EFI_STATUS always returns EFI_SUCCESS
--*/
;
VOID
EfiDebugAssert (
IN CHAR8 *FileName,
IN INTN LineNumber,
IN CHAR8 *Description
)
/*++
Routine Description:
Worker function for ASSERT (). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded DEADLOOP ().
Arguments:
FileName - File name of failing routine.
LineNumber - Line number of failing ASSERT().
Description - Description, usually the assertion,
Returns:
None
--*/
;
VOID
EfiDebugVPrint (
IN UINTN ErrorLevel,
IN CHAR8 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded do nothing.
Arguments:
ErrorLevel - If error level is set do the debug print.
Format - String to use for the print, followed by Print arguments.
Marker - VarArgs
Returns:
None
--*/
;
VOID
EfiDebugPrint (
IN UINTN ErrorLevel,
IN CHAR8 *Format,
...
)
/*++
Routine Description:
Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
information. If Error Logging hub is not loaded do nothing.
Arguments:
ErrorLevel - If error level is set do the debug print.
Format - String to use for the print, followed by Print arguments.
... - VAR args for Format
Returns:
None
--*/
;
EFI_STATUS
EFIAPI
SmmEfiCreateEventLegacyBoot (
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT EFI_EVENT *LegacyBootEvent
)
/*++
Routine Description:
Create a Legacy Boot Event.
Tiano extended the CreateEvent Type enum to add a legacy boot event type.
This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
added and now it's possible to not voilate the UEFI specification by
declaring a GUID for the legacy boot event class. This library supports
the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
work both ways.
Arguments:
LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
Returns:
EFI_SUCCESS Event was created.
Other Event was not created.
--*/
;
EFI_STATUS
EFIAPI
SmmEfiCreateEventReadyToBoot (
IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction,
IN VOID *NotifyContext,
OUT EFI_EVENT *ReadyToBootEvent
)
/*++
Routine Description:
Create a Read to Boot Event.
Tiano extended the CreateEvent Type enum to add a ready to boot event type.
This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
added and now it's possible to not voilate the UEFI specification and use
the ready to boot event class defined in UEFI 2.0. This library supports
the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
work both ways.
Arguments:
ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
Return:
EFI_SUCCESS - Event was created.
Other - Event was not created.
--*/
;
#endif

View File

@@ -0,0 +1,205 @@
/*++
Copyright (c) 2004, 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:
EfiUiLib.h
Abstract:
Collection of usefull UI functions.
Revision History:
--*/
#ifndef _EFI_UI_LIB_H_
#define _EFI_UI_LIB_H_
#include "Tiano.h"
#include "TianoTypes.h"
#include "EfiDriverLib.h"
CHAR16 *
StrHzToString (
OUT CHAR16 *String,
IN UINT64 Val
)
/*++
Routine Description:
Converts frequency in Hz to Unicode string.
Three significant digits are delivered. Used for processor info display.
Arguments:
String - string that will contain the frequency.
Val - value to convert, minimum is 100000 i.e., 0.1 MHz.
Returns:
String that contains the frequency.
--*/
;
CHAR16 *
StrBytesToString (
OUT CHAR16 *String,
IN UINT64 Val
)
/*++
Routine Description:
Converts size in bytes to Unicode string.
Used for memory/cache size display.
Arguments:
String - string that will contain the value
Val - value to convert in bytes
Returns:
String that contains the value.
--*/
;
CHAR16 *
StrVersionToString (
OUT CHAR16 *String,
IN UINT8 Version
)
/*++
Routine Description:
Converts 8 bit version value to Unicode string.
The upper nibble contains the upper part, the lower nibble contains the minor part.
The output format is <major>.<minor>.
Arguments:
String - string that will contain the version value
Version - Version value to convert
Returns:
String that contains the version value.
--*/
;
CHAR16 *
StrMacToString (
OUT CHAR16 *String,
IN EFI_MAC_ADDRESS *MacAddr,
IN UINT32 AddrSize
)
/*++
Routine Description:
Converts MAC address to Unicode string.
The value is 64-bit and the resulting string will be 12
digit hex number in pairs of digits separated by dashes.
Arguments:
String - string that will contain the value
MacAddr - MAC address to convert
AddrSize - Size of address
Returns:
String that contains the value.
--*/
;
CHAR16 *
StrIp4AdrToString (
OUT CHAR16 *String,
IN EFI_IPv4_ADDRESS *Ip4Addr
)
/*++
Routine Description:
Converts IP v4 address to Unicode string.
The value is 64-bit and the resulting string will
be four decimal values 0-255 separated by dots.
Arguments:
String - string that will contain the value
Ip4Addr - IP v4 address to convert from
Returns:
String that contain the value
--*/
;
EFI_STATUS
StrStringToIp4Adr (
OUT EFI_IPv4_ADDRESS *Ip4Addr,
IN CHAR16 *String
)
/*++
Routine Description:
Parses and converts Unicode string to IP v4 address.
The value will 64-bit.
The string must be four decimal values 0-255 separated by dots.
The string is parsed and format verified.
Arguments:
Ip4Addr - pointer to the variable to store the value to
String - string that contains the value to parse and convert
Returns:
EFI_SUCCESS - if successful
EFI_INVALID_PARAMETER - if String contains invalid IP v4 format
--*/
;
CHAR16 *
Ascii2Unicode (
OUT CHAR16 *UnicodeStr,
IN CHAR8 *AsciiStr
)
/*++
Routine Description:
Converts ASCII characters to Unicode.
Arguments:
UnicodeStr - the Unicode string to be written to. The buffer must be large enough.
AsciiStr - The ASCII string to be converted.
Returns:
The address to the Unicode string - same as UnicodeStr.
--*/
;
CHAR8 *
Unicode2Ascii (
OUT CHAR8 *AsciiStr,
IN CHAR16 *UnicodeStr
)
/*++
Routine Description:
Converts ASCII characters to Unicode.
Assumes that the Unicode characters are only these defined in the ASCII set.
Arguments:
AsciiStr - The ASCII string to be written to. The buffer must be large enough.
UnicodeStr - the Unicode string to be converted.
Returns:
The address to the ASCII string - same as AsciiStr.
--*/
;
#endif

View File

@@ -0,0 +1,75 @@
/*++
Copyright (c) 2004, 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:
EfiWinNtLib.h
Abstract:
Set up gWinNt pointer so we can call WinNT APIs.
--*/
#ifndef _EFI_WIN_NT_LIB_H_
#define _EFI_WIN_NT_LIB_H_
extern EFI_WIN_NT_THUNK_PROTOCOL *gWinNt;
EFI_STATUS
EfiInitializeWinNtDriverLib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Intialize gWinNt and initialize debug console.
Arguments:
ImageHandle - The firmware allocated handle for the EFI image.
SystemTable - A pointer to the EFI System Table.
Returns:
Status code
--*/
;
//
// NTDebugConsole Prototypes
//
VOID
NtDebugConsoleInit (
VOID
)
/*++
Routine Description:
Nt debug console initialize.
Arguments:
None
Returns:
None
--*/
;
#endif

View File

@@ -0,0 +1,104 @@
/*++
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:
GetImage.h
Abstract:
Image data retrieval support for common use.
--*/
#ifndef _GET_IMAGE_H_
#define _GET_IMAGE_H_
#include "EfiImageFormat.h"
EFI_STATUS
GetImage (
IN EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
OUT VOID **Buffer,
OUT UINTN *Size
)
/*++
Routine Description:
Enumerate all the FVs, and fill Buffer with the SectionType section content in NameGuid file.
Note:
1. when SectionType is EFI_SECTION_PE32, it tries to read NameGuid file after failure on
reading EFI_SECTION_PE32 section.
2. when SectionType is EFI_SECTION_TE, it tries to get EFI_SECTION_PE32 section after failure on
reading EFI_SECTION_TE section. If it's failed again, it tries to read NameGuid file.
3. Callee allocates memory, which caller is responsible to free.
Arguments:
NameGuid - Pointer to EFI_GUID, which is file name.
SectionType - Required section type.
Buffer - Pointer to a pointer in which the read content is returned.
Caller is responsible to free Buffer.
Size - Pointer to a UINTN, which indicates the size of returned *Buffer.
Returns:
EFI_NOT_FOUND - Required content can not be found.
EFI_SUCCESS - Required content can be found, but whether the Buffer is filled
with section content or not depends on the Buffer and Size.
--*/
;
EFI_STATUS
GetImageEx (
IN EFI_HANDLE ImageHandle,
IN EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
OUT VOID **Buffer,
OUT UINTN *Size,
BOOLEAN WithinImageFv
)
/*++
Routine Description:
Search FVs, and fill Buffer with the SectionType section content in NameGuid file.
If ImageHandle is not NULL, the FV from which the ImageHandle is loaded is searched
first. If WithinImageFv is TRUE, only the FV from which the ImageHandle is loaded
is searched. If ImageHandle is NULL or WithinImageFv is FALSE, all FVs in the system
is searched.
Note:
1. when SectionType is EFI_SECTION_PE32, it tries to read NameGuid file after failure on
reading EFI_SECTION_PE32 section.
2. when SectionType is EFI_SECTION_TE, it tries to get EFI_SECTION_PE32 section after failure on
reading EFI_SECTION_TE section. If it's failed again, it tries to read NameGuid file.
3. Callee allocates memory, which caller is responsible to free.
Arguments:
ImageHandle - The caller's driver image handle.
NameGuid - Pointer to EFI_GUID, which is file name.
SectionType - Required section type.
Buffer - Pointer to a pointer in which the read content is returned.
Caller is responsible to free Buffer.
Size - Pointer to a UINTN, which indicates the size of returned *Buffer.
WithinImageFv - Whether the search only performs on the FV from which the caller's
driver image is loaded.
Returns:
EFI_INVALID_PARAMETER - ImageHandle is NULL and WithinImageFv is TRUE.
EFI_NOT_FOUND - Required content can not be found.
EFI_SUCCESS - Required content can be found, but whether the Buffer is filled
with section content or not depends on the Buffer and Size.
--*/
;
#endif //_GET_IMAGE_H_

View File

@@ -0,0 +1,250 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
GraphicsLib.h
Abstract:
--*/
#ifndef _EFI_GRAPHICS_LIB_H_
#define _EFI_GRAPHICS_LIB_H_
#include EFI_PROTOCOL_DEFINITION (ConsoleControl)
#include EFI_PROTOCOL_DEFINITION (FirmwareVolume)
#include EFI_PROTOCOL_DEFINITION (FirmwareVolume2)
#include EFI_PROTOCOL_DEFINITION (GraphicsOutput)
#include EFI_PROTOCOL_DEFINITION (UgaDraw)
#include EFI_PROTOCOL_DEFINITION (EfiOEMBadging)
#include EFI_GUID_DEFINITION (Bmp)
EFI_STATUS
GetGraphicsBitMapFromFV (
IN EFI_GUID *FileNameGuid,
OUT VOID **Image,
OUT UINTN *ImageSize
)
/*++
Routine Description:
Return the graphics image file named FileNameGuid into Image and return it's
size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
file name.
Arguments:
FileNameGuid - File Name of graphics file in the FV(s).
Image - Pointer to pointer to return graphics image. If NULL, a
buffer will be allocated.
ImageSize - Size of the graphics Image in bytes. Zero if no image found.
Returns:
EFI_SUCCESS - Image and ImageSize are valid.
EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
EFI_NOT_FOUND - FileNameGuid not found
--*/
;
EFI_STATUS
GetGraphicsBitMapFromFVEx (
IN EFI_HANDLE ImageHandle,
IN EFI_GUID *FileNameGuid,
OUT VOID **Image,
OUT UINTN *ImageSize
)
/*++
Routine Description:
Return the graphics image file named FileNameGuid into Image and return it's
size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
file name.
Arguments:
ImageHandle - The driver image handle of the caller. The parameter is used to
optimize the loading of the image file so that the FV from which
the driver image is loaded will be tried first.
FileNameGuid - File Name of graphics file in the FV(s).
Image - Pointer to pointer to return graphics image. If NULL, a
buffer will be allocated.
ImageSize - Size of the graphics Image in bytes. Zero if no image found.
Returns:
EFI_SUCCESS - Image and ImageSize are valid.
EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
EFI_NOT_FOUND - FileNameGuid not found
--*/
;
EFI_STATUS
ConvertBmpToGopBlt (
IN VOID *BmpImage,
IN UINTN BmpImageSize,
IN OUT VOID **GopBlt,
IN OUT UINTN *GopBltSize,
OUT UINTN *PixelHeight,
OUT UINTN *PixelWidth
)
/*++
Routine Description:
Convert a *.BMP graphics image to a GOP/UGA 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.
Arguments:
BmpImage - Pointer to BMP file
BmpImageSize - Number of bytes in BmpImage
GopBlt - Buffer containing GOP version of BmpImage.
GopBltSize - Size of GopBlt in bytes.
PixelHeight - Height of GopBlt/BmpImage in pixels
PixelWidth - Width of GopBlt/BmpImage in pixels
Returns:
EFI_SUCCESS - GopBlt and GopBltSize are returned.
EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
EFI_BUFFER_TOO_SMALL - The passed in GopBlt buffer is not big enough.
GopBltSize will contain the required size.
EFI_OUT_OF_RESOURCES - No enough buffer to allocate
--*/
;
EFI_STATUS
EnableQuietBoot (
IN EFI_GUID *LogoFile
)
/*++
Routine Description:
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
Arguments:
LogoFile - File name of logo to display on the center of the screen.
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
;
EFI_STATUS
EnableQuietBootEx (
IN EFI_GUID *LogoFile,
IN EFI_HANDLE ImageHandle
)
/*++
Routine Description:
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
Arguments:
LogoFile - File name of logo to display on the center of the screen.
ImageHandle - The driver image handle of the caller. The parameter is used to
optimize the loading of the logo file so that the FV from which
the driver image is loaded will be tried first.
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
;
EFI_STATUS
DisableQuietBoot (
VOID
)
/*++
Routine Description:
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
Arguments:
NONE
Returns:
EFI_SUCCESS - UGA devices are back in text mode and synced up.
EFI_UNSUPPORTED - Logo not found
--*/
;
EFI_STATUS
LockKeyboards (
IN CHAR16 *Password
)
/*++
Routine Description:
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.
Arguments:
Password - Password used to lock ConIn device
Returns:
EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
displayed.
EFI_UNSUPPORTED - Logo not found
--*/
;
#endif

View File

@@ -0,0 +1,260 @@
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CpuFuncs.h
Abstract:
--*/
#ifndef _CPU_FUNCS_H_
#define _CPU_FUNCS_H_
#define EFI_CPUID_SIGNATURE 0x0
#define EFI_CPUID_VERSION_INFO 0x1
#define EFI_CPUID_CACHE_INFO 0x2
#define EFI_CPUID_SERIAL_NUMBER 0x3
#define EFI_CPUID_EXTENDED_FUNCTION 0x80000000
#define EFI_CPUID_EXTENDED_CPU_SIG 0x80000001
#define EFI_CPUID_BRAND_STRING1 0x80000002
#define EFI_CPUID_BRAND_STRING2 0x80000003
#define EFI_CPUID_BRAND_STRING3 0x80000004
//
// CPUID version information masks
// Note: leaving masks here is for the compatibility
// use EfiCpuVersion (...) instead
//
#define EFI_CPUID_FAMILY 0x0F00
#define EFI_CPUID_MODEL 0x00F0
#define EFI_CPUID_STEPPING 0x000F
#define EFI_CPUID_PENTIUM_M 0x0600
#define EFI_CPUID_BANIAS 0x0090
#define EFI_CPUID_DOTHAN 0x00D0
#define EFI_CPUID_NETBURST 0x0F00
#define EFI_MSR_IA32_PLATFORM_ID 0x17
#define EFI_MSR_IA32_APIC_BASE 0x1B
#define EFI_MSR_EBC_HARD_POWERON 0x2A
#define EFI_MSR_EBC_SOFT_POWERON 0x2B
#define BINIT_DRIVER_DISABLE 0x40
#define INTERNAL_MCERR_DISABLE 0x20
#define INITIATOR_MCERR_DISABLE 0x10
#define EFI_MSR_EBC_FREQUENCY_ID 0x2C
#define EFI_MSR_IA32_BIOS_UPDT_TRIG 0x79
#define EFI_MSR_IA32_BIOS_SIGN_ID 0x8B
#define EFI_MSR_PSB_CLOCK_STATUS 0xCD
#define EFI_APIC_GLOBAL_ENABLE 0x800
#define EFI_MSR_IA32_MISC_ENABLE 0x1A0
#define LIMIT_CPUID_MAXVAL_ENABLE_BIT 0x00400000
#define AUTOMATIC_THERMAL_CONTROL_ENABLE_BIT 0x00000008
#define COMPATIBLE_FPU_OPCODE_ENABLE_BIT 0x00000004
#define LOGICAL_PROCESSOR_PRIORITY_ENABLE_BIT 0x00000002
#define FAST_STRING_ENABLE_BIT 0x00000001
#define EFI_CACHE_VARIABLE_MTRR_BASE 0x200
#define EFI_CACHE_VARIABLE_MTRR_END 0x20F
#define EFI_CACHE_IA32_MTRR_DEF_TYPE 0x2FF
#define EFI_CACHE_VALID_ADDRESS 0xFFFFFF000
#define EFI_CACHE_MTRR_VALID 0x800
#define EFI_CACHE_FIXED_MTRR_VALID 0x400
#define EFI_MSR_VALID_MASK 0xFFFFFFFFF
#define EFI_IA32_MTRR_FIX64K_00000 0x250
#define EFI_IA32_MTRR_FIX16K_80000 0x258
#define EFI_IA32_MTRR_FIX16K_A0000 0x259
#define EFI_IA32_MTRR_FIX4K_C0000 0x268
#define EFI_IA32_MTRR_FIX4K_C8000 0x269
#define EFI_IA32_MTRR_FIX4K_D0000 0x26A
#define EFI_IA32_MTRR_FIX4K_D8000 0x26B
#define EFI_IA32_MTRR_FIX4K_E0000 0x26C
#define EFI_IA32_MTRR_FIX4K_E8000 0x26D
#define EFI_IA32_MTRR_FIX4K_F0000 0x26E
#define EFI_IA32_MTRR_FIX4K_F8000 0x26F
#define EFI_IA32_MCG_CAP 0x179
#define EFI_IA32_MCG_CTL 0x17B
#define EFI_IA32_MC0_CTL 0x400
#define EFI_IA32_MC0_STATUS 0x401
#define EFI_CACHE_UNCACHEABLE 0
#define EFI_CACHE_WRITECOMBINING 1
#define EFI_CACHE_WRITETHROUGH 4
#define EFI_CACHE_WRITEPROTECTED 5
#define EFI_CACHE_WRITEBACK 6
//
// Combine f(FamilyId), m(Model), s(SteppingId) to a single 32 bit number
//
#define EfiMakeCpuVersion(f, m, s) \
(((UINT32) (f) << 16) | ((UINT32) (m) << 8) | ((UINT32) (s)))
typedef struct {
UINT32 HeaderVersion;
UINT32 UpdateRevision;
UINT32 Date;
UINT32 ProcessorId;
UINT32 Checksum;
UINT32 LoaderRevision;
UINT32 ProcessorFlags;
UINT32 DataSize;
UINT32 TotalSize;
UINT8 Reserved[12];
} EFI_CPU_MICROCODE_HEADER;
typedef struct {
UINT32 ExtSigCount;
UINT32 ExtChecksum;
UINT8 Reserved[12];
UINT32 ProcessorId;
UINT32 ProcessorFlags;
UINT32 Checksum;
} EFI_CPU_MICROCODE_EXT_HEADER;
typedef struct {
UINT32 RegEax;
UINT32 RegEbx;
UINT32 RegEcx;
UINT32 RegEdx;
} EFI_CPUID_REGISTER;
VOID
EfiWriteMsr (
IN UINT32 Input,
IN UINT64 Value
)
/*++
Routine Description:
Write Cpu MSR
Arguments:
Input -The index value to select the register
Value -The value to write to the selected register
Returns:
None
--*/
;
UINT64
EfiReadMsr (
IN UINT32 Input
)
/*++
Routine Description:
Read Cpu MSR.
Arguments:
Input: -The index value to select the register
Returns:
Return the read data
--*/
;
VOID
EfiCpuid (
IN UINT32 RegEax,
OUT EFI_CPUID_REGISTER *Reg
)
/*++
Routine Description:
Get the Cpu info by excute the CPUID instruction.
Arguments:
RegEax -The input value to put into register EAX
Reg -The Output value
Returns:
None
--*/
;
VOID
EfiCpuVersion (
IN UINT16 *FamilyId, OPTIONAL
IN UINT8 *Model, OPTIONAL
IN UINT8 *SteppingId, OPTIONAL
IN UINT8 *Processor OPTIONAL
)
/*++
Routine Description:
Extract CPU detail version infomation
Arguments:
FamilyId - FamilyId, including ExtendedFamilyId
Model - Model, including ExtendedModel
SteppingId - SteppingId
Processor - Processor
--*/
;
UINT64
EfiReadTsc (
VOID
)
/*++
Routine Description:
Read Time stamp.
Arguments:
None
Returns:
Return the read data
--*/
;
VOID
EfiCpuidExt (
IN UINT32 RegisterInEax,
IN UINT32 CacheLevel,
OUT EFI_CPUID_REGISTER *Regs
)
/*++
Routine Description:
When RegisterInEax != 4, the functionality is the same as EfiCpuid.
When RegisterInEax == 4, the function return the deterministic cache
parameters by excuting the CPUID instruction
Arguments:
RegisterInEax: - The input value to put into register EAX
CacheLevel: - The deterministic cache level
Regs: - The Output value
Returns:
None
--*/
;
#endif

View File

@@ -0,0 +1,26 @@
/*++
Copyright (c) 2004, 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:
ProcDep.h
Abstract:
IA-32 specific Runtime Lib code. At this time there is non.
IPF has different code due to extra API requirements.
--*/
#ifndef _PROC_DEP_H_
#define _PROC_DEP_H_
#endif

View File

@@ -0,0 +1,111 @@
/*++
Copyright (c) 2004, 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:
Ia32EfiRuntimeDriverLib.h
Abstract:
Light weight lib to support IA32 EFI Libraries.
--*/
#ifndef _IA32_EFI_RUNTIME_LIB_H_
#define _IA32_EFI_RUNTIME_LIB_H_
#include "Tiano.h"
#include "EfiRuntimeLib.h"
#include EFI_PROTOCOL_DEFINITION (ExtendedSalGuid)
typedef
EFI_STATUS
(EFIAPI *COMMON_PROC_ENTRY) (
IN UINTN FunctionId,
IN UINTN Arg2,
IN UINTN Arg3,
IN UINTN Arg4,
IN UINTN Arg5,
IN UINTN Arg6,
IN UINTN Arg7,
IN UINTN Arg8
);
typedef struct {
COMMON_PROC_ENTRY CommonProcEntry;
} COMMON_PROC_ENTRY_STRUCT;
EFI_STATUS
InstallPlatformRuntimeLib (
IN EFI_GUID *Guid,
IN COMMON_PROC_ENTRY_STRUCT *CommonEntry
)
/*++
Routine Description:
Install platform runtime lib.
Arguments:
Guid - Guid for runtime lib
CommonEntry - Common entry
Returns:
Status code
--*/
;
EFI_STATUS
GetPlatformRuntimeLib (
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Get platform runtime lib.
Arguments:
SystemTable - Pointer to system table
Returns:
Status code
--*/
;
EFI_STATUS
ConvertPlatformRuntimeLibPtr (
IN EFI_RUNTIME_SERVICES *mRT
)
/*++
Routine Description:
Convert platform runtime lib pointer.
Arguments:
mRT - Pointer to runtime service table.
Returns:
Status code
--*/
;
#endif

View File

@@ -0,0 +1,93 @@
/*++
Copyright (c) 2004, 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:
CpuFuncs.h
Abstract:
--*/
#ifndef _CPU_FUNCS_H
#define _CPU_FUNCS_H
#define EFI_CPUID_SIGNATURE 0x0
#define EFI_CPUID_VERSION_INFO 0x1
#define EFI_CPUID_CACHE_INFO 0x2
#define EFI_CPUID_SERIAL_NUMBER 0x3
#define EFI_CPUID_EXTENDED_FUNCTION 0x80000000
#define EFI_CPUID_EXTENDED_CPU_SIG 0x80000001
#define EFI_CPUID_BRAND_STRING1 0x80000002
#define EFI_CPUID_BRAND_STRING2 0x80000003
#define EFI_CPUID_BRAND_STRING3 0x80000004
#define EFI_MSR_IA32_APIC_BASE 0x1B
#define EFI_MSR_EBC_HARD_POWERON 0x2A
#define EFI_MSR_EBC_SOFT_POWERON 0x2B
#define EFI_MSR_EBC_FREQUENCY_ID 0x2C
#define EFI_MSR_IA32_BIOS_UPDT_TRIG 0x79
#define EFI_MSR_IA32_BIOS_SIGN_ID 0x8B
#define EFI_APIC_GLOBAL_ENABLE 0x800
#define EFI_CACHE_VARIABLE_MTRR_BASE 0x200
#define EFI_CACHE_VARIABLE_MTRR_END 0x20F
#define EFI_CACHE_IA32_MTRR_DEF_TYPE 0x2FF
#define EFI_CACHE_VALID_ADDRESS 0xFFFFFF000
#define EFI_CACHE_MTRR_VALID 0x800
#define EFI_CACHE_FIXED_MTRR_VALID 0x400
#define EFI_MSR_VALID_MASK 0xFFFFFFFFF
#define EFI_IA32_MTRR_FIX64K_00000 0x250
#define EFI_IA32_MTRR_FIX16K_80000 0x258
#define EFI_IA32_MTRR_FIX16K_A0000 0x259
#define EFI_IA32_MTRR_FIX4K_C0000 0x268
#define EFI_IA32_MTRR_FIX4K_C8000 0x269
#define EFI_IA32_MTRR_FIX4K_D0000 0x26A
#define EFI_IA32_MTRR_FIX4K_D8000 0x26B
#define EFI_IA32_MTRR_FIX4K_E0000 0x26C
#define EFI_IA32_MTRR_FIX4K_E8000 0x26D
#define EFI_IA32_MTRR_FIX4K_F0000 0x26E
#define EFI_IA32_MTRR_FIX4K_F8000 0x26F
#define EFI_IA32_MCG_CAP 0x179
#define EFI_IA32_MCG_CTL 0x17B
#define EFI_IA32_MC0_CTL 0x400
#define EFI_IA32_MC0_STATUS 0x401
#define EFI_CACHE_UNCACHEABLE 0
#define EFI_CACHE_WRITECOMBINING 1
#define EFI_CACHE_WRITETHROUGH 4
#define EFI_CACHE_WRITEPROTECTED 5
#define EFI_CACHE_WRITEBACK 6
UINT64
EfiReadTsc (
VOID
)
/*++
Routine Description:
Read Time stamp.
Arguments:
None
Returns:
Return the read data
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,119 @@
/*++
Copyright (c) 2004, 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:
ProcDep.h
Abstract:
IPF specific Runtime Lib code. IPF has a SAL API that does not
exit on IA-32. Thus
--*/
#ifndef _PROC_DEP_H_
#define _PROC_DEP_H_
#include EFI_PROTOCOL_DEFINITION (ExtendedSalGuid)
#include EFI_PROTOCOL_DEFINITION (ExtendedSalBootService)
#include "SalApi.h"
EFI_STATUS
RegisterEsalFunction (
IN UINT64 FunctionId,
IN EFI_GUID *ClassGuid,
IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,
IN VOID *ModuleGlobal
)
/*++
Routine Description:
Register ESAL Class Function and it's asociated global.
This function is boot service only!
Arguments:
FunctionId - ID of function to register
ClassGuid - GUID of function class
Function - Function to register under ClassGuid/FunctionId pair
ModuleGlobal - Module global for Function.
Returns:
EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.
--*/
;
EFI_STATUS
RegisterEsalClass (
IN EFI_GUID *ClassGuid,
IN VOID *ModuleGlobal,
...
)
/*++
Routine Description:
Register ESAL Class and it's asociated global.
This function is boot service only!
Arguments:
ClassGuid - GUID of function class
ModuleGlobal - Module global for Function.
.. - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL
indicates the end of the list.
Returns:
EFI_SUCCESS - All members of ClassGuid registered
--*/
;
SAL_RETURN_REGS
EfiCallEsalService (
IN EFI_GUID *ClassGuid,
IN UINT64 FunctionId,
IN UINT64 Arg2,
IN UINT64 Arg3,
IN UINT64 Arg4,
IN UINT64 Arg5,
IN UINT64 Arg6,
IN UINT64 Arg7,
IN UINT64 Arg8
)
/*++
Routine Description:
Call module that is not linked direclty to this module. This code is IP
relative and hides the binding issues of virtual or physical calling. The
function that gets dispatched has extra arguments that include the registered
module global and a boolean flag to indicate if the system is in virutal mode.
Arguments:
ClassGuid - GUID of function
FunctionId - Function in ClassGuid to call
Arg2 - Argument 2 ClassGuid/FunctionId defined
Arg3 - Argument 3 ClassGuid/FunctionId defined
Arg4 - Argument 4 ClassGuid/FunctionId defined
Arg5 - Argument 5 ClassGuid/FunctionId defined
Arg6 - Argument 6 ClassGuid/FunctionId defined
Arg7 - Argument 7 ClassGuid/FunctionId defined
Arg8 - Argument 8 ClassGuid/FunctionId defined
Returns:
Status of ClassGuid/FuncitonId
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,310 @@
/*++
Copyright (c) 2004, 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:
LinkedList.h
Abstract:
This implementation of a linked list provides data structures for the
list itself and for list nodes. It provides operations for initializing
the list, modifying the list, and walking the list.
--*/
//
// Prevent multiple includes in the same source file
//
#ifndef _LINKED_LIST_H_
#define _LINKED_LIST_H_
typedef struct _EFI_LIST_ENTRY {
struct _EFI_LIST_ENTRY *ForwardLink;
struct _EFI_LIST_ENTRY *BackLink;
} EFI_LIST_ENTRY;
typedef EFI_LIST_ENTRY EFI_LIST;
typedef EFI_LIST_ENTRY EFI_LIST_NODE;
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
//
// EFI_FIELD_OFFSET - returns the byte offset to a field within a structure
//
#define EFI_FIELD_OFFSET(TYPE,Field) ((UINTN)(&(((TYPE *) 0)->Field)))
//
// A lock structure
//
typedef struct {
EFI_TPL Tpl;
EFI_TPL OwnerTpl;
UINTN Lock;
} FLOCK;
VOID
InitializeListHead (
EFI_LIST_ENTRY *List
)
/*++
Routine Description:
Initialize the head of the List. The caller must allocate the memory
for the EFI_LIST. This function must be called before the other linked
list macros can be used.
Arguments:
List - Pointer to list head to initialize
Returns:
None.
--*/
;
BOOLEAN
IsListEmpty (
EFI_LIST_ENTRY *List
)
/*++
Routine Description:
Return TRUE is the list contains zero nodes. Otherzise return FALSE.
The list must have been initialized with InitializeListHead () before using
this function.
Arguments:
List - Pointer to list head to test
Returns:
Return TRUE is the list contains zero nodes. Otherzise return FALSE.
--*/
;
VOID
RemoveEntryList (
EFI_LIST_ENTRY *Entry
)
/*++
Routine Description:
Remove Node from the doubly linked list. It is the caller's responsibility
to free any memory used by the entry if needed. The list must have been
initialized with InitializeListHead () before using this function.
Arguments:
Entry - Element to remove from the list.
Returns:
None
--*/
;
VOID
InsertTailList (
EFI_LIST_ENTRY *ListHead,
EFI_LIST_ENTRY *Entry
)
/*++
Routine Description:
Insert a Node into the end of a doubly linked list. The list must have
been initialized with InitializeListHead () before using this function.
Arguments:
ListHead - Head of doubly linked list
Entry - Element to insert at the end of the list.
Returns:
None
--*/
;
VOID
InsertHeadList (
EFI_LIST_ENTRY *ListHead,
EFI_LIST_ENTRY *Entry
)
/*++
Routine Description:
Insert a Node into the start of a doubly linked list. The list must have
been initialized with InitializeListHead () before using this function.
Arguments:
ListHead - Head of doubly linked list
Entry - Element to insert to beginning of list
Returns:
None
--*/
;
VOID
SwapListEntries (
EFI_LIST_ENTRY *Entry1,
EFI_LIST_ENTRY *Entry2
)
/*++
Routine Description:
Swap the location of the two elements of a doubly linked list. Node2
is placed in front of Node1. The list must have been initialized with
InitializeListHead () before using this function.
Arguments:
Entry1 - Element in the doubly linked list in front of Node2.
Entry2 - Element in the doubly linked list behind Node1.
Returns:
None
--*/
;
EFI_LIST_ENTRY *
GetFirstNode (
EFI_LIST_ENTRY *List
)
/*++
Routine Description:
Return the first node pointed to by the list head. The list must
have been initialized with InitializeListHead () before using this
function and must contain data.
Arguments:
List - The head of the doubly linked list.
Returns:
Pointer to the first node, if the list contains nodes. The list will
return a null value--that is, the value of List--when the list is empty.
See the description of IsNull for more information.
--*/
;
EFI_LIST_ENTRY *
GetNextNode (
EFI_LIST_ENTRY *List,
EFI_LIST_ENTRY *Node
)
/*++
Routine Description:
Returns the node following Node in the list. The list must
have been initialized with InitializeListHead () before using this
function and must contain data.
Arguments:
List - The head of the list. MUST NOT be the literal value NULL.
Node - The node in the list. This value MUST NOT be the literal value NULL.
See the description of IsNull for more information.
Returns:
Pointer to the next node, if one exists. Otherwise, returns a null value,
which is actually a pointer to List.
See the description of IsNull for more information.
--*/
;
BOOLEAN
IsNull (
EFI_LIST_ENTRY *List,
EFI_LIST_ENTRY *Node
)
/*++
Routine Description:
Determines whether the given node is null. Note that Node is null
when its value is equal to the value of List. It is an error for
Node to be the literal value NULL [(VOID*)0x0].
Arguments:
List - The head of the list. MUST NOT be the literal value NULL.
Node - The node to test. MUST NOT be the literal value NULL. See
the description above.
Returns:
Returns true if the node is null.
--*/
;
BOOLEAN
IsNodeAtEnd (
EFI_LIST_ENTRY *List,
EFI_LIST_ENTRY *Node
)
/*++
Routine Description:
Determines whether the given node is at the end of the list. Used
to walk the list. The list must have been initialized with
InitializeListHead () before using this function and must contain
data.
Arguments:
List - The head of the list. MUST NOT be the literal value NULL.
Node - The node to test. MUST NOT be the literal value NULL.
See the description of IsNull for more information.
Returns:
Returns true if the list is the tail.
--*/
;
#endif

View File

@@ -0,0 +1,231 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
RtDevicePath.h
Abstract:
Device Path services. The thing to remember is device paths are built out of
nodes. The device path is terminated by an end node that is length
sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
all over this file.
The only place where multi-instance device paths are supported is in
environment varibles. Multi-instance device paths should never be placed
on a Handle.
--*/
#ifndef _RT_DEVICE_PATH_H_
#define _RT_DEVICE_PATH_H_
BOOLEAN
RtEfiIsDevicePathMultiInstance (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
/*++
Routine Description:
Return TRUE is this is a multi instance device path.
Arguments:
DevicePath - A pointer to a device path data structure.
Returns:
TRUE - If DevicePath is multi instance.
FALSE - If DevicePath is not multi instance.
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiDevicePathInstance (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT UINTN *Size
)
/*++
Routine Description:
Function retrieves the next device path instance from a device path data structure.
Arguments:
DevicePath - A pointer to a device path data structure.
Size - A pointer to the size of a device path instance in bytes.
Returns:
This function returns a pointer to the current device path instance.
In addition, it returns the size in bytes of the current device path instance in Size,
and a pointer to the next device path instance in DevicePath.
If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.
--*/
;
UINTN
RtEfiDevicePathSize (
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
)
/*++
Routine Description:
Calculate the size of a whole device path.
Arguments:
DevPath - The pointer to the device path data.
Returns:
Size of device path data structure..
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiAppendDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *Src1,
IN EFI_DEVICE_PATH_PROTOCOL *Src2
)
/*++
Routine Description:
Function is used to append a Src1 and Src2 together.
Arguments:
Src1 - A pointer to a device path data structure.
Src2 - A pointer to a device path data structure.
Returns:
A pointer to the new device path is returned.
NULL is returned if space for the new device path could not be allocated from pool.
It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiDevicePathFromHandle (
IN EFI_HANDLE Handle
)
/*++
Routine Description:
Locate device path protocol interface on a device handle.
Arguments:
Handle - The device handle
Returns:
Device path protocol interface located.
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiDuplicateDevicePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevPath
)
/*++
Routine Description:
Duplicate a new device path data structure from the old one.
Arguments:
DevPath - A pointer to a device path data structure.
Returns:
A pointer to the new allocated device path data.
Caller must free the memory used by DevicePath if it is no longer needed.
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiAppendDevicePathNode (
IN EFI_DEVICE_PATH_PROTOCOL *Src1,
IN EFI_DEVICE_PATH_PROTOCOL *Src2
)
/*++
Routine Description:
Function is used to append a device path node to the end of another device path.
Arguments:
Src1 - A pointer to a device path data structure.
Src2 - A pointer to a device path data structure.
Returns:
This function returns a pointer to the new device path.
If there is not enough temporary pool memory available to complete this function,
then NULL is returned.
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiFileDevicePath (
IN EFI_HANDLE Device OPTIONAL,
IN CHAR16 *FileName
)
/*++
Routine Description:
Create a device path that appends a MEDIA_DEVICE_PATH with
FileNameGuid to the device path of DeviceHandle.
Arguments:
Device - Optional Device Handle to use as Root of the Device Path
FileName - FileName
Returns:
EFI_DEVICE_PATH_PROTOCOL that was allocated from dynamic memory
or NULL pointer.
--*/
;
EFI_DEVICE_PATH_PROTOCOL *
RtEfiAppendDevicePathInstance (
IN EFI_DEVICE_PATH_PROTOCOL *Src,
IN EFI_DEVICE_PATH_PROTOCOL *Instance
)
/*++
Routine Description:
Append a device path instance to another.
Arguments:
Src - The device path instance to be appended with.
Instance - The device path instance appending the other.
Returns:
The contaction of these two.
--*/
;
#endif

View File

@@ -0,0 +1,75 @@
/*++
Copyright (c) 2004, 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:
SmmRuntimeLib.h
Abstract:
SMM Related prototypes that can be referenced for Preboot Configuration only.
--*/
#ifndef _SMM_RUNTIME_LIB_H_
#define _SMM_RUNTIME_LIB_H_
#include "Tiano.h"
#include "EfiRuntimeLib.h"
BOOLEAN
EfiInSmm (
VOID
)
/*++
Routine Description:
Test whether in Smm mode currently.
Arguments:
None
Returns:
TRUE - In Smm mode
FALSE - Not in Smm mode
--*/
;
EFI_STATUS
RegisterSmmRuntimeDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable,
OUT EFI_HANDLE *SmmImageHandle
)
/*++
Routine Description:
Registers a Driver with the SMM.
Arguments:
ImageHandle - The firmware allocated handle for the EFI image.
SystemTable - A pointer to the EFI System Table.
SmmImageHandle - Image handle returned by the SMM driver.
Returns:
Status code
--*/
;
#endif

View File

@@ -0,0 +1,262 @@
/*++
Copyright (c) 2005 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
CpuFuncs.h
Abstract:
--*/
#ifndef _CPU_FUNCS_H_
#define _CPU_FUNCS_H_
#define EFI_CPUID_SIGNATURE 0x0
#define EFI_CPUID_VERSION_INFO 0x1
#define EFI_CPUID_CACHE_INFO 0x2
#define EFI_CPUID_SERIAL_NUMBER 0x3
#define EFI_CPUID_EXTENDED_FUNCTION 0x80000000
#define EFI_CPUID_EXTENDED_CPU_SIG 0x80000001
#define EFI_CPUID_BRAND_STRING1 0x80000002
#define EFI_CPUID_BRAND_STRING2 0x80000003
#define EFI_CPUID_BRAND_STRING3 0x80000004
//
// CPUID version information masks
// Note: leaving masks here is for the compatibility
// use EfiCpuVersion (...) instead
//
#define EFI_CPUID_FAMILY 0x0F00
#define EFI_CPUID_MODEL 0x00F0
#define EFI_CPUID_STEPPING 0x000F
#define EFI_CPUID_PENTIUM_M 0x0600
#define EFI_CPUID_BANIAS 0x0090
#define EFI_CPUID_DOTHAN 0x00D0
#define EFI_CPUID_NETBURST 0x0F00
#define EFI_MSR_IA32_PLATFORM_ID 0x17
#define EFI_MSR_IA32_APIC_BASE 0x1B
#define EFI_MSR_EBC_HARD_POWERON 0x2A
#define EFI_MSR_EBC_SOFT_POWERON 0x2B
#define BINIT_DRIVER_DISABLE 0x40
#define INTERNAL_MCERR_DISABLE 0x20
#define INITIATOR_MCERR_DISABLE 0x10
#define EFI_MSR_EBC_FREQUENCY_ID 0x2C
#define EFI_MSR_IA32_BIOS_UPDT_TRIG 0x79
#define EFI_MSR_IA32_BIOS_SIGN_ID 0x8B
#define EFI_MSR_PSB_CLOCK_STATUS 0xCD
#define EFI_APIC_GLOBAL_ENABLE 0x800
#define EFI_MSR_IA32_MISC_ENABLE 0x1A0
#define LIMIT_CPUID_MAXVAL_ENABLE_BIT 0x00400000
#define AUTOMATIC_THERMAL_CONTROL_ENABLE_BIT 0x00000008
#define COMPATIBLE_FPU_OPCODE_ENABLE_BIT 0x00000004
#define LOGICAL_PROCESSOR_PRIORITY_ENABLE_BIT 0x00000002
#define FAST_STRING_ENABLE_BIT 0x00000001
#define EFI_CACHE_VARIABLE_MTRR_BASE 0x200
#define EFI_CACHE_VARIABLE_MTRR_END 0x20F
#define EFI_CACHE_IA32_MTRR_DEF_TYPE 0x2FF
#define EFI_CACHE_VALID_ADDRESS 0xFFFFFF000
#define EFI_CACHE_MTRR_VALID 0x800
#define EFI_CACHE_FIXED_MTRR_VALID 0x400
#define EFI_MSR_VALID_MASK 0xFFFFFFFFF
#define EFI_IA32_MTRR_FIX64K_00000 0x250
#define EFI_IA32_MTRR_FIX16K_80000 0x258
#define EFI_IA32_MTRR_FIX16K_A0000 0x259
#define EFI_IA32_MTRR_FIX4K_C0000 0x268
#define EFI_IA32_MTRR_FIX4K_C8000 0x269
#define EFI_IA32_MTRR_FIX4K_D0000 0x26A
#define EFI_IA32_MTRR_FIX4K_D8000 0x26B
#define EFI_IA32_MTRR_FIX4K_E0000 0x26C
#define EFI_IA32_MTRR_FIX4K_E8000 0x26D
#define EFI_IA32_MTRR_FIX4K_F0000 0x26E
#define EFI_IA32_MTRR_FIX4K_F8000 0x26F
#define EFI_IA32_MCG_CAP 0x179
#define EFI_IA32_MCG_CTL 0x17B
#define EFI_IA32_MC0_CTL 0x400
#define EFI_IA32_MC0_STATUS 0x401
#define EFI_CACHE_UNCACHEABLE 0
#define EFI_CACHE_WRITECOMBINING 1
#define EFI_CACHE_WRITETHROUGH 4
#define EFI_CACHE_WRITEPROTECTED 5
#define EFI_CACHE_WRITEBACK 6
//
// Combine f(FamilyId), m(Model), s(SteppingId) to a single 32 bit number
//
#define EfiMakeCpuVersion(f, m, s) \
(((UINT32) (f) << 16) | ((UINT32) (m) << 8) | ((UINT32) (s)))
typedef struct {
UINT32 HeaderVersion;
UINT32 UpdateRevision;
UINT32 Date;
UINT32 ProcessorId;
UINT32 Checksum;
UINT32 LoaderRevision;
UINT32 ProcessorFlags;
UINT32 DataSize;
UINT32 TotalSize;
UINT8 Reserved[12];
} EFI_CPU_MICROCODE_HEADER;
typedef struct {
UINT32 ExtSigCount;
UINT32 ExtChecksum;
UINT8 Reserved[12];
UINT32 ProcessorId;
UINT32 ProcessorFlags;
UINT32 Checksum;
} EFI_CPU_MICROCODE_EXT_HEADER;
typedef struct {
UINT32 RegEax;
UINT32 RegEbx;
UINT32 RegEcx;
UINT32 RegEdx;
} EFI_CPUID_REGISTER;
VOID
EfiWriteMsr (
IN UINT32 Input,
IN UINT64 Value
)
/*++
Routine Description:
Write Cpu MSR
Arguments:
Input -The index value to select the register
Value -The value to write to the selected register
Returns:
None
--*/
;
UINT64
EfiReadMsr (
IN UINT32 Input
)
/*++
Routine Description:
Read Cpu MSR.
Arguments:
Input: -The index value to select the register
Returns:
Return the read data
--*/
;
VOID
EfiCpuid (
IN UINT32 RegEax,
OUT EFI_CPUID_REGISTER *Reg
)
/*++
Routine Description:
Get the Cpu info by excute the CPUID instruction.
Arguments:
RegEax -The input value to put into register EAX
Reg -The Output value
Returns:
None
--*/
;
VOID
EfiCpuVersion (
IN UINT16 *FamilyId, OPTIONAL
IN UINT8 *Model, OPTIONAL
IN UINT8 *SteppingId, OPTIONAL
IN UINT8 *Processor OPTIONAL
)
/*++
Routine Description:
Extract CPU detail version infomation
Arguments:
FamilyId - FamilyId, including ExtendedFamilyId
Model - Model, including ExtendedModel
SteppingId - SteppingId
Processor - Processor
--*/
;
UINT64
EfiReadTsc (
VOID
)
/*++
Routine Description:
Read Time stamp.
Arguments:
None
Returns:
Return the read data
--*/
;
VOID
EfiCpuidExt (
IN UINT32 RegisterInEax,
IN UINT32 CacheLevel,
OUT EFI_CPUID_REGISTER *Regs
)
/*++
Routine Description:
When RegisterInEax != 4, the functionality is the same as EfiCpuid.
When RegisterInEax == 4, the function return the deterministic cache
parameters by excuting the CPUID instruction
Arguments:
RegisterInEax: - The input value to put into register EAX
CacheLevel: - The deterministic cache level
Regs: - The Output value
Returns:
None
--*/
;
#endif

View File

@@ -0,0 +1,29 @@
/*++
Copyright (c) 2005, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
ProcDep.h
Abstract:
x64 specific Runtime Lib code. At this time there is non.
IPF has different code due to extra API requirements.
--*/
#ifndef _PROC_DEP_H_
#define _PROC_DEP_H_
#endif

View File

@@ -0,0 +1,88 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Ascii
STRING_W is ""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR8 CHAR_W;
#define STRING_W(_s) _s
#define ASPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define AvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
UINTN
UvSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN StrLen,
IN CONST CHAR16 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
StartOfBuffer - Wide char buffer to print the results of the parsing of Format into.
StrLen - Maximum number of characters to put into buffer.
Format - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
UvSPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
AsciiFormat[Index] = (CHAR8) FormatString[Index];
}
AsciiFormat[Index] = '\0';
Index = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR16) AsciiResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,212 @@
/*++
Copyright (c) 2004, 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:
BoxDraw.c
Abstract:
Lib functions to support Box Draw Unicode code pages.
Revision History
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
typedef struct {
CHAR16 Unicode;
CHAR8 PcAnsi;
CHAR8 Ascii;
} UNICODE_TO_CHAR;
//
// This list is used to define the valid extend chars.
// It also provides a mapping from Unicode to PCANSI or
// ASCII. The ASCII mapping we just made up.
//
//
static UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
BOXDRAW_HORIZONTAL, 0xc4, L'-',
BOXDRAW_VERTICAL, 0xb3, L'|',
BOXDRAW_DOWN_RIGHT, 0xda, L'/',
BOXDRAW_DOWN_LEFT, 0xbf, L'\\',
BOXDRAW_UP_RIGHT, 0xc0, L'\\',
BOXDRAW_UP_LEFT, 0xd9, L'/',
BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|',
BOXDRAW_VERTICAL_LEFT, 0xb4, L'|',
BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+',
BOXDRAW_UP_HORIZONTAL, 0xc1, L'+',
BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+',
BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-',
BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|',
BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/',
BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/',
BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/',
BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\',
BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\',
BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\',
BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\',
BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\',
BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\',
BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/',
BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/',
BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/',
BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|',
BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|',
BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|',
BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|',
BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|',
BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|',
BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+',
BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+',
BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+',
BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+',
BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+',
BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+',
BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+',
BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+',
BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+',
BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*',
BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+',
GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^',
GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>',
GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v',
GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<',
ARROW_LEFT, 0x3c, L'<',
ARROW_UP, 0x18, L'^',
ARROW_RIGHT, 0x3e, L'>',
ARROW_DOWN, 0x19, L'v',
0x0000, 0x00
};
BOOLEAN
LibIsValidTextGraphics (
IN CHAR16 Graphic,
OUT CHAR8 *PcAnsi, OPTIONAL
OUT CHAR8 *Ascii OPTIONAL
)
/*++
Routine Description:
Detects if a Unicode char is for Box Drawing text graphics.
Arguments:
Grphic - Unicode char to test.
PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
Asci - Optional pointer to return Ascii equivalent of Graphic.
Returns:
TRUE if Gpaphic is a supported Unicode Box Drawing character.
--*/
{
UNICODE_TO_CHAR *Table;
if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {
//
// Unicode drawing code charts are all in the 0x25xx range,
// arrows are 0x21xx
//
return FALSE;
}
for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {
if (Graphic == Table->Unicode) {
if (PcAnsi != NULL) {
*PcAnsi = Table->PcAnsi;
}
if (Ascii != NULL) {
*Ascii = Table->Ascii;
}
return TRUE;
}
}
return FALSE;
}
BOOLEAN
IsValidAscii (
IN CHAR16 Ascii
)
/*++
Routine Description:
Is it valid ascii char?
Arguments:
Ascii - The char to check
Returns:
TRUE - Is a ascii char
FALSE - Not a ascii char
--*/
{
if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {
return TRUE;
}
return FALSE;
}
BOOLEAN
IsValidEfiCntlChar (
IN CHAR16 CharC
)
/*++
Routine Description:
Is it valid EFI control char?
Arguments:
Ascii - The char to check
Returns:
TRUE - Is a valid EFI control char
FALSE - Not a valid EFI control char
--*/
{
if (CharC == CHAR_NULL || CharC == CHAR_BACKSPACE || CharC == CHAR_LINEFEED || CharC == CHAR_CARRIAGE_RETURN) {
return TRUE;
}
return FALSE;
}

View File

@@ -0,0 +1,585 @@
/*++
Copyright (c) 2004, 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:
Print.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "EfiCommonLib.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
STATIC
CHAR_W *
GetFlagsAndWidth (
IN CHAR_W *Format,
OUT UINTN *Flags,
OUT UINTN *Width,
IN OUT VA_LIST *Marker
);
STATIC
UINTN
GuidToString (
IN EFI_GUID *Guid,
IN OUT CHAR_W *Buffer,
IN UINTN BufferSize
);
STATIC
UINTN
TimeToString (
IN EFI_TIME *Time,
IN OUT CHAR_W *Buffer,
IN UINTN BufferSize
);
STATIC
UINTN
EfiStatusToString (
IN EFI_STATUS Status,
OUT CHAR_W *Buffer,
IN UINTN BufferSize
);
UINTN
SPrint (
OUT CHAR_W *Buffer,
IN UINTN BufferSize,
IN CONST CHAR_W *Format,
...
)
/*++
Routine Description:
SPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = VSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
VSPrint (
OUT CHAR_W *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR_W *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
VSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine
Arguments:
StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means
no limit.
FormatString - Unicode format string see file header for more details.
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];
CHAR_W *Buffer;
CHAR8 *AsciiStr;
CHAR16 *UnicodeStr;
CHAR_W *Format;
UINTN Index;
UINTN Flags;
UINTN Width;
UINTN Count;
UINTN NumberOfCharacters;
UINTN BufferLeft;
UINT64 Value;
EFI_GUID *TmpGUID;
//
// Process the format string. Stop if Buffer is over run.
//
Buffer = StartOfBuffer;
Format = (CHAR_W *)FormatString;
NumberOfCharacters = BufferSize/sizeof(CHAR_W);
BufferLeft = BufferSize;
for (Index = 0; (*Format != '\0') && (Index < NumberOfCharacters - 1); Format++) {
if (*Format != '%') {
if ((*Format == '\n') && (Index < NumberOfCharacters - 2)) {
//
// If carage return add line feed
//
Buffer[Index++] = '\r';
BufferLeft -= sizeof(CHAR_W);
}
Buffer[Index++] = *Format;
BufferLeft -= sizeof(CHAR_W);
} else {
//
// Now it's time to parse what follows after %
//
Format = GetFlagsAndWidth (Format, &Flags, &Width, &Marker);
switch (*Format) {
case 'X':
Flags |= PREFIX_ZERO;
Width = sizeof (UINT64) * 2;
//
// break skiped on purpose
//
case 'x':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = VA_ARG (Marker, UINTN);
}
EfiValueToHexStr (TempBuffer, Value, Flags, Width);
UnicodeStr = TempBuffer;
for ( ;(*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) {
Buffer[Index++] = *UnicodeStr;
}
break;
case 'd':
if ((Flags & LONG_TYPE) == LONG_TYPE) {
Value = VA_ARG (Marker, UINT64);
} else {
Value = (UINTN)VA_ARG (Marker, UINTN);
}
EfiValueToString (TempBuffer, Value, Flags, Width);
UnicodeStr = TempBuffer;
for ( ;(*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) {
Buffer[Index++] = *UnicodeStr;
}
break;
case 's':
case 'S':
UnicodeStr = (CHAR16 *)VA_ARG (Marker, CHAR_W *);
if (UnicodeStr == NULL) {
UnicodeStr = L"<null string>";
}
for (Count = 0 ;(*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++, Count++) {
Buffer[Index++] = *UnicodeStr;
}
//
// Add padding if needed
//
for (; (Count < Width) && (Index < NumberOfCharacters - 1); Count++) {
Buffer[Index++] = ' ';
}
break;
case 'a':
AsciiStr = (CHAR8 *)VA_ARG (Marker, CHAR8 *);
if (AsciiStr == NULL) {
AsciiStr = "<null string>";
}
for (Count = 0 ;(*AsciiStr != '\0') && (Index < NumberOfCharacters - 1); AsciiStr++, Count++) {
Buffer[Index++] = (CHAR_W)*AsciiStr;
}
//
// Add padding if needed
//
for (;(Count < Width) && (Index < NumberOfCharacters - 1); Count++) {
Buffer[Index++] = ' ';
}
break;
case 'c':
Buffer[Index++] = (CHAR_W)VA_ARG (Marker, UINTN);
break;
case 'g':
TmpGUID = VA_ARG (Marker, EFI_GUID *);
if (TmpGUID != NULL) {
Index += GuidToString (
TmpGUID,
&Buffer[Index],
BufferLeft
);
}
break;
case 't':
Index += TimeToString (
VA_ARG (Marker, EFI_TIME *),
&Buffer[Index],
BufferLeft
);
break;
case 'r':
Index += EfiStatusToString (
VA_ARG (Marker, EFI_STATUS),
&Buffer[Index],
BufferLeft
);
break;
case '%':
Buffer[Index++] = *Format;
break;
default:
//
// if the type is unknown print it to the screen
//
Buffer[Index++] = *Format;
}
BufferLeft = BufferSize - Index * sizeof(CHAR_W) ;
}
}
Buffer[Index++] = '\0';
return &Buffer[Index] - StartOfBuffer;
}
STATIC
CHAR_W *
GetFlagsAndWidth (
IN CHAR_W *Format,
OUT UINTN *Flags,
OUT UINTN *Width,
IN OUT VA_LIST *Marker
)
/*++
Routine Description:
VSPrint worker function that parses flag and width information from the
Format string and returns the next index into the Format string that needs
to be parsed. See file headed for details of Flag and Width.
Arguments:
Format - Current location in the VSPrint format string.
Flags - Returns flags
Width - Returns width of element
Marker - Vararg list that may be paritally consumed and returned.
Returns:
Pointer indexed into the Format string for all the information parsed
by this routine.
--*/
{
UINTN Count;
BOOLEAN Done;
*Flags = 0;
*Width = 0;
for (Done = FALSE; !Done; ) {
Format++;
switch (*Format) {
case '-': *Flags |= LEFT_JUSTIFY; break;
case '+': *Flags |= PREFIX_SIGN; break;
case ' ': *Flags |= PREFIX_BLANK; break;
case ',': *Flags |= COMMA_TYPE; break;
case 'L':
case 'l': *Flags |= LONG_TYPE; break;
case '*':
*Width = VA_ARG (*Marker, UINTN);
break;
case '0':
*Flags |= PREFIX_ZERO;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
Count = 0;
do {
Count = (Count * 10) + *Format - '0';
Format++;
} while ((*Format >= '0') && (*Format <= '9'));
Format--;
*Width = Count;
break;
default:
Done = TRUE;
}
}
return Format;
}
STATIC
UINTN
GuidToString (
IN EFI_GUID *Guid,
IN CHAR_W *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
VSPrint worker function that prints an EFI_GUID.
Arguments:
Guid - Pointer to GUID to print.
Buffer - Buffe to print Guid into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
Size = SPrint (
Buffer,
BufferSize,
STRING_W ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
(UINTN)Guid->Data1,
(UINTN)Guid->Data2,
(UINTN)Guid->Data3,
(UINTN)Guid->Data4[0],
(UINTN)Guid->Data4[1],
(UINTN)Guid->Data4[2],
(UINTN)Guid->Data4[3],
(UINTN)Guid->Data4[4],
(UINTN)Guid->Data4[5],
(UINTN)Guid->Data4[6],
(UINTN)Guid->Data4[7]
);
//
// SPrint will null terminate the string. The -1 skips the null
//
return Size - 1;
}
STATIC
UINTN
TimeToString (
IN EFI_TIME *Time,
OUT CHAR_W *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
VSPrint worker function that prints EFI_TIME.
Arguments:
Time - Pointer to EFI_TIME sturcture to print.
Buffer - Buffer to print Time into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
Size = SPrint (
Buffer,
BufferSize,
STRING_W ("%02d/%02d/%04d %02d:%02d"),
(UINTN)Time->Month,
(UINTN)Time->Day,
(UINTN)Time->Year,
(UINTN)Time->Hour,
(UINTN)Time->Minute
);
//
// SPrint will null terminate the string. The -1 skips the null
//
return Size - 1;
}
STATIC
UINTN
EfiStatusToString (
IN EFI_STATUS Status,
OUT CHAR_W *Buffer,
IN UINTN BufferSize
)
/*++
Routine Description:
VSPrint worker function that prints EFI_STATUS as a string. If string is
not known a hex value will be printed.
Arguments:
Status - EFI_STATUS sturcture to print.
Buffer - Buffer to print EFI_STATUS message string into.
BufferSize - Size of Buffer.
Returns:
Number of characters printed.
--*/
{
UINTN Size;
CHAR8 *Desc;
Desc = NULL;
//
// Can't use global Status String Array as UINTN is not constant for EBC
//
if (Status == EFI_SUCCESS) { Desc = "Success"; } else
if (Status == EFI_LOAD_ERROR) { Desc = "Load Error"; } else
if (Status == EFI_INVALID_PARAMETER) { Desc = "Invalid Parameter"; } else
if (Status == EFI_UNSUPPORTED) { Desc = "Unsupported"; } else
if (Status == EFI_BAD_BUFFER_SIZE) { Desc = "Bad Buffer Size"; } else
if (Status == EFI_BUFFER_TOO_SMALL) { Desc = "Buffer Too Small"; } else
if (Status == EFI_NOT_READY) { Desc = "Not Ready"; } else
if (Status == EFI_DEVICE_ERROR) { Desc = "Device Error"; } else
if (Status == EFI_WRITE_PROTECTED) { Desc = "Write Protected"; } else
if (Status == EFI_OUT_OF_RESOURCES) { Desc = "Out of Resources"; } else
if (Status == EFI_VOLUME_CORRUPTED) { Desc = "Volume Corrupt"; } else
if (Status == EFI_VOLUME_FULL) { Desc = "Volume Full"; } else
if (Status == EFI_NO_MEDIA) { Desc = "No Media"; } else
if (Status == EFI_MEDIA_CHANGED) { Desc = "Media changed"; } else
if (Status == EFI_NOT_FOUND) { Desc = "Not Found"; } else
if (Status == EFI_ACCESS_DENIED) { Desc = "Access Denied"; } else
if (Status == EFI_NO_RESPONSE) { Desc = "No Response"; } else
if (Status == EFI_NO_MAPPING) { Desc = "No mapping"; } else
if (Status == EFI_TIMEOUT) { Desc = "Time out"; } else
if (Status == EFI_NOT_STARTED) { Desc = "Not started"; } else
if (Status == EFI_ALREADY_STARTED) { Desc = "Already started"; } else
if (Status == EFI_ABORTED) { Desc = "Aborted"; } else
if (Status == EFI_ICMP_ERROR) { Desc = "ICMP Error"; } else
if (Status == EFI_TFTP_ERROR) { Desc = "TFTP Error"; } else
if (Status == EFI_PROTOCOL_ERROR) { Desc = "Protocol Error"; } else
if (Status == EFI_WARN_UNKNOWN_GLYPH) { Desc = "Warning Unknown Glyph"; } else
if (Status == EFI_WARN_DELETE_FAILURE) { Desc = "Warning Delete Failure"; } else
if (Status == EFI_WARN_WRITE_FAILURE) { Desc = "Warning Write Failure"; } else
if (Status == EFI_WARN_BUFFER_TOO_SMALL) { Desc = "Warning Buffer Too Small"; }
//
// If we found a match, copy the message to the user's buffer. Otherwise
// sprint the hex status code to their buffer.
//
if (Desc != NULL) {
Size = SPrint (Buffer, BufferSize, STRING_W ("%a"), Desc);
} else {
Size = SPrint (Buffer, BufferSize, STRING_W ("%X"), Status);
}
return Size - 1;
}

View File

@@ -0,0 +1,37 @@
/*++
Copyright (c) 2004, 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:
Print.h
Abstract:
Private data for Print.c
--*/
#ifndef _PRINT_H_
#define _PRINT_H_
#define LEFT_JUSTIFY 0x01
#define PREFIX_SIGN 0x02
#define PREFIX_BLANK 0x04
#define COMMA_TYPE 0x08
#define LONG_TYPE 0x10
#define PREFIX_ZERO 0x20
//
// Largest number of characters that can be printed out.
//
#define EFI_DRIVER_LIB_MAX_PRINT_BUFFER (80 * 4)
#endif

View File

@@ -0,0 +1,49 @@
#/*++
#
# Copyright (c) 2004, 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:
#
# PrintLib.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = PrintLib
COMPONENT_TYPE = LIBRARY
[sources.common]
BoxDraw.c
Print.c
Print.h
StdErr.c
Unicode\PrintWidth.h
Unicode\SPrint.c
[includes.common]
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation\Efi
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Library\Dxe\Print\Unicode
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
[nmake.common]

View File

@@ -0,0 +1,284 @@
/*++
Copyright (c) 2004, 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:
StdErr.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "EfiCommonLib.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
ErrorPrint (
IN CONST CHAR16 *ErrorString,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
ErrorString - String of error infomation.
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
UINTN Index;
UINTN MaxIndex;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
//
// Format string was too long for use to process.
//
return 0;
}
if (ErrorString != '\0') {
if (gST->StdErr != NULL) {
//
// To be extra safe make sure StdErr has been initialized
//
gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_RED, EFI_BLACK));
gST->StdErr->OutputString (gST->StdErr, (CHAR16 *) ErrorString);
gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK));
}
}
for (Index = 0; Index < MaxIndex; Index++) {
UnicodeFormat[Index] = (CHAR16) Format[Index];
}
UnicodeFormat[Index] = 0;
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
VA_END (Marker);
//
// Need to convert to Unicode to do an OutputString
//
if (gST->StdErr != NULL) {
//
// To be extra safe make sure StdErr has been initialized
//
gST->StdErr->OutputString (gST->StdErr, Buffer);
}
return Return;
}
UINTN
Aprint (
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
UINTN Index;
UINTN MaxIndex;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
//
// Format string was too long for use to process.
//
return 0;
}
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER; Index++) {
UnicodeFormat[Index] = (CHAR16) Format[Index];
}
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
VA_END (Marker);
//
// Need to convert to Unicode to do an OutputString
//
if (gST->ConOut != NULL) {
//
// To be extra safe make sure ConOut has been initialized
//
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
return Return;
}
UINTN
Print (
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker);
VA_END (Marker);
if (gST->ConOut != NULL) {
//
// To be extra safe make sure ConOut has been initialized
//
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
return Return;
}
UINTN
UPrint (
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker);
VA_END (Marker);
if (gST->ConOut != NULL) {
//
// To be extra safe make sure ConOut has been initialized
//
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
return Return;
}

View File

@@ -0,0 +1,35 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Unicode
STRING_W is L""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR16 CHAR_W;
#define STRING_W(_s) L##_s
#define USPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define UvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
#include "EfiCommonLib.h"
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
ASPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = AvSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
AvSPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of ASPrint.
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
}
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,88 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Ascii
STRING_W is ""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR8 CHAR_W;
#define STRING_W(_s) _s
#define ASPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define AvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
UINTN
UvSPrint (
OUT CHAR16 *StartOfBuffer,
IN UINTN StrLen,
IN CONST CHAR16 *Format,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
StartOfBuffer - Wide char buffer to print the results of the parsing of Format into.
StrLen - Maximum number of characters to put into buffer.
Format - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
;
#endif

View File

@@ -0,0 +1,142 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
USPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
UvSPrint (
OUT CHAR16 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR16 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of USPrint.
Process format and place the results in Buffer for wide chars.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
AsciiFormat[Index] = (CHAR8) FormatString[Index];
}
AsciiFormat[Index] = '\0';
Index = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR16) AsciiResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}

View File

@@ -0,0 +1,212 @@
/*++
Copyright (c) 2004, 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:
BoxDraw.c
Abstract:
Lib functions to support Box Draw Unicode code pages.
Revision History
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
typedef struct {
CHAR16 Unicode;
CHAR8 PcAnsi;
CHAR8 Ascii;
} UNICODE_TO_CHAR;
//
// This list is used to define the valid extend chars.
// It also provides a mapping from Unicode to PCANSI or
// ASCII. The ASCII mapping we just made up.
//
//
static UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
BOXDRAW_HORIZONTAL, 0xc4, L'-',
BOXDRAW_VERTICAL, 0xb3, L'|',
BOXDRAW_DOWN_RIGHT, 0xda, L'/',
BOXDRAW_DOWN_LEFT, 0xbf, L'\\',
BOXDRAW_UP_RIGHT, 0xc0, L'\\',
BOXDRAW_UP_LEFT, 0xd9, L'/',
BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|',
BOXDRAW_VERTICAL_LEFT, 0xb4, L'|',
BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+',
BOXDRAW_UP_HORIZONTAL, 0xc1, L'+',
BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+',
BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-',
BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|',
BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/',
BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/',
BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/',
BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\',
BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\',
BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\',
BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\',
BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\',
BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\',
BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/',
BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/',
BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/',
BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|',
BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|',
BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|',
BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|',
BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|',
BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|',
BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+',
BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+',
BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+',
BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+',
BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+',
BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+',
BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+',
BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+',
BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+',
BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*',
BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+',
GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^',
GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>',
GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v',
GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<',
ARROW_LEFT, 0x3c, L'<',
ARROW_UP, 0x18, L'^',
ARROW_RIGHT, 0x3e, L'>',
ARROW_DOWN, 0x19, L'v',
0x0000, 0x00
};
BOOLEAN
LibIsValidTextGraphics (
IN CHAR16 Graphic,
OUT CHAR8 *PcAnsi, OPTIONAL
OUT CHAR8 *Ascii OPTIONAL
)
/*++
Routine Description:
Detects if a Unicode char is for Box Drawing text graphics.
Arguments:
Graphic - Unicode char to test.
PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
Asci - Optional pointer to return Ascii equivalent of Graphic.
Returns:
TRUE if Gpaphic is a supported Unicode Box Drawing character.
--*/
{
UNICODE_TO_CHAR *Table;
if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {
//
// Unicode drawing code charts are all in the 0x25xx range,
// arrows are 0x21xx
//
return FALSE;
}
for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {
if (Graphic == Table->Unicode) {
if (PcAnsi != NULL) {
*PcAnsi = Table->PcAnsi;
}
if (Ascii != NULL) {
*Ascii = Table->Ascii;
}
return TRUE;
}
}
return FALSE;
}
BOOLEAN
IsValidAscii (
IN CHAR16 Ascii
)
/*++
Routine Description:
Is it valid ascii char?
Arguments:
Ascii - The char to check
Returns:
TRUE - Is a ascii char
FALSE - Not a ascii char
--*/
{
if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {
return TRUE;
}
return FALSE;
}
BOOLEAN
IsValidEfiCntlChar (
IN CHAR16 CharC
)
/*++
Routine Description:
Is it valid EFI control char?
Arguments:
CharC - The char to check
Returns:
TRUE - Is a valid EFI control char
FALSE - Not a valid EFI control char
--*/
{
if (CharC == CHAR_NULL || CharC == CHAR_BACKSPACE || CharC == CHAR_LINEFEED || CharC == CHAR_CARRIAGE_RETURN) {
return TRUE;
}
return FALSE;
}

View File

@@ -0,0 +1,153 @@
/*++
Copyright (c) 2004, 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:
Print.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "TianoCommon.h"
#include "EfiCommonLib.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
SPrint (
OUT CHAR_W *Buffer,
IN UINTN BufferSize,
IN CONST CHAR_W *Format,
...
)
/*++
Routine Description:
SPrint function to process format and place the results in Buffer.
Arguments:
Buffer - Wide char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means no
limit.
Format - Format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = VSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
VSPrint (
OUT CHAR_W *StartOfBuffer,
IN UINTN BufferSize,
IN CONST CHAR_W *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
VSPrint function to process format and place the results in Buffer. Since a
VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
this is the main print working routine
Arguments:
StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer. Zero means
no limit.
FormatString - Unicode format string see file header for more details.
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
EFI_STATUS Status;
EFI_PRINT_PROTOCOL *PrintProtocol;
Status = gBS->LocateProtocol (
&gEfiPrintProtocolGuid,
NULL,
(VOID*)&PrintProtocol
);
if (EFI_ERROR (Status)) {
return 0;
} else {
return PrintProtocol->VSPrint (
StartOfBuffer,
BufferSize,
FormatString,
Marker
);
}
}

View File

@@ -0,0 +1,37 @@
/*++
Copyright (c) 2004, 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:
Print.h
Abstract:
Private data for Print.c
--*/
#ifndef _PRINT_H_
#define _PRINT_H_
#define LEFT_JUSTIFY 0x01
#define PREFIX_SIGN 0x02
#define PREFIX_BLANK 0x04
#define COMMA_TYPE 0x08
#define LONG_TYPE 0x10
#define PREFIX_ZERO 0x20
//
// Largest number of characters that can be printed out.
//
#define EFI_DRIVER_LIB_MAX_PRINT_BUFFER (80 * 4)
#endif

View File

@@ -0,0 +1,50 @@
#/*++
#
# Copyright (c) 2004, 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:
#
# PrintLib.inf
#
# Abstract:
#
# Component description file.
#
#--*/
[defines]
BASE_NAME = PrintLibLite
COMPONENT_TYPE = LIBRARY
[sources.common]
BoxDraw.c
Print.c
Print.h
StdErr.c
Unicode\PrintWidth.h
Unicode\SPrint.c
[includes.common]
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Framework
$(EDK_SOURCE)\Foundation\Efi
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Foundation\Library\Dxe\Print\Unicode
$(EDK_SOURCE)\Foundation\Core\Dxe
[libraries.common]
EdkProtocolLib
[nmake.common]

View File

@@ -0,0 +1,284 @@
/*++
Copyright (c) 2004, 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:
StdErr.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "EfiCommonLib.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
ErrorPrint (
IN CONST CHAR16 *ErrorString,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
ErrorString - String of error infomation.
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
UINTN Index;
UINTN MaxIndex;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
//
// Format string was too long for use to process.
//
return 0;
}
if (ErrorString != '\0') {
if (gST->StdErr != NULL) {
//
// To be extra safe make sure StdErr has been initialized
//
gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_RED, EFI_BLACK));
gST->StdErr->OutputString (gST->StdErr, (CHAR16 *) ErrorString);
gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK));
}
}
for (Index = 0; Index < MaxIndex; Index++) {
UnicodeFormat[Index] = (CHAR16) Format[Index];
}
UnicodeFormat[Index] = 0;
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
VA_END (Marker);
//
// Need to convert to Unicode to do an OutputString
//
if (gST->StdErr != NULL) {
//
// To be extra safe make sure StdErr has been initialized
//
gST->StdErr->OutputString (gST->StdErr, Buffer);
}
return Return;
}
UINTN
Aprint (
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
UINTN Index;
UINTN MaxIndex;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
//
// Format string was too long for use to process.
//
return 0;
}
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER; Index++) {
UnicodeFormat[Index] = (CHAR16) Format[Index];
}
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
VA_END (Marker);
//
// Need to convert to Unicode to do an OutputString
//
if (gST->ConOut != NULL) {
//
// To be extra safe make sure ConOut has been initialized
//
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
return Return;
}
UINTN
Print (
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker);
VA_END (Marker);
if (gST->ConOut != NULL) {
//
// To be extra safe make sure ConOut has been initialized
//
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
return Return;
}
UINTN
UPrint (
IN CONST CHAR16 *Format,
...
)
/*++
Routine Description:
Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
characters.
Arguments:
Format - Ascii format string see file header for more details.
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
VA_START (Marker, Format);
Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker);
VA_END (Marker);
if (gST->ConOut != NULL) {
//
// To be extra safe make sure ConOut has been initialized
//
gST->ConOut->OutputString (gST->ConOut, Buffer);
}
return Return;
}

View File

@@ -0,0 +1,35 @@
/*++
Copyright (c) 2004, 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:
PrintWidth.h
Abstract:
Unicde option for generic width.
CHAR_W is Unicode
STRING_W is L""
--*/
#ifndef _PRINT_WIDTH_H_
#define _PRINT_WIDTH_H_
typedef CHAR16 CHAR_W;
#define STRING_W(_s) L##_s
#define USPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format)
#define UvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker)
#include "EfiCommonLib.h"
#endif

View File

@@ -0,0 +1,144 @@
/*++
Copyright (c) 2004, 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:
Sprint.c
Abstract:
Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
simple implemenation of SPrint() and Print() to support debug.
You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
time. This makes the implementation very simple.
VSPrint, Print, SPrint format specification has the follwoing form
%[flags][width]type
flags:
'-' - Left justify
'+' - Prefix a sign
' ' - Prefix a blank
',' - Place commas in numberss
'0' - Prefix for width with zeros
'l' - UINT64
'L' - UINT64
width:
'*' - Get width from a UINTN argumnet from the argument list
Decimal number that represents width of print
type:
'X' - argument is a UINTN hex number, prefix '0'
'x' - argument is a hex number
'd' - argument is a decimal number
'a' - argument is an ascii string
'S','s' - argument is an Unicode string
'g' - argument is a pointer to an EFI_GUID
't' - argument is a pointer to an EFI_TIME structure
'c' - argument is an ascii character
'r' - argument is EFI_STATUS
'%' - Print a %
--*/
#include "TianoCommon.h"
#include "PrintWidth.h"
#include "EfiPrintLib.h"
#include "Print.h"
UINTN
ASPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *Format,
...
)
/*++
Routine Description:
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
Format - Format string
... - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Return;
VA_LIST Marker;
VA_START (Marker, Format);
Return = AvSPrint (Buffer, BufferSize, Format, Marker);
VA_END (Marker);
return Return;
}
UINTN
AvSPrint (
OUT CHAR8 *Buffer,
IN UINTN BufferSize,
IN CONST CHAR8 *FormatString,
IN VA_LIST Marker
)
/*++
Routine Description:
Internal implementation of ASPrint.
Process format and place the results in Buffer for narrow chars.
Arguments:
Buffer - Narrow char buffer to print the results of the parsing of Format into.
BufferSize - Maximum number of characters to put into buffer.
FormatString - Format string
Marker - Vararg list consumed by processing Format.
Returns:
Number of characters printed.
--*/
{
UINTN Index;
CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {
UnicodeFormat[Index] = (CHAR16) FormatString[Index];
}
UnicodeFormat[Index] = '\0';
Index = VSPrint (UnicodeResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, UnicodeFormat, Marker);
for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) {
Buffer[Index] = (CHAR8) UnicodeResult[Index];
}
Buffer[Index] = '\0';
return Index++;
}