/** @file
Copyright (c) 2006 - 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.
**/
#ifndef _LEGACY_BIOS_INTERFACE_
#define _LEGACY_BIOS_INTERFACE_
#include <FrameworkDxe.h>
#include <Guid/DxeServices.h>
#include <Guid/LegacyBios.h>
#include <Guid/StatusCodeDataTypeId.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/LegacyRegion2.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/LegacyInterrupt.h>
#include <Protocol/LegacyBios.h>
#include <Protocol/DiskInfo.h>
#include <Protocol/GenericMemoryTest.h>
#include <Protocol/LegacyBiosPlatform.h>
#include <Protocol/DevicePath.h>
#include <Protocol/Legacy8259.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/PeCoffLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugAgentLib.h>
//
// BUGBUG: This entry maybe changed to PCD in future and wait for
// redesign of BDS library
//
//
// Thunk Status Codes
// (These apply only to errors with the thunk and not to the code that was
// thunked to.)
//
//
// Vector base definitions
//
//
// 8259 Hardware definitions
//
//
// The original PC used INT8-F for master PIC. Since these mapped over
// processor exceptions TIANO moved the master PIC to INT68-6F.
//
// The vector base for slave PIC is set as 0x70 for PC-AT compatibility.
//
//
// When we call CSM16 functions, some CSM16 use es:[offset + 0xabcd] to get data passed from CSM32,
// offset + 0xabcd could overflow which exceeds 0xFFFF which is invalid in real mode.
// So this will keep offset as small as possible to avoid offset overflow in real mode.
//
//
// Trace defines
//
//
typedef struct {
//
// Values for RealModeGdt
//
#if defined (MDE_CPU_IA32)
#elif defined (MDE_CPU_X64)
#elif defined (MDE_CPU_IPF)
#endif
#pragma pack(1)
//
// Define what a processor GDT looks like
//
typedef struct {
} GDT32;
typedef struct {
} GDT64;
//
// Define what a processor descriptor looks like
// This data structure must be kept in sync with ASM STRUCT in Thunk.inc
//
typedef struct {
} DESCRIPTOR64;
typedef struct {
} DESCRIPTOR32;
//
// Low stub lay out
//
#define NOT_FIRST_INSTANCE 0
#if defined (MDE_CPU_IA32)
typedef struct {
//
// Space for the code
// The address of Code is also the beginning of the relocated Thunk code
//
//
// The address of the Reverse Thunk code
// Note that this member CONTAINS the address of the relocated reverse thunk
// code unlike the member variable 'Code', which IS the address of the Thunk
// code.
//
//
// Data for the code (cs releative)
//
//
// real-mode GDT (temporary GDT with two real mode segment descriptors)
//
//
// Members specifically for the reverse thunk
// The RevReal* members are used to store the current state of real mode
// before performing the reverse thunk. The RevFlat* members must be set
// before calling the reverse thunk assembly code.
//
//
// A low memory stack
//
//
// Stack for flat mode after reverse thunk
// @bug - This may no longer be necessary if the reverse thunk interface
// is changed to have the flat stack in a different location.
//
//
// Legacy16 Init memory map info
//
#elif defined (MDE_CPU_X64)
typedef struct {
//
// Space for the code
// The address of Code is also the beginning of the relocated Thunk code
//
//
// Data for the code (cs releative)
//
//
// real-mode GDT (temporary GDT with two real mode segment descriptors)
//
//
// A low memory stack
//
//
// Legacy16 Init memory map info
//
#elif defined (MDE_CPU_IPF)
typedef struct {
//
// Space for the code
// The address of Code is also the beginning of the relocated Thunk code
//
//
// The address of the Reverse Thunk code
// Note that this member CONTAINS the address of the relocated reverse thunk
// code unlike the member variable 'Code', which IS the address of the Thunk
// code.
//
//
// Data for the code (cs releative)
//
//
// real-mode GDT (temporary GDT with two real mode segment descriptors)
//
//
// Members specifically for the reverse thunk
// The RevReal* members are used to store the current state of real mode
// before performing the reverse thunk. The RevFlat* members must be set
// before calling the reverse thunk assembly code.
//
//
// A low memory stack
//
//
// Stack for flat mode after reverse thunk
// @bug - This may no longer be necessary if the reverse thunk interface
// is changed to have the flat stack in a different location.
//
//
// Legacy16 Init memory map info
//
#endif
//
// PnP Expansion Header
//
typedef struct {
typedef struct {
//
// Structure how EFI has mapped a devices HDD drive numbers.
// Boot to EFI aware OS or shell requires this mapping when
// 16-bit CSM assigns drive numbers.
// This mapping is ignored booting to a legacy OS.
//
typedef struct {
//
// This data is passed to Leacy16Boot
//
typedef enum {
typedef struct {
typedef struct {
#pragma pack()
//
// 8254 Timer registers
//
//
//
typedef struct {
//
// CPU Architectural Protocol
//
//
// Timer Architectural Protocol
//
//
// Protocol to Lock and Unlock 0xc0000 - 0xfffff
//
//
// Interrupt control for thunk and PCI IRQ
//
//
// PCI Interrupt PIRQ control
//
//
// Generic Memory Test
//
//
// TRUE if PCI Interupt Line registers have been programmed.
//
//
// Code space below 1MB needed by thunker to transition to real mode.
// Contains stack and real mode code fragments
//
//
// Starting shadow address of the Legacy BIOS
//
//
//
//
// $EFI Legacy16 code entry info in memory < 1 MB;
//
//
// Cached copy of Legacy16 entry point
//
//
// Returned from $EFI and passed in to OPROMS
//
//
// E820 table
//
//
// True if legacy VGA INT 10h handler installed
//
//
// Number of IDE drives
//
//
// Current Free Option ROM space. An option ROM must NOT go past
// BiosStart.
//
//
// Save Legacy16 unexpected interrupt vector. Reprogram INT 68-6F from
// EFI values to legacy value just before boot.
//
//
// Indicate that whether GenericLegacyBoot is entered or not
//
//
// CSM16 PCI Interface Version
//
#pragma pack(1)
/*
40:00-01 Com1
40:02-03 Com2
40:04-05 Com3
40:06-07 Com4
40:08-09 Lpt1
40:0A-0B Lpt2
40:0C-0D Lpt3
40:0E-0E Ebda segment
40:10-11 MachineConfig
40:12 Bda12 - skip
40:13-14 MemSize below 1MB
40:15-16 Bda15_16 - skip
40:17 Keyboard Shift status
40:18-19 Bda18_19 - skip
40:1A-1B Key buffer head
40:1C-1D Key buffer tail
40:1E-3D Bda1E_3D- key buffer -skip
40:3E-3F FloppyData 3E = Calibration status 3F = Motor status
40:40 FloppyTimeout
40:41-74 Bda41_74 - skip
40:75 Number of HDD drives
40:76-77 Bda76_77 - skip
40:78-79 78 = Lpt1 timeout, 79 = Lpt2 timeout
40:7A-7B 7A = Lpt3 timeout, 7B = Lpt4 timeout
40:7C-7D 7C = Com1 timeout, 7D = Com2 timeout
40:7E-7F 7E = Com3 timeout, 7F = Com4 timeout
40:80-81 Pointer to start of key buffer
40:82-83 Pointer to end of key buffer
40:84-87 Bda84_87 - skip
40:88 HDD Data Xmit rate
40:89-8f skip
40:90 Floppy data rate
40:91-95 skip
40:96 Keyboard Status
40:97 LED Status
40:98-101 skip
*/
typedef struct {
} BDA_STRUC;
#pragma pack()
#define LEGACY_BIOS_INSTANCE_FROM_THIS(this) CR (this, LEGACY_BIOS_INSTANCE, LegacyBios, LEGACY_BIOS_INSTANCE_SIGNATURE)
/**
Thunk to 16-bit real mode and execute a software interrupt with a vector
of BiosInt. Regs will contain the 16-bit register context on entry and
exit.
@param This Protocol instance pointer.
@param BiosInt Processor interrupt vector to invoke
@param Regs Register contexted passed into (and returned) from thunk to
16-bit mode
@retval FALSE Thunk completed, and there were no BIOS errors in the target code.
See Regs for status.
@retval TRUE There was a BIOS erro in the target code.
**/
);
/**
Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
16-bit register context on entry and exit. Arguments can be passed on
the Stack argument
@param This Protocol instance pointer.
@param Segment Segemnt of 16-bit mode call
@param Offset Offset of 16-bit mdoe call
@param Regs Register contexted passed into (and returned) from
thunk to 16-bit mode
@param Stack Caller allocated stack used to pass arguments
@param StackSize Size of Stack in bytes
@retval FALSE Thunk completed, and there were no BIOS errors in
the target code. See Regs for status.
@retval TRUE There was a BIOS erro in the target code.
**/
);
/**
Test to see if a legacy PCI ROM exists for this device. Optionally return
the Legacy ROM instance for this PCI device.
@param This Protocol instance pointer.
@param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
be loaded
@param RomImage Return the legacy PCI ROM for this device
@param RomSize Size of ROM Image
@param Flags Indicates if ROM found and if PC-AT.
@retval EFI_SUCCESS Legacy Option ROM availible for this device
@retval EFI_UNSUPPORTED Legacy Option ROM not supported.
**/
);
/**
Assign drive number to legacy HDD drives prior to booting an EFI
aware OS so the OS can access drives without an EFI driver.
Note: BBS compliant drives ARE NOT available until this call by
either shell or EFI.
@param This Protocol instance pointer.
@param BbsCount Number of BBS_TABLE structures
@param BbsTable List BBS entries
@retval EFI_SUCCESS Drive numbers assigned
**/
);
/**
HDD diagnostics.
@param This Protocol instance pointer.
@param Attributes How to interpret the other input parameters
@param BbsEntry The 0-based index into the BbsTable for the parent
device.
@param BeerData Pointer to the 128 bytes of ram BEER data.
@param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
The caller must provide a pointer to the specific
Service Area and not the start all Service Areas.
EFI_INVALID_PARAMETER if error. Does NOT return if no error.
**/
);
/**
Load a legacy PC-AT OPROM on the PciHandle device. Return information
about how many disks were added by the OPROM and the shadow address and
size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
@param This Protocol instance pointer.
@param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
be loaded. This value is NULL if RomImage is
non-NULL. This is the normal case.
@param RomImage A PCI PC-AT ROM image. This argument is non-NULL
if there is no hardware associated with the ROM
and thus no PciHandle, otherwise is must be NULL.
Example is PXE base code.
@param Flags Indicates if ROM found and if PC-AT.
@param DiskStart Disk number of first device hooked by the ROM. If
DiskStart is the same as DiskEnd no disked were
hooked.
@param DiskEnd Disk number of the last device hooked by the ROM.
@param RomShadowAddress Shadow address of PC-AT ROM
@param RomShadowedSize Size of RomShadowAddress in bytes
@retval EFI_SUCCESS Legacy ROM loaded for this device
@retval EFI_INVALID_PARAMETER PciHandle not found
@retval EFI_UNSUPPORTED There is no PCI ROM in the ROM BAR or no onboard
ROM
**/
);
/**
Fill in the standard BDA for Keyboard LEDs
@param This Protocol instance pointer.
@param Leds Current LED status
@retval EFI_SUCCESS It should always work.
**/
);
/**
Get all BBS info
@param This Protocol instance pointer.
@param HddCount Number of HDD_INFO structures
@param HddInfo Onboard IDE controller information
@param BbsCount Number of BBS_TABLE structures
@param BbsTable List BBS entries
@retval EFI_SUCCESS Tables returned
@retval EFI_NOT_FOUND resource not found
@retval EFI_DEVICE_ERROR can not get BBS table
**/
);
/**
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
**/
);
/**
Attempt to legacy boot the BootOption. If the EFI contexted has been
compromised this function will not return.
@param This Protocol instance pointer.
@param BbsDevicePath EFI Device Path from BootXXXX variable.
@param LoadOptionsSize Size of LoadOption in size.
@param LoadOptions LoadOption from BootXXXX variable
@retval EFI_SUCCESS Removable media not present
**/
);
/**
Allocate memory < 1 MB and copy the thunker code into low memory. Se up
all the descriptors.
@param Private Private context for Legacy BIOS
@retval EFI_SUCCESS Should only pass.
**/
);
/**
Fill in the standard BDA and EBDA stuff before Legacy16 load
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS It should always work.
**/
);
/**
Collect IDE Inquiry data from the IDE disks
@param Private Legacy BIOS Instance data
@param HddInfo Hdd Information
@param Flag Reconnect IdeController or not
@retval EFI_SUCCESS It should always work.
**/
);
/**
Enable ide controller. This gets disabled when LegacyBoot.c is about
to run the Option ROMs.
@param Private Legacy BIOS Instance data
**/
);
/**
If the IDE channel is in compatibility (legacy) mode, remove all
PCI I/O BAR addresses from the controller.
@param IdeController The handle of target IDE controller
**/
);
/**
Program the interrupt routing register in all the PCI devices. On a PC AT system
this register contains the 8259 IRQ vector that matches it's PCI interrupt.
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS Succeed.
@retval EFI_ALREADY_STARTED All PCI devices have been processed.
**/
);
/**
Collect EFI Info about legacy devices.
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS It should always work.
**/
);
/**
Shadow all the PCI legacy ROMs. Use data from the Legacy BIOS Protocol
to chose the order. Skip any devices that have already have legacy
BIOS run.
@param Private Protocol instance pointer.
@retval EFI_SUCCESS Succeed.
@retval EFI_UNSUPPORTED Cannot get VGA device handle.
**/
);
/**
Fill in the standard BDA and EBDA stuff prior to legacy Boot
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS It should always work.
**/
);
/**
Fill in the standard CMOS stuff before Legacy16 load
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS It should always work.
**/
);
/**
Fill in the standard CMOS stuff prior to legacy Boot
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS It should always work.
**/
);
/**
Contains the code that is copied into low memory (below 640K).
This code reflects interrupts 0x68-0x6f to interrupts 0x08-0x0f.
This template must be copied into low memory, and the IDT entries
0x68-0x6F must be point to the low memory copy of this code. Each
entry is 4 bytes long, so IDT entries 0x68-0x6F can be easily
computed.
**/
);
/**
Build the E820 table.
@param Private Legacy BIOS Instance data
@param Size Size of E820 Table
@retval EFI_SUCCESS It should always work.
**/
);
/**
This function is to put all AP in halt state.
@param Private Legacy BIOS Instance data
**/
);
/**
Worker function for LegacyBiosGetFlatDescs, retrieving content of
specific registers.
@param IntThunk Pointer to IntThunk of Legacy BIOS context.
**/
);
/**
Routine for calling real thunk code.
@param RealCode The address of thunk code.
@param BiosInt The Bios interrupt vector number.
@param CallAddress The address of 16-bit mode call.
@return Status returned by real thunk code
**/
);
/**
Routine for generating soft interrupt.
@param Vector The interrupt vector number.
**/
);
/**
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.
**/
);
/**
Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
@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
**/
);
/**
Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
@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 Region assigned
@retval EFI_ACCESS_DENIED Destination outside assigned region
**/
);
/**
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.
**/
);
/**
Checks the state of the floppy and if media is inserted.
This routine checks the state of the floppy and if media is inserted.
There are 3 cases:
No floppy present - Set BBS entry to ignore
Floppy present & no media - Set BBS entry to lowest priority. We cannot
set it to ignore since 16-bit CSM will
indicate no floppy and thus drive A: is
unusable. CSM-16 will not try floppy since
lowest priority and thus not incur boot
time penality.
Floppy present & media - Set BBS entry to some priority.
@return State of floppy media
**/
);
/**
Identify drive data must be updated to actual parameters before boot.
This requires updating the checksum, if it exists.
@param IdentifyDriveData ATA Identify Data
@param Checksum checksum of the ATA Identify Data
@retval EFI_SUCCESS checksum calculated
@retval EFI_SECURITY_VIOLATION IdentifyData invalid
**/
);
/**
Identify drive data must be updated to actual parameters before boot.
@param IdentifyDriveData ATA Identify Data
**/
);
/**
Complete build of BBS TABLE.
@param Private Legacy BIOS Instance data
@param BbsTable BBS Table passed to 16-bit code
@retval EFI_SUCCESS Removable media not present
**/
);
/**
@param[in] Index The index of the CMOS register to read.
@return The data value from the CMOS register specified by Index.
**/
);
/**
@param[in] Index The index of the CMOS register to write.
@param[in] Value The value of CMOS register to write.
@return The value written to the CMOS register specified by Index.
**/
);
/**
Calculate the new standard CMOS checksum and write it.
@param Private Legacy BIOS Instance data
@retval EFI_SUCCESS Calculate 16-bit checksum successfully
**/
);
/**
Test to see if a legacy PCI ROM exists for this device. Optionally return
the Legacy ROM instance for this PCI device.
@param[in] This Protocol instance pointer.
@param[in] PciHandle The PCI PC-AT OPROM from this devices ROM BAR will be loaded
@param[out] RomImage Return the legacy PCI ROM for this device
@param[out] RomSize Size of ROM Image
@param[out] RuntimeImageLength Runtime size of ROM Image
@param[out] Flags Indicates if ROM found and if PC-AT.
@param[out] OpromRevision Revision of the PCI Rom
@param[out] ConfigUtilityCodeHeaderPointer of Configuration Utility Code Header
@return EFI_SUCCESS Legacy Option ROM availible for this device
@return EFI_ALREADY_STARTED This device is already managed by its Oprom
@return EFI_UNSUPPORTED Legacy Option ROM not supported.
**/
);
/**
Relocate this image under 4G memory for IPF.
@param ImageHandle Handle of driver image.
@param SystemTable Pointer to system table.
@retval EFI_SUCCESS Image successfully relocated.
@retval EFI_ABORTED Failed to relocate image.
**/
);
/**
Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
16-bit register context on entry and exit. Arguments can be passed on
the Stack argument
@param This Protocol instance pointer.
@param Segment Segemnt of 16-bit mode call
@param Offset Offset of 16-bit mdoe call
@param Regs Register contexted passed into (and returned) from thunk to
16-bit mode
@param Stack Caller allocated stack used to pass arguments
@param StackSize Size of Stack in bytes
@retval FALSE Thunk completed, and there were no BIOS errors in the target code.
See Regs for status.
@retval TRUE There was a BIOS erro in the target code.
**/
);
#endif