/** @file
Platform BDS customizations.
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "BdsPlatform.h"
#ifdef VBOX
#include "VBoxPkg.h"
#include "DevEFI.h"
#include "Library/PrintLib.h"
/* Hmmm Uga Draw wasn't pointed in BDS, so perhaps it's totally dead */
#endif
//
// Global data
//
#ifdef VBOX
/*
* @todo move this function to the library.
*/
static UINT32
{
{
}
return VarLen;
}
static VOID
)
{
if (Gop)
{
}
else if (Uga)
{
UINT32 H = 1027;
UINT32 V = 768;
}
if(EFI_ERROR(r))
goto done;
if(EFI_ERROR(r))
goto done;
done:
return;
}
{
gBS->CreateEventEx(EVT_NOTIFY_SIGNAL, TPL_NOTIFY, VBoxConsoleSwitchMode, NULL, &gEfiEventReadyToBootGuid, &event);
return EFI_SUCCESS;
}
#endif /* VBOX */
//
// Type definitions
//
typedef
);
/**
@param[in] Handle - Handle of PCI device instance
@param[in] PciIo - PCI IO protocol instance
@param[in] Pci - PCI Header register block
**/
typedef
);
//
// Function prototypes
//
);
);
);
#ifndef VBOX
);
);
#endif
//
// BDS Platform Functions
//
)
/*++
Routine Description:
Platform Bds init. Incude the platform firmware vendor, revision
and so crc check.
Arguments:
Returns:
None.
--*/
{
#ifndef VBOX
LoadVideoRom ();
#endif
}
)
/*++
Routine Description:
Connect RootBridge
Arguments:
None.
Returns:
EFI_SUCCESS - Connect RootBridge successfully.
EFI_STATUS - Connect RootBridge fail.
--*/
{
//
// Make all the PCI_IO protocols on PCI Seg 0 show up
//
&gPlatformRootBridges[0],
);
return Status;
}
return Status;
}
return EFI_SUCCESS;
}
)
/*++
Routine Description:
Add IsaKeyboard to ConIn,
add IsaSerial to ConOut, ConIn, ErrOut.
LPC Bridge: 06 01 00
Arguments:
DeviceHandle - Handle of PCIIO protocol.
Returns:
EFI_SUCCESS - LPC bridge is added to ConOut, ConIn, and ErrOut.
EFI_STATUS - No LPC bridge is added.
--*/
{
DevicePath = NULL;
(VOID*)&DevicePath
);
return Status;
}
//
// Register Keyboard
//
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnpPs2KeyboardDeviceNode);
//
// Register COM1
//
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);
//
// Print Device Path
//
DEBUG((
"BdsPlatform.c+%d: COM%d DevPath: %s\n",
));
//
// Register COM2
//
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);
//
// Print Device Path
//
DEBUG((
"BdsPlatform.c+%d: COM%d DevPath: %s\n",
));
return EFI_SUCCESS;
}
)
{
return EFI_INVALID_PARAMETER;
}
//
// Initialize the GopDevicePath to be PciDevicePath
//
);
return Status;
}
//
// Try to connect this handle, so that GOP dirver could start on this
// device and create child handles with GraphicsOutput Protocol installed
// on them, then we get device paths of these child handles and select
// them as possible console device.
//
NULL,
);
//
// Add all the child handles as possible Console Device
//
Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID*)&TempDevicePath);
continue;
}
if (CompareMem (
) == 0) {
//
// In current implementation, we only enable one of the child handles
// as console device, i.e. sotre one of the child handle's device
// path to variable "ConOut"
// In futhure, we could select all child handles to be console device
//
//
// Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()
// Add the integrity GOP device path.
//
}
}
}
return EFI_SUCCESS;
}
)
/*++
Routine Description:
Add PCI VGA to ConOut.
PCI VGA: 03 00 00
Arguments:
DeviceHandle - Handle of PCIIO protocol.
Returns:
EFI_SUCCESS - PCI VGA is added to ConOut.
EFI_STATUS - No PCI VGA device is added.
--*/
{
DevicePath = NULL;
(VOID*)&DevicePath
);
return Status;
}
return EFI_SUCCESS;
}
)
/*++
Routine Description:
Add PCI Serial to ConOut, ConIn, ErrOut.
PCI Serial: 07 00 02
Arguments:
DeviceHandle - Handle of PCIIO protocol.
Returns:
EFI_SUCCESS - PCI Serial is added to ConOut, ConIn, and ErrOut.
EFI_STATUS - No PCI Serial device is added.
--*/
{
DevicePath = NULL;
(VOID*)&DevicePath
);
return Status;
}
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);
return EFI_SUCCESS;
}
)
{
//
// Start to check all the PciIo to find all possible device
//
HandleCount = 0;
HandleBuffer = NULL;
Id,
NULL,
);
return Status;
}
continue;
}
Status = (*CallBackFunction) (
);
}
return EFI_SUCCESS;
}
)
{
//
// Check for all PCI device
//
0,
&Pci
);
return Status;
}
&Pci
);
}
)
{
return VisitAllInstancesOfProtocol (
);
}
/**
Do platform specific PCI Device check and add them to
ConOut, ConIn, ErrOut.
@param[in] Handle - Handle of PCI device instance
@param[in] PciIo - PCI IO protocol instance
@param[in] Pci - PCI Header register block
@retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
@retval EFI_STATUS - PCI Device check or Console variable update fail.
**/
)
{
);
if (!mDetectVgaOnly) {
//
// Here we decide whether it is LPC Bridge
//
if ((IS_PCI_LPC (Pci)) ||
((IS_PCI_ISA_PDECODE (Pci)) &&
)
) {
//
// Add IsaKeyboard to ConIn,
// add IsaSerial to ConOut, ConIn, ErrOut
//
return EFI_SUCCESS;
}
//
// Here we decide which Serial device to enable in PCI bus
//
if (IS_PCI_16550SERIAL (Pci)) {
//
// Add them to ConOut, ConIn, ErrOut.
//
return EFI_SUCCESS;
}
}
//
// Here we decide which VGA device to enable in PCI bus
//
if (IS_PCI_VGA (Pci)) {
//
// Add them to ConOut.
//
return EFI_SUCCESS;
}
return Status;
}
/**
Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
@param[in] DetectVgaOnly - Only detect VGA device if it's TRUE.
@retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
@retval EFI_STATUS - PCI Device check or Console variable update fail.
**/
)
{
}
)
/*++
Routine Description:
Connect the predefined platform default console device. Always try to find
and enable the vga device if have.
Arguments:
PlatformConsole - Predfined platform default console device array.
Returns:
EFI_SUCCESS - Success connect at least one ConIn and ConOut
device, there must have one ConOut device is
active vga device.
EFI_STATUS - Return the status of
BdsLibConnectAllDefaultConsoles ()
--*/
{
//
// Connect RootBridge
//
);
);
//
// Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
//
//
// Have chance to connect the platform default console,
// the platform default console is the minimue device group
// the platform should support
//
//
// Update the console variable with the connect type
//
}
}
}
}
} else {
//
// Only detect VGA device and add them to ConOut
//
}
//
// Connect the all the default console with current cosole variable
//
return Status;
}
return EFI_SUCCESS;
}
)
{
//
// Bus 0, Device 0, Function 0 - Host to PCI Bridge
//
//
// Bus 0, Device 1, Function 0 - PCI to ISA Bridge
//
//
// Bus 0, Device 1, Function 1 - IDE Controller
//
//
// Bus 0, Device 1, Function 3 - Power Managment Controller
//
//
// Bus 0, Device 2, Function 0 - Video Controller
//
//
// Bus 0, Device 3, Function 0 - Network Controller
//
//
// Bus 0, Device 4, Function 0 - RAM Memory
//
}
)
{
DevicePath = NULL;
(VOID*)&DevicePath
);
return Status;
}
//
// Print Device Path
//
DEBUG((
"Found Mass Storage device: %s\n",
));
return Status;
}
}
return EFI_SUCCESS;
}
/**
This notification function is invoked when the
EMU Variable FVB has been changed.
@param Event The event that occured
@param Context For EFI compatiblity. Not used.
**/
)
{
}
)
{
if (ConnectedToFileSystem) {
return EFI_ALREADY_STARTED;
}
return Status;
}
NULL,
);
return EFI_SUCCESS;
}
{
HandleCount = 0;
HandleBuffer = NULL;
#ifndef VBOX
);
#endif
NULL,
);
}
)
/*++
Routine Description:
Connect with predeined platform connect sequence,
Arguments:
None.
Returns:
None.
--*/
{
Index = 0;
//
// Here we can get the customized platform connect sequence
// Notes: we can connect with new variable which record the
// last time boots connect device path sequence
//
//
// Build the platform boot option
//
Index++;
}
//
// Just use the simple policy to connect all devices
//
BdsLibConnectAll ();
//
// Clear the logo after all devices are connected.
//
}
)
/*++
Routine Description:
to load their own drivers
Arguments:
BdsDriverLists - The header of the driver option link list.
Returns:
None.
--*/
{
return;
}
)
/*++
Routine Description:
can customize this fuction to support specific platform diagnostic.
Arguments:
MemoryTestLevel - The memory test intensive level
QuietBoot - Indicate if need to enable the quiet boot
BaseMemoryTest - A pointer to BaseMemoryTest()
Returns:
None.
--*/
{
//
// Here we can decide if we need to show
// the diagnostics screen
// Notes: this quiet boot code should be remove
// from the graphic lib
//
if (QuietBoot) {
//
// Perform system diagnostic
//
DisableQuietBoot ();
}
return ;
}
//
// Perform system diagnostic
//
}
)
/*++
Routine Description:
The function will excute with as the platform policy, current policy
policy action.
Arguments:
DriverOptionList - The header of the driver option link list
BootOptionList - The header of the boot option link list
ProcessCapsules - A pointer to ProcessCapsules()
BaseMemoryTest - A pointer to BaseMemoryTest()
Returns:
None.
--*/
{
//
// Try to restore variables from the hard disk early so
// they can be used for the other BDS connect operations.
//
//
// Init the time out value
//
//
// Load the driver option as the driver option list
//
//
// Get current Boot Mode
//
//
// Go the different platform policy with different boot mode
// Notes: this part code can be change with the table policy
//
//
// Connect platform console
//
//
//
}
//
// Create a 300ms duration event to ensure user has enough input time to enter Setup
//
0,
NULL,
NULL,
);
//
// Memory test and Logo show
//
//
// Perform some platform specific connect sequence
//
//
// Give one chance to enter the setup if we
// have the time out
//
if (Timeout != 0) {
//PlatformBdsEnterFrontPage (Timeout, FALSE);
}
BdsLibConnectAll ();
#ifdef VBOX
{
DEBUG ((EFI_D_INFO, "------------------ VBox Platform Specific Initialization Start -----------------------\n"));
if (!BootOption0080)
{
NULL,
&phFileSystem);
if ( rc == EFI_SUCCESS
&& cFileSystem > 0)
{
/* Ok, we've found several simple file system handles
* 1. we should find if '\\System\\Library\\CoreServices\\boot.efi' present
* 2. Alter 'BootOrder' to include this file in boot sequence.
*/
{
/* mount and look up the boot.efi */
continue;
continue;
rc = hFSRoot->Open(hFSRoot, &hBootEfiFile, L"\\System\\Library\\CoreServices\\boot.efi", EFI_FILE_MODE_READ, 0);
continue;
/* nice file is found and we have to register it */
pDevicePath = FileDevicePath(phFileSystem[iFileSystem], L"\\System\\Library\\CoreServices\\boot.efi");
if (!pDevicePath)
continue;
}
}
}
else
{
#if 0
/* Boot0080 option is found */
L"BootOrder",
sizeof(BDS_COMMON_OPTION),
#if 0
rc = BdsLibRegisterNewOption (BootOptionList, BootOption0080->DevicePath, L"Mac Boot Temp", L"BootOrder");
#endif
#endif
}
DEBUG ((EFI_D_INFO, "------------------ VBox Platform Specific Initialization End -----------------------\n"));
}
#endif
//
// Please uncomment above ConnectAll and EnumerateAll code and remove following first boot
// checking code in real production tip.
//
// In BOOT_WITH_FULL_CONFIGURATION boot mode, should always connect every device
// and do enumerate all the default boot options. But in development system board, the boot mode
// cannot be BOOT_ASSUMING_NO_CONFIGURATION_CHANGES because the machine box
// is always open. So the following code only do the ConnectAll and EnumerateAll at first boot.
//
//
// If cannot find "BootOrder" variable, it may be first boot.
// Try to connect all devices and enumerate all boot options here.
//
BdsLibConnectAll ();
}
//
// To give the User a chance to enter Setup here, if user set TimeOut is 0.
// BDS should still give user a chance to enter Setup
//
// Connect first boot option, and then check user input before exit
//
//
// skip the header of the link list, becuase it has no boot option
//
continue;
} else {
//
// Make sure the boot option device path connected, but ignore the BBS device path
//
}
break;
}
}
#ifdef VBOX
#endif
//
// Check whether the user input after the duration time has expired
//
OldTpl = EfiGetCurrentTpl();
//
// Enter Setup if user input
//
Timeout = 0xffff;
}
return ;
}
)
/*++
Routine Description:
Hook point after a boot attempt succeeds. We don't expect a boot option to
return, so the EFI 1.0 specification defines that you will default to an
interactive mode and stop processing the BootOrder list in this case. This
Arguments:
Option - Pointer to Boot Option that succeeded to boot.
Returns:
None.
--*/
{
//
// If Boot returned with EFI_SUCCESS and there is not in the boot device
// select loop then we need to pop up a UI and wait for user input.
//
}
}
)
/*++
Routine Description:
Hook point after a boot attempt fails.
Arguments:
Option - Pointer to Boot Option that failed to boot.
Status - Status returned from failed boot.
ExitData - Exit data returned from failed boot.
ExitDataSize - Exit data size returned from failed boot.
Returns:
None.
--*/
{
//
// If Boot returned with failed status then we need to pop up a UI and wait
// for user input.
//
}
}
)
/*++
Routine Description:
if there no console device can be connected.
Arguments:
None.
Returns:
EFI_SUCCESS - Direct return success now.
--*/
{
return EFI_SUCCESS;
}
)
{
return;
}
/**
This notification function is invoked when an instance of the
EFI_DEVICE_PATH_PROTOCOL is produced.
@param Event The event that occured
@param Context For EFI compatiblity. Not used.
**/
)
{
//
// Examine all new handles
//
for (;;) {
//
// Get the next handle
//
BufferSize = sizeof (Handle);
NULL,
);
//
// If not found, we're done
//
if (EFI_NOT_FOUND == Status) {
break;
}
continue;
}
//
// Get the DevicePath protocol on that handle
//
while (!IsDevicePathEnd (DevPathNode)) {
//
// Find the handler to dump this device path node
//
if (
) {
PciOr16 (
0,
1,
1,
),
);
}
//
// Next device path node
//
}
}
return;
}
)
{
NULL,
);
}
/**
Lock the ConsoleIn device in system table. All key
presses will be ignored until the Password is typed in. The only way to
disable the password is to type it in to a ConIn device.
@param Password Password used to lock ConIn device.
@retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
@retval EFI_UNSUPPORTED Password not found
**/
)
{
return EFI_UNSUPPORTED;
}
#ifndef VBOX
)
{
//
// The virtual machines sometimes load the video rom image
// directly at the legacy video BIOS location of C000:0000,
// and do not implement the PCI expansion ROM feature.
//
}
)
{
FileName = L"PciRomInMemory";
//FileName = L"PciRom Addr=0000000000000000";
//HexToString (&FileName[12], Rom, 16);
ImageIndex = 0;
do {
return retStatus;
}
//
// If the pointer to the PCI Data Structure is invalid, no further images can be located.
// The PCI Data Structure must be DWORD aligned.
//
if (EfiRomHeader->PcirOffset == 0 ||
break;
}
//
// If a valid signature is not present in the PCI Data Structure, no further images can be located.
//
break;
}
break;
}
//
// decompress here if needed
//
}
} else {
);
if (DecompressedImageBuffer != NULL) {
);
}
}
}
}
}
}
if (!SkipImage) {
//
// load image and start image
//
);
}
}
}
}
if (DecompressedImageBuffer != NULL) {
}
}
}
ImageIndex++;
return retStatus;
}
#endif /* !VBOX */