LegacyPlatform.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Legacy BIOS Platform support
Copyright (c) 2006 - 2011, 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 "LegacyPlatform.h"
{ 1, 2, 1, 1 }, // ATA HardDrive
{ 2, 3, 1, 1 }, // ATAPI CDROM
{ 3, 0x80, 2, 0 }, // PXE
{ 4, 1, 0, 6 }, // USB Floppy
{ 4, 2, 0, 6 }, // USB HDD
{ 4, 3, 0, 6 }, // USB CD
};
//
// Global variables for System ROMs
//
#define SYSTEM_ROM_FILE_GUID \
{ 0x1547B4F3, 0x3E8A, 0x4FEF, 0x81, 0xC8, 0x32, 0x8E, 0xD6, 0x47, 0xAB, 0x1A }
#define NULL_ROM_FILE_GUID \
{ 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
{ SYSTEM_ROM_FILE_GUID, 1 },
{ NULL_ROM_FILE_GUID, 0 }
};
{0x0B,0},
{0x09,0},
{0x0A,0},
{0x05,0},
{0x07,0},
{0x00,0},
{0x00,0}
};
//
// PIRQ Table
// - Slot numbering will be used to update the bus number and determine bridge
// to check to get bus number. The Slot number - 1 is an index into a decode
// table to get the bridge information.
//
{
EFI_LEGACY_PIRQ_TABLE_SIGNATURE, // UINT32 Signature
0x00, // UINT8 MinorVersion
0x01, // UINT8 MajorVersion
0x0000, // UINT16 TableSize
0x00, // UINT8 Bus
0x08, // UINT8 DevFun
0x0000, // UINT16 PciOnlyIrq
0x8086, // UINT16 CompatibleVid
0x122e, // UINT16 CompatibleDid
0x00000000, // UINT32 Miniport
{ // UINT8 Reserved[11]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00
},
0x00, // UINT8 Checksum
},
{
// -- Pin 1 -- -- Pin 2 -- -- Pin 3 -- -- Pin 4 --
// Bus Dev Reg Map Reg Map Reg Map Reg Map
0x00,0x08,0x60,0xDEB8,0x61,0xDEB8,0x62,0xDEB8,0x63,0xDEB8,0x00,0x00,
0x00,0x10,0x61,0xDEB8,0x62,0xDEB8,0x63,0xDEB8,0x60,0xDEB8,0x01,0x00,
0x00,0x18,0x62,0xDEB8,0x63,0xDEB8,0x60,0xDEB8,0x61,0xDEB8,0x02,0x00,
0x00,0x20,0x63,0xDEB8,0x60,0xDEB8,0x61,0xDEB8,0x62,0xDEB8,0x03,0x00,
0x00,0x28,0x60,0xDEB8,0x61,0xDEB8,0x62,0xDEB8,0x63,0xDEB8,0x04,0x00,
0x00,0x30,0x61,0xDEB8,0x62,0xDEB8,0x63,0xDEB8,0x60,0xDEB8,0x05,0x00,
}
};
/**
Return the handles and assorted information for the specified PCI Class code
@param[in] PciClasses Array of PCI_CLASS_RECORD to find terminated with ClassCode 0xff
@param[in,out] DeviceTable Table to place handles etc in.
@param[in,out] DeviceIndex Number of devices found
@param[in] DeviceFlags FALSE if a valid legacy ROM is required, TRUE otherwise.
@retval EFI_SUCCESS One or more devices found
@retval EFI_NOT_FOUND No device found
**/
)
{
//
// Get legacy BIOS protocol as it is required to deal with Option ROMs.
//
NULL,
(VOID**)&LegacyBios
);
//
// Get all PCI handles and check them to generate a list of matching devices.
//
NULL,
);
);
0,
sizeof (PciConfigHeader) / sizeof (UINT32),
);
NULL,
NULL,
);
//
// Verify that results of OPROM check match request.
// The two valid requests are:
// DeviceFlags = 0 require a valid legacy ROM
// DeviceFlags = 1 require either no ROM or a valid legacy ROM
//
if (
) {
++ *DeviceIndex;
DeviceTable++;
}
}
}
}
//
// Free any allocated buffers
//
if (*DeviceIndex != StartIndex) {
return EFI_SUCCESS;
} else {
return EFI_NOT_FOUND;
}
}
/**
Load and initialize the Legacy BIOS SMM handler.
@param This The protocol instance pointer.
@param EfiToLegacy16BootTable A pointer to Legacy16 boot table.
@retval EFI_SUCCESS SMM code loaded.
@retval EFI_DEVICE_ERROR SMM code failed to load
**/
SmmInit (
)
{
return EFI_SUCCESS;
}
/**
Finds the device path that should be used as the primary display adapter.
@param VgaHandle - The handle of the video device
**/
)
{
//
// Initialize return to 'not found' state
//
//
// Initialize variable states. Ths is important for selecting the VGA device
// if multiple devices exist behind a single bridge.
//
HandleCount = 0;
HandleBuffer = NULL;
//
// The bus range to search for a VGA device in.
//
//
// Start to check all the pci io to find all possible VGA device
//
HandleCount = 0;
HandleBuffer = NULL;
NULL,
);
return;
}
//
// Detemine if this is in the correct bus range.
//
continue;
}
//
// Read device information.
//
0,
&Pci
);
continue;
}
//
// Make sure the device is a VGA device.
//
if (!IS_PCI_VGA (&Pci)) {
continue;
}
DEBUG ((EFI_D_INFO,
"PCI VGA: 0x%04x:0x%04x\n",
));
//
// devices are found in the target bus range.
//
if (CurrentAddress < SelectedAddress) {
}
}
}
}
/**
Returns a buffer of handles for the requested subfunction.
@param This The protocol instance pointer.
@param Mode Specifies what handle to return. See EFI_GET_PLATFORM_HANDLE_MODE enum.
@param Type Mode specific. See EFI_GET_PLATFORM_HANDLE_MODE enum.
@param HandleBuffer Mode specific. See EFI_GET_PLATFORM_HANDLE_MODE enum.
@param HandleCount Mode specific. See EFI_GET_PLATFORM_HANDLE_MODE enum.
@param AdditionalData Mode specific. See EFI_GET_PLATFORM_HANDLE_MODE enum.
@retval EFI_SUCCESS Handle is valid.
@retval EFI_UNSUPPORTED Mode is not supported on the platform.
@retval EFI_NOT_FOUND Handle is not known.
**/
)
{
LocalIndex = 0x00;
HddIndex = 0;
NULL,
(VOID**)&LegacyBios
);
//
// Process mode specific operations
//
switch (Mode) {
case EfiGetPlatformVgaHandle:
//
// Get the handle for the currently selected VGA device.
//
*HandleBuffer = &mVgaHandles[0];
return EFI_SUCCESS;
case EfiGetPlatformIdeHandle:
if (AdditionalData != NULL) {
}
//
// Locate all found block io devices
//
if (LocalIndex == 0) {
return EFI_NOT_FOUND;
}
//
// Make sure all IDE controllers are connected. This is necessary
// in NO_CONFIG_CHANGE boot path to ensure IDE controller is correctly
// initialized and all IDE drives are enumerated
//
if (!bConnected) {
}
}
//
// Locate onboard controllers.
//
}
}
}
//
// Set the IDE contorller as primary devices.
//
PriorityIndex = 0;
break;
}
}
//
// Copy over handles and update return values.
//
}
*HandleBuffer = &mDiskHandles[0];
//
// We have connected all IDE controllers once. No more needed
//
bConnected = TRUE;
//
// Log all onboard controllers.
//
);
0,
sizeof (PciConfigHeader) / sizeof (UINT32),
);
PciIo->GetLocation (
&Segment,
&Bus,
&Device,
);
//
// Be sure to only fill out correct information based on platform
// configureation.
//
//
// Primary controller data
//
} else {
}
HddIndex++;
//
// Secondary controller data
//
} else {
}
HddIndex++;
}
}
}
return EFI_SUCCESS;
//
// Locate all found block io devices
//
if (LocalIndex == 0) {
return EFI_NOT_FOUND;
}
//
// Find our ISA bridge.
//
TempDevice = LocalDevice[0];
}
}
//
// Perform copy and update return values.
//
}
*HandleBuffer = &mIsaHandles[0];
return EFI_SUCCESS;
case EfiGetPlatformUsbHandle:
default:
return EFI_UNSUPPORTED;
};
}
/**
Allows platform to perform any required action after a LegacyBios operation.
Invokes the specific sub function specified by Mode.
@param This The protocol instance pointer.
@param Mode Specifies what handle to return. See EFI_GET_PLATFORM_HOOK_MODE enum.
@param Type Mode specific. See EFI_GET_PLATFORM_HOOK_MODE enum.
@param DeviceHandle Mode specific. See EFI_GET_PLATFORM_HOOK_MODE enum.
@param ShadowAddress Mode specific. See EFI_GET_PLATFORM_HOOK_MODE enum.
@param Compatibility16Table Mode specific. See EFI_GET_PLATFORM_HOOK_MODE enum.
@param AdditionalData Mode specific. See EFI_GET_PLATFORM_HOOK_MODE enum.
@retval EFI_SUCCESS The operation performed successfully. Mode specific.
@retval EFI_UNSUPPORTED Mode is not supported on the platform.
**/
)
{
switch (Mode) {
NULL,
(VOID**)&LegacyBios
);
//
// Set the 80x25 Text VGA Mode
//
return Status;
return EFI_SUCCESS;
default:
return EFI_UNSUPPORTED;
};
}
/**
Returns information associated with PCI IRQ routing.
This function returns the following information associated with PCI IRQ routing:
* An IRQ routing table and number of entries in the table.
* The $PIR table and its size.
* A list of PCI IRQs and the priority order to assign them.
@param This The protocol instance pointer.
@param RoutingTable The pointer to PCI IRQ Routing table.
This location is the $PIR table minus the header.
@param RoutingTableEntries The number of entries in table.
@param LocalPirqTable $PIR table.
@param PirqTableSize $PIR table size.
@param LocalIrqPriorityTable A list of interrupts in priority order to assign.
@param IrqPriorityTableEntries The number of entries in the priority table.
@retval EFI_SUCCESS Data was successfully returned.
**/
)
{
Checksum = 0;
if (LocalPirqTable != NULL) {
PTableSize = sizeof (EFI_LEGACY_PIRQ_TABLE_HEADER) +
sizeof (EFI_LEGACY_IRQ_ROUTING_ENTRY) * MAX_IRQ_ROUTING_ENTRIES;
NULL,
(VOID**)&LegacyInterrupt
);
&Bus,
&Device,
);
//
// Update fields in $PIR table header
//
//
// Calculate checksum.
//
Ptr += 1;
}
//
// Update return values.
//
}
//
// More items to return.
//
if (LocalIrqPriorityTable != NULL) {
}
return EFI_SUCCESS;
}
/**
Finds the binary data or other platform information.
@param This The protocol instance pointer.
@param Mode Specifies what data to return. See See EFI_GET_PLATFORM_INFO_MODE enum.
@param Table Mode specific. See EFI_GET_PLATFORM_INFO_MODE enum.
@param TableSize Mode specific. See EFI_GET_PLATFORM_INFO_MODE enum.
@param Location Mode specific. See EFI_GET_PLATFORM_INFO_MODE enum.
@param Alignment Mode specific. See EFI_GET_PLATFORM_INFO_MODE enum.
@param LegacySegment Mode specific. See EFI_GET_PLATFORM_INFO_MODE enum.
@param LegacyOffset Mode specific. See EFI_GET_PLATFORM_INFO_MODE enum.
@retval EFI_SUCCESS Data returned successfully.
@retval EFI_UNSUPPORTED Mode is not supported on the platform.
@retval EFI_NOT_FOUND Binary image or table not found.
**/
)
{
switch (Mode) {
//
// Loop through table of System rom descriptions
//
0,
);
continue;
}
return EFI_SUCCESS;
}
return EFI_NOT_FOUND;
default:
return EFI_UNSUPPORTED;
};
}
/**
Translates the given PIRQ accounting for bridge.
This function translates the given PIRQ back through all buses, if required,
and returns the true PIRQ and associated IRQ.
@param This The protocol instance pointer.
@param PciBus The PCI bus number for this device.
@param PciDevice The PCI device number for this device.
@param PciFunction The PCI function number for this device.
@param Pirq Input is PIRQ reported by device, and output is true PIRQ.
@param PciIrq The IRQ already assigned to the PIRQ, or the IRQ to be
assigned to the PIRQ.
@retval EFI_SUCCESS The PIRQ was translated.
**/
)
{
NULL,
(VOID**)&LegacyInterrupt
);
if (LocalPirq > 4) {
LocalPirq -= 4;
}
while (PirqData == 0) {
);
break;
}
}
if (PirqData == 0) {
//
// No unused interrpts, so start reusing them.
//
}
}
}
}
return EFI_SUCCESS;
}
/**
Attempt to legacy boot the BootOption. If the EFI contexted has been
compromised this function will not return.
@param This The protocol instance pointer.
@param BbsDevicePath The EFI Device Path from BootXXXX variable.
@param BbsTable The Internal BBS table.
@param LoadOptionSize The size of LoadOption in size.
@param LoadOption The LoadOption from BootXXXX variable
@param EfiToLegacy16BootTable A pointer to BootTable structure
@retval EFI_SUCCESS Ready to boot.
**/
)
{
//
// Initialize values
//
Priority = 0;
//
// Set how Gate A20 is gated by hardware
//
//
// There are 2 cases that must be covered.
// Case 1: Booting to a legacy OS - BbsDevicePath is non-NULL.
// Case 2: Booting to an EFI aware OS - BbsDevicePath is NULL.
// We need to perform the PrepareToBoot function to assign
// drive numbers to HDD devices to allow the shell or EFI
// to access them.
//
if (BbsDevicePath != NULL) {
} else {
}
//
// Skip the boot devices where priority is set by BDS and set the next one
//
}
}
switch (DevicePathType) {
case BBS_FLOPPY:
case BBS_HARDDISK:
case BBS_CDROM:
case BBS_EMBED_NETWORK:
++Priority;
}
}
break;
case BBS_BEV_DEVICE:
++Priority;
}
}
break;
case BBS_USB:
case BBS_PCMCIA:
case BBS_UNKNOWN:
default:
break;
};
//
// Set priority for rest of devices
//
++Priority;
}
}
return EFI_SUCCESS;
}
/**
Initialize Legacy Platform support
@retval EFI_SUCCESS Successfully initialized
**/
)
{
Private = &mPrivateData;
//
// Grab a copy of all the protocols we depend on.
//
//
// Make a new handle and install the protocol
//
);
return Status;
}