/** @file
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 "LegacyBiosInterface.h"
//
// define maximum number of HDD system supports
//
//
// Module Global:
// Since this driver will only ever produce one instance of the Private Data
// protocol you are not required to dynamically allocate the PrivateData.
//
/**
Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode
memory.
@param AllocateType Allocated Legacy Memory Type
@param StartPageAddress Start address of range
@param Pages Number of pages to allocate
@param Result Result of allocation
@retval EFI_SUCCESS Legacy16 code loaded
@retval Other No protocol installed, unload driver.
**/
)
{
//
// Allocate Pages of memory less <= StartPageAddress
//
);
//
// Do not ASSERT on Status error but let caller decide since some cases
// memory is already taken but that is ok.
//
}
//
// If reach here the status = EFI_SUCCESS
//
return Status;
}
/**
This function is called when EFI needs to reserve an area in the 0xE0000 or 0xF0000
64 KB blocks.
Note: inconsistency with the Framework CSM spec. Per the spec, this function may be
invoked only once. This limitation is relaxed to allow multiple calls in this implemenation.
@param This Protocol instance pointer.
@param LegacyMemorySize Size of required region
@param Region Region to use. 00 = Either 0xE0000 or 0xF0000
block Bit0 = 1 0xF0000 block Bit1 = 1 0xE0000
block
@param Alignment Address alignment. Bit mapped. First non-zero
bit from right is alignment.
@param LegacyMemoryAddress Region Assigned
@retval EFI_SUCCESS Region assigned
@retval EFI_ACCESS_DENIED Procedure previously invoked
@retval Other Region not assigned
**/
)
{
&Regs,
NULL,
0
);
} else {
}
return Status;
}
/**
This function is called when copying data to the region assigned by
EFI_LEGACY_BIOS_PROTOCOL.GetLegacyRegion().
@param This Protocol instance pointer.
@param LegacyMemorySize Size of data to copy
@param LegacyMemoryAddress Legacy Region destination address Note: must
be in region assigned by
LegacyBiosGetLegacyRegion
@param LegacyMemorySourceAddress Source of data
@retval EFI_SUCCESS The data was copied successfully.
@retval EFI_ACCESS_DENIED Either the starting or ending address is out of bounds.
**/
)
{
) {
return EFI_ACCESS_DENIED;
}
//
// There is no protection from writes over lapping if this function is
// called multiple times.
//
return EFI_SUCCESS;
}
/**
Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
been shadowed.
@param Private Legacy BIOS context data
@retval EFI_SUCCESS Legacy16 code loaded
@retval Other No protocol installed, unload driver.
**/
)
{
Location = 0;
Alignment = 0;
//
// we allocate the C/D/E/F segment as RT code so no one will use it any more.
//
Address = 0xC0000;
//
// If it is already reserved, we should be safe, or else we allocate it.
//
0x40000/EFI_PAGE_SIZE,
);
//
// Bugbug: need to figure out whether C/D/E/F segment should be marked as reserved memory.
//
}
}
//
// start testtest
// GetTimerValue (&Ticker);
//
// gRT->SetVariable (L"StartLegacy",
// &gEfiGlobalVariableGuid,
// EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
// sizeof (UINT64),
// (VOID *)&Ticker
// );
// end testtest
//
&Location,
0,
0
);
return Status;
}
//
// Can only shadow into memory allocated for legacy useage.
//
//
// Shadow Legacy BIOS. Turn on memory and copy image
//
//
// Initialize region from 0xc0000 to start of BIOS to all ffs. This allows unused
// regions to be used by EMM386 etc.
//
CopyMem (
);
//
// Search for Legacy16 table in Shadowed ROM
//
}
}
}
return EFI_NOT_FOUND;
}
if (!Done) {
//
// Legacy16 table header checksum error.
//
}
//
// Remember location of the Legacy16 table
//
ZeroMem (
sizeof (EFI_TO_COMPATIBILITY16_BOOT_TABLE)
);
//
// Store away a copy of the EFI System Table
//
//
// IPF CSM integration -Bug
//
// Construct the Legacy16 boot memory map. This sets up number of
// E820 entries.
//
//
// Initialize BDA and EBDA standard values needed to load Legacy16 code
//
//
// All legacy interrupt should be masked when do initialization work from legacy 16 code.
//
NewMask = 0xFFFF;
//
// Call into Legacy16 code to do an INIT
//
&Regs,
NULL,
0
);
//
// Restore original legacy interrupt mask value
//
return EFI_DEVICE_ERROR;
}
//
// start testtest
// GetTimerValue (&Ticker);
//
// gRT->SetVariable (L"BackFromInitYourself",
// &gEfiGlobalVariableGuid,
// EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
// sizeof (UINT64),
// (VOID *)&Ticker
// );
// end testtest
//
// Copy E820 table after InitializeYourself is completed
//
&Regs,
NULL,
0
);
} else {
}
//
// Get PnPInstallationCheck Info.
//
//
// Check if PCI Express is supported. If yes, Save base address.
//
NULL,
NULL,
&Location,
0,
0
);
Location = 0;
}
//
// Check if TPM is supported. If yes get a region in E0000,F0000 to copy it
// into, copy it and update pointer to binary image. This needs to be
// done prior to any OPROM for security purposes.
//
&Location,
0,
0
);
&Regs,
NULL,
0
);
} else {
}
}
//
// Lock the Legacy BIOS region
//
Private->Cpu->FlushDataCache (Private->Cpu, Private->BiosStart, (UINT32) LegacyBiosImageSize, EfiCpuFlushTypeWriteBackInvalidate);
Private->LegacyRegion->Lock (Private->LegacyRegion, Private->BiosStart, (UINT32) LegacyBiosImageSize, &Granularity);
//
// Get the BbsTable from LOW_MEMORY_THUNK
//
//
// Skip Floppy and possible onboard IDE drives
//
}
//
// Allocate space for Legacy HDD table
//
LegacyEfiHddTable = (LEGACY_EFI_HDD_TABLE *) AllocateZeroPool ((UINTN) MAX_HDD_ENTRIES * sizeof (LEGACY_EFI_HDD_TABLE));
//
// start testtest
// GetTimerValue (&Ticker);
//
// gRT->SetVariable (L"EndOfLoadFv",
// &gEfiGlobalVariableGuid,
// EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
// sizeof (UINT64),
// (VOID *)&Ticker
// );
// end testtest
//
return EFI_SUCCESS;
}
/**
Shadow all legacy16 OPROMs that haven't been shadowed.
Warning: Use this with caution. This routine disconnects all EFI
drivers. If used externally then caller must re-connect EFI
drivers.
@param This Protocol instance pointer.
@retval EFI_SUCCESS OPROMs shadowed
**/
)
{
//
// EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *LegacyBiosPlatform;
// EFI_LEGACY16_TABLE *Legacy16Table;
//
//
// LegacyBiosPlatform = Private->LegacyBiosPlatform;
// Legacy16Table = Private->Legacy16Table;
//
// Shadow PCI ROMs. We must do this near the end since this will kick
// of Native EFI drivers that may be needed to collect info for Legacy16
//
// WARNING: PciIo is gone after this call.
//
//
// Shadow PXE base code, BIS etc.
//
// LegacyBiosPlatform->ShadowServiceRoms (LegacyBiosPlatform,
// &Private->OptionRom,
// Legacy16Table);
//
return EFI_SUCCESS;
}
/**
Get the PCI BIOS interface version.
@param Private Driver private data.
@return The PCI interface version number in Binary Coded Decimal (BCD) format.
E.g.: 0x0210 indicates 2.10, 0x0300 indicates 3.00
**/
)
{
PciInterfaceVersion = 0;
if (!ThunkFailed) {
//
// From PCI Firmware 3.0 Specification:
// If the CARRY FLAG [CF] is cleared and AH is set to 00h, it is still necessary to examine the
// contents of [EDX] for the presence of the string "PCI" + (trailing space) to fully validate the
// presence of the PCI function set. [BX] will further indicate the version level, with enough
// granularity to allow for incremental changes in the code that don't affect the function interface.
// Version numbers are stored as Binary Coded Decimal (BCD) values. For example, Version 2.10
// would be returned as a 02h in the [BH] registers and 10h in the [BL] registers.
//
}
}
return PciInterfaceVersion;
}
/**
Install Driver to produce Legacy BIOS protocol.
@param ImageHandle Handle of driver image.
@param SystemTable Pointer to system table.
@retval EFI_SUCCESS Legacy BIOS protocol installed
@retval No protocol installed, unload driver.
**/
)
{
//
// Load this driver's image to memory
//
return Status;
}
Private = &mPrivateData;
//
// Grab a copy of all the protocols we depend on. Any error would
// be a dispatcher bug!.
//
Status = gBS->LocateProtocol (&gEfiLegacyRegion2ProtocolGuid, NULL, (VOID **) &Private->LegacyRegion);
Status = gBS->LocateProtocol (&gEfiLegacyBiosPlatformProtocolGuid, NULL, (VOID **) &Private->LegacyBiosPlatform);
Status = gBS->LocateProtocol (&gEfiLegacyInterruptProtocolGuid, NULL, (VOID **) &Private->LegacyInterrupt);
//
// Locate Memory Test Protocol if exists
//
NULL,
);
//
// Make sure all memory from 0-640K is tested
//
continue;
}
);
}
//
// Make sure all memory from 1MB to 16MB is tested and added to memory map
//
continue;
}
);
}
//
// Enable read attribute of legacy region.
//
0xc0000,
0x40000,
);
//
// Set Cachebility for legacy region
// BUGBUG: Comments about this legacy region cacheability setting
// This setting will make D865GCHProduction CSM Unhappy
//
if (PcdGetBool (PcdLegacyBiosCacheLegacyRegion)) {
0x0,
0xA0000,
);
0xc0000,
0x40000,
);
}
0xA0000,
0x20000,
);
//
// Allocate 0 - 4K for real mode interupt vectors and BDA.
//
0,
1,
);
//
// Initialize region from 0x0000 to 4k. This initializes interrupt vector
// range.
//
//
// Allocate pages for OPROM usage
//
);
//
// Allocate all 32k chunks from 0x60000 ~ 0x88000 for Legacy OPROMs that
// don't use PMM but look for zeroed memory. Note that various non-BBS
// SCSIs expect different areas to be free
//
1,
);
} else {
}
}
//
// Allocate low PMM memory and zero it out
//
);
//
// Allocate space for thunker and Init Thunker
//
);
//
// Init the legacy memory map in memory < 1 MB.
//
//
// Allocate high PMM Memory under 16 MB
//
0x1000000,
);
}
//
// ShutdownAPs();
//
// Start the Legacy BIOS;
//
return Status;
}
//
// Initialize interrupt redirection code and entries;
// IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.
//
CopyMem (
);
//
// Save Unexpected interrupt vector so can restore it just prior to boot
//
BaseVectorMaster[Index] = (EFI_SEGMENT (IntRedirCode + Index * 4) << 16) | EFI_OFFSET (IntRedirCode + Index * 4);
}
//
// Save EFI value
//
//
// Make a new handle and install the protocol
//
);
));
return Status;
}