Home | History | Annotate | Download | only in Protocol
      1 /** @file
      2   The EFI Legacy BIOS Protocol is used to abstract legacy Option ROM usage
      3   under EFI and Legacy OS boot.  This file also includes all the related
      4   COMPATIBILIY16 structures and defintions.
      5 
      6   Note: The names for EFI_IA32_REGISTER_SET elements were picked to follow
      7   well known naming conventions.
      8 
      9   Thunk is the code that switches from 32-bit protected environment into the 16-bit real-mode
     10 	environment. Reverse thunk is the code that does the opposite.
     11 
     12 Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
     13 This program and the accompanying materials are licensed and made available under
     14 the terms and conditions of the BSD License that accompanies this distribution.
     15 The full text of the license may be found at
     16 http://opensource.org/licenses/bsd-license.php.
     17 
     18 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     19 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     20 
     21   @par Revision Reference:
     22   This protocol is defined in Framework for EFI Compatibility Support Module spec
     23   Version 0.98.
     24 
     25 **/
     26 
     27 #ifndef _EFI_LEGACY_BIOS_H_
     28 #define _EFI_LEGACY_BIOS_H_
     29 
     30 ///
     31 ///
     32 ///
     33 #pragma pack(1)
     34 
     35 typedef UINT8                       SERIAL_MODE;
     36 typedef UINT8                       PARALLEL_MODE;
     37 
     38 #define EFI_COMPATIBILITY16_TABLE_SIGNATURE SIGNATURE_32 ('I', 'F', 'E', '$')
     39 
     40 ///
     41 /// There is a table located within the traditional BIOS in either the 0xF000:xxxx or 0xE000:xxxx
     42 /// physical address range. It is located on a 16-byte boundary and provides the physical address of the
     43 /// entry point for the Compatibility16 functions. These functions provide the platform-specific
     44 /// information that is required by the generic EfiCompatibility code. The functions are invoked via
     45 /// thunking by using EFI_LEGACY_BIOS_PROTOCOL.FarCall86() with the 32-bit physical
     46 /// entry point.
     47 ///
     48 typedef struct {
     49   ///
     50   /// The string "$EFI" denotes the start of the EfiCompatibility table. Byte 0 is "I," byte
     51   /// 1 is "F," byte 2 is "E," and byte 3 is "$" and is normally accessed as a DWORD or UINT32.
     52   ///
     53   UINT32                            Signature;
     54 
     55   ///
     56   /// The value required such that byte checksum of TableLength equals zero.
     57   ///
     58   UINT8                             TableChecksum;
     59 
     60   ///
     61   /// The length of this table.
     62   ///
     63   UINT8                             TableLength;
     64 
     65   ///
     66   /// The major EFI revision for which this table was generated.
     67   ///
     68   UINT8                             EfiMajorRevision;
     69 
     70   ///
     71   /// The minor EFI revision for which this table was generated.
     72   ///
     73   UINT8                             EfiMinorRevision;
     74 
     75   ///
     76   /// The major revision of this table.
     77   ///
     78   UINT8                             TableMajorRevision;
     79 
     80   ///
     81   /// The minor revision of this table.
     82   ///
     83   UINT8                             TableMinorRevision;
     84 
     85   ///
     86   /// Reserved for future usage.
     87   ///
     88   UINT16                            Reserved;
     89 
     90   ///
     91   /// The segment of the entry point within the traditional BIOS for Compatibility16 functions.
     92   ///
     93   UINT16                            Compatibility16CallSegment;
     94 
     95   ///
     96   /// The offset of the entry point within the traditional BIOS for Compatibility16 functions.
     97   ///
     98   UINT16                            Compatibility16CallOffset;
     99 
    100   ///
    101   /// The segment of the entry point within the traditional BIOS for EfiCompatibility
    102   /// to invoke the PnP installation check.
    103   ///
    104   UINT16                            PnPInstallationCheckSegment;
    105 
    106   ///
    107   /// The Offset of the entry point within the traditional BIOS for EfiCompatibility
    108   /// to invoke the PnP installation check.
    109   ///
    110   UINT16                            PnPInstallationCheckOffset;
    111 
    112   ///
    113   /// EFI system resources table. Type EFI_SYSTEM_TABLE is defined in the IntelPlatform
    114   ///Innovation Framework for EFI Driver Execution Environment Core Interface Specification (DXE CIS).
    115   ///
    116   UINT32                            EfiSystemTable;
    117 
    118   ///
    119   /// The address of an OEM-provided identifier string. The string is null terminated.
    120   ///
    121   UINT32                            OemIdStringPointer;
    122 
    123   ///
    124   /// The 32-bit physical address where ACPI RSD PTR is stored within the traditional
    125   /// BIOS. The remained of the ACPI tables are located at their EFI addresses. The size
    126   /// reserved is the maximum for ACPI 2.0. The EfiCompatibility will fill in the ACPI
    127   /// RSD PTR with either the ACPI 1.0b or 2.0 values.
    128   ///
    129   UINT32                            AcpiRsdPtrPointer;
    130 
    131   ///
    132   /// The OEM revision number. Usage is undefined but provided for OEM module usage.
    133   ///
    134   UINT16                            OemRevision;
    135 
    136   ///
    137   /// The 32-bit physical address where INT15 E820 data is stored within the traditional
    138   /// BIOS. The EfiCompatibility code will fill in the E820Pointer value and copy the
    139   /// data to the indicated area.
    140   ///
    141   UINT32                            E820Pointer;
    142 
    143   ///
    144   /// The length of the E820 data and is filled in by the EfiCompatibility code.
    145   ///
    146   UINT32                            E820Length;
    147 
    148   ///
    149   /// The 32-bit physical address where the $PIR table is stored in the traditional BIOS.
    150   /// The EfiCompatibility code will fill in the IrqRoutingTablePointer value and
    151   /// copy the data to the indicated area.
    152   ///
    153   UINT32                            IrqRoutingTablePointer;
    154 
    155   ///
    156   /// The length of the $PIR table and is filled in by the EfiCompatibility code.
    157   ///
    158   UINT32                            IrqRoutingTableLength;
    159 
    160   ///
    161   /// The 32-bit physical address where the MP table is stored in the traditional BIOS.
    162   /// The EfiCompatibility code will fill in the MpTablePtr value and copy the data
    163   /// to the indicated area.
    164   ///
    165   UINT32                            MpTablePtr;
    166 
    167   ///
    168   /// The length of the MP table and is filled in by the EfiCompatibility code.
    169   ///
    170   UINT32                            MpTableLength;
    171 
    172   ///
    173   /// The segment of the OEM-specific INT table/code.
    174   ///
    175   UINT16                            OemIntSegment;
    176 
    177   ///
    178   /// The offset of the OEM-specific INT table/code.
    179   ///
    180   UINT16                            OemIntOffset;
    181 
    182   ///
    183   /// The segment of the OEM-specific 32-bit table/code.
    184   ///
    185   UINT16                            Oem32Segment;
    186 
    187   ///
    188   /// The offset of the OEM-specific 32-bit table/code.
    189   ///
    190   UINT16                            Oem32Offset;
    191 
    192   ///
    193   /// The segment of the OEM-specific 16-bit table/code.
    194   ///
    195   UINT16                            Oem16Segment;
    196 
    197   ///
    198   /// The offset of the OEM-specific 16-bit table/code.
    199   ///
    200   UINT16                            Oem16Offset;
    201 
    202   ///
    203   /// The segment of the TPM binary passed to 16-bit CSM.
    204   ///
    205   UINT16                            TpmSegment;
    206 
    207   ///
    208   /// The offset of the TPM binary passed to 16-bit CSM.
    209   ///
    210   UINT16                            TpmOffset;
    211 
    212   ///
    213   /// A pointer to a string identifying the independent BIOS vendor.
    214   ///
    215   UINT32                            IbvPointer;
    216 
    217   ///
    218   /// This field is NULL for all systems not supporting PCI Express. This field is the base
    219   /// value of the start of the PCI Express memory-mapped configuration registers and
    220   /// must be filled in prior to EfiCompatibility code issuing the Compatibility16 function
    221   /// Compatibility16InitializeYourself().
    222   /// Compatibility16InitializeYourself() is defined in Compatability16
    223   /// Functions.
    224   ///
    225   UINT32                            PciExpressBase;
    226 
    227   ///
    228   /// Maximum PCI bus number assigned.
    229   ///
    230   UINT8                             LastPciBus;
    231 
    232   ///
    233   /// Start Address of Upper Memory Area (UMA) to be set as Read/Write. If
    234   /// UmaAddress is a valid address in the shadow RAM, it also indicates that the region
    235   /// from 0xC0000 to (UmaAddress - 1) can be used for Option ROM.
    236   ///
    237   UINT32                            UmaAddress;
    238 
    239   ///
    240   /// Upper Memory Area size in bytes to be set as Read/Write. If zero, no UMA region
    241   /// will be set as Read/Write (i.e. all Shadow RAM is set as Read-Only).
    242   ///
    243   UINT32                            UmaSize;
    244 
    245   ///
    246   /// Start Address of high memory that can be used for permanent allocation. If zero,
    247   /// high memory is not available for permanent allocation.
    248   ///
    249   UINT32                            HiPermanentMemoryAddress;
    250 
    251   ///
    252   /// Size of high memory that can be used for permanent allocation in bytes. If zero,
    253   /// high memory is not available for permanent allocation.
    254   ///
    255   UINT32                            HiPermanentMemorySize;
    256 } EFI_COMPATIBILITY16_TABLE;
    257 
    258 ///
    259 /// Functions provided by the CSM binary which communicate between the EfiCompatibility
    260 /// and Compatability16 code.
    261 ///
    262 /// Inconsistent with the specification here:
    263 /// The member's name started with "Compatibility16" [defined in Intel Framework
    264 /// Compatibility Support Module Specification / 0.97 version]
    265 /// has been changed to "Legacy16" since keeping backward compatible.
    266 ///
    267 typedef enum {
    268   ///
    269   /// Causes the Compatibility16 code to do any internal initialization required.
    270   /// Input:
    271   ///   AX = Compatibility16InitializeYourself
    272   ///   ES:BX = Pointer to EFI_TO_COMPATIBILITY16_INIT_TABLE
    273   /// Return:
    274   ///   AX = Return Status codes
    275   ///
    276   Legacy16InitializeYourself    = 0x0000,
    277 
    278   ///
    279   /// Causes the Compatibility16 BIOS to perform any drive number translations to match the boot sequence.
    280   /// Input:
    281   ///   AX = Compatibility16UpdateBbs
    282   ///   ES:BX = Pointer to EFI_TO_COMPATIBILITY16_BOOT_TABLE
    283   /// Return:
    284   ///   AX = Returned status codes
    285   ///
    286   Legacy16UpdateBbs             = 0x0001,
    287 
    288   ///
    289   /// Allows the Compatibility16 code to perform any final actions before booting. The Compatibility16
    290   /// code is read/write.
    291   /// Input:
    292   ///   AX = Compatibility16PrepareToBoot
    293   ///   ES:BX = Pointer to EFI_TO_COMPATIBILITY16_BOOT_TABLE structure
    294   /// Return:
    295   ///   AX = Returned status codes
    296   ///
    297   Legacy16PrepareToBoot         = 0x0002,
    298 
    299   ///
    300   /// Causes the Compatibility16 BIOS to boot. The Compatibility16 code is Read/Only.
    301   /// Input:
    302   ///   AX = Compatibility16Boot
    303   /// Output:
    304   ///   AX = Returned status codes
    305   ///
    306   Legacy16Boot                  = 0x0003,
    307 
    308   ///
    309   /// Allows the Compatibility16 code to get the last device from which a boot was attempted. This is
    310   /// stored in CMOS and is the priority number of the last attempted boot device.
    311   /// Input:
    312   ///   AX = Compatibility16RetrieveLastBootDevice
    313   /// Output:
    314   ///   AX = Returned status codes
    315   ///   BX = Priority number of the boot device.
    316   ///
    317   Legacy16RetrieveLastBootDevice = 0x0004,
    318 
    319   ///
    320   /// Allows the Compatibility16 code rehook INT13, INT18, and/or INT19 after dispatching a legacy OpROM.
    321   /// Input:
    322   ///   AX = Compatibility16DispatchOprom
    323   ///   ES:BX = Pointer to EFI_DISPATCH_OPROM_TABLE
    324   /// Output:
    325   ///   AX = Returned status codes
    326   ///   BX = Number of non-BBS-compliant devices found. Equals 0 if BBS compliant.
    327   ///
    328   Legacy16DispatchOprom         = 0x0005,
    329 
    330   ///
    331   /// Finds a free area in the 0xFxxxx or 0xExxxx region of the specified length and returns the address
    332   /// of that region.
    333   /// Input:
    334   ///   AX = Compatibility16GetTableAddress
    335   ///   BX = Allocation region
    336   ///       00 = Allocate from either 0xE0000 or 0xF0000 64 KB blocks.
    337   ///       Bit 0 = 1 Allocate from 0xF0000 64 KB block
    338   ///       Bit 1 = 1 Allocate from 0xE0000 64 KB block
    339   ///   CX = Requested length in bytes.
    340   ///   DX = Required address alignment. Bit mapped. First non-zero bit from the right is the alignment.
    341   /// Output:
    342   ///   AX = Returned status codes
    343   ///   DS:BX = Address of the region
    344   ///
    345   Legacy16GetTableAddress       = 0x0006,
    346 
    347   ///
    348   /// Enables the EfiCompatibility module to do any nonstandard processing of keyboard LEDs or state.
    349   /// Input:
    350   ///   AX = Compatibility16SetKeyboardLeds
    351   ///   CL = LED status.
    352   ///     Bit 0  Scroll Lock 0 = Off
    353   ///     Bit 1  NumLock
    354   ///     Bit 2  Caps Lock
    355   /// Output:
    356   ///     AX = Returned status codes
    357   ///
    358   Legacy16SetKeyboardLeds       = 0x0007,
    359 
    360   ///
    361   /// Enables the EfiCompatibility module to install an interrupt handler for PCI mass media devices that
    362   /// do not have an OpROM associated with them. An example is SATA.
    363   /// Input:
    364   ///   AX = Compatibility16InstallPciHandler
    365   ///   ES:BX = Pointer to EFI_LEGACY_INSTALL_PCI_HANDLER structure
    366   /// Output:
    367   ///   AX = Returned status codes
    368   ///
    369   Legacy16InstallPciHandler     = 0x0008
    370 } EFI_COMPATIBILITY_FUNCTIONS;
    371 
    372 
    373 ///
    374 /// EFI_DISPATCH_OPROM_TABLE
    375 ///
    376 typedef struct {
    377   UINT16  PnPInstallationCheckSegment;  ///< A pointer to the PnpInstallationCheck data structure.
    378   UINT16  PnPInstallationCheckOffset;   ///< A pointer to the PnpInstallationCheck data structure.
    379   UINT16  OpromSegment;                 ///< The segment where the OpROM was placed. Offset is assumed to be 3.
    380   UINT8   PciBus;                       ///< The PCI bus.
    381   UINT8   PciDeviceFunction;            ///< The PCI device * 0x08 | PCI function.
    382   UINT8   NumberBbsEntries;             ///< The number of valid BBS table entries upon entry and exit. The IBV code may
    383                                         ///< increase this number, if BBS-compliant devices also hook INTs in order to force the
    384                                         ///< OpROM BIOS Setup to be executed.
    385   UINT32  BbsTablePointer;              ///< A pointer to the BBS table.
    386   UINT16  RuntimeSegment;               ///< The segment where the OpROM can be relocated to. If this value is 0x0000, this
    387                                         ///< means that the relocation of this run time code is not supported.
    388                                         ///< Inconsistent with specification here:
    389                                         ///< The member's name "OpromDestinationSegment" [defined in Intel Framework Compatibility Support Module Specification / 0.97 version]
    390                                         ///< has been changed to "RuntimeSegment" since keeping backward compatible.
    391 
    392 } EFI_DISPATCH_OPROM_TABLE;
    393 
    394 ///
    395 /// EFI_TO_COMPATIBILITY16_INIT_TABLE
    396 ///
    397 typedef struct {
    398   ///
    399   /// Starting address of memory under 1 MB. The ending address is assumed to be 640 KB or 0x9FFFF.
    400   ///
    401   UINT32                            BiosLessThan1MB;
    402 
    403   ///
    404   /// The starting address of the high memory block.
    405   ///
    406   UINT32                            HiPmmMemory;
    407 
    408   ///
    409   /// The length of high memory block.
    410   ///
    411   UINT32                            HiPmmMemorySizeInBytes;
    412 
    413   ///
    414   /// The segment of the reverse thunk call code.
    415   ///
    416   UINT16                            ReverseThunkCallSegment;
    417 
    418   ///
    419   /// The offset of the reverse thunk call code.
    420   ///
    421   UINT16                            ReverseThunkCallOffset;
    422 
    423   ///
    424   /// The number of E820 entries copied to the Compatibility16 BIOS.
    425   ///
    426   UINT32                            NumberE820Entries;
    427 
    428   ///
    429   /// The amount of usable memory above 1 MB, e.g., E820 type 1 memory.
    430   ///
    431   UINT32                            OsMemoryAbove1Mb;
    432 
    433   ///
    434   /// The start of thunk code in main memory. Memory cannot be used by BIOS or PMM.
    435   ///
    436   UINT32                            ThunkStart;
    437 
    438   ///
    439   /// The size of the thunk code.
    440   ///
    441   UINT32                            ThunkSizeInBytes;
    442 
    443   ///
    444   /// Starting address of memory under 1 MB.
    445   ///
    446   UINT32                            LowPmmMemory;
    447 
    448   ///
    449   /// The length of low Memory block.
    450   ///
    451   UINT32                            LowPmmMemorySizeInBytes;
    452 } EFI_TO_COMPATIBILITY16_INIT_TABLE;
    453 
    454 ///
    455 /// DEVICE_PRODUCER_SERIAL.
    456 ///
    457 typedef struct {
    458   UINT16                            Address;    ///< I/O address assigned to the serial port.
    459   UINT8                             Irq;        ///< IRQ assigned to the serial port.
    460   SERIAL_MODE                       Mode;       ///< Mode of serial port. Values are defined below.
    461 } DEVICE_PRODUCER_SERIAL;
    462 
    463 ///
    464 /// DEVICE_PRODUCER_SERIAL's modes.
    465 ///@{
    466 #define DEVICE_SERIAL_MODE_NORMAL               0x00
    467 #define DEVICE_SERIAL_MODE_IRDA                 0x01
    468 #define DEVICE_SERIAL_MODE_ASK_IR               0x02
    469 #define DEVICE_SERIAL_MODE_DUPLEX_HALF          0x00
    470 #define DEVICE_SERIAL_MODE_DUPLEX_FULL          0x10
    471 ///@)
    472 
    473 ///
    474 /// DEVICE_PRODUCER_PARALLEL.
    475 ///
    476 typedef struct {
    477   UINT16                            Address;  ///< I/O address assigned to the parallel port.
    478   UINT8                             Irq;      ///< IRQ assigned to the parallel port.
    479   UINT8                             Dma;      ///< DMA assigned to the parallel port.
    480   PARALLEL_MODE                     Mode;     ///< Mode of the parallel port. Values are defined below.
    481 } DEVICE_PRODUCER_PARALLEL;
    482 
    483 ///
    484 /// DEVICE_PRODUCER_PARALLEL's modes.
    485 ///@{
    486 #define DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY   0x00
    487 #define DEVICE_PARALLEL_MODE_MODE_BIDIRECTIONAL 0x01
    488 #define DEVICE_PARALLEL_MODE_MODE_EPP           0x02
    489 #define DEVICE_PARALLEL_MODE_MODE_ECP           0x03
    490 ///@}
    491 
    492 ///
    493 /// DEVICE_PRODUCER_FLOPPY
    494 ///
    495 typedef struct {
    496   UINT16                            Address;          ///< I/O address assigned to the floppy.
    497   UINT8                             Irq;              ///< IRQ assigned to the floppy.
    498   UINT8                             Dma;              ///< DMA assigned to the floppy.
    499   UINT8                             NumberOfFloppy;   ///< Number of floppies in the system.
    500 } DEVICE_PRODUCER_FLOPPY;
    501 
    502 ///
    503 /// LEGACY_DEVICE_FLAGS
    504 ///
    505 typedef struct {
    506   UINT32                            A20Kybd : 1;      ///< A20 controller by keyboard controller.
    507   UINT32                            A20Port90 : 1;    ///< A20 controlled by port 0x92.
    508   UINT32                            Reserved : 30;    ///< Reserved for future usage.
    509 } LEGACY_DEVICE_FLAGS;
    510 
    511 ///
    512 /// DEVICE_PRODUCER_DATA_HEADER
    513 ///
    514 typedef struct {
    515   DEVICE_PRODUCER_SERIAL            Serial[4];      ///< Data for serial port x. Type DEVICE_PRODUCER_SERIAL is defined below.
    516   DEVICE_PRODUCER_PARALLEL          Parallel[3];    ///< Data for parallel port x. Type DEVICE_PRODUCER_PARALLEL is defined below.
    517   DEVICE_PRODUCER_FLOPPY            Floppy;         ///< Data for floppy. Type DEVICE_PRODUCER_FLOPPY is defined below.
    518   UINT8                             MousePresent;   ///< Flag to indicate if mouse is present.
    519   LEGACY_DEVICE_FLAGS               Flags;          ///< Miscellaneous Boolean state information passed to CSM.
    520 } DEVICE_PRODUCER_DATA_HEADER;
    521 
    522 ///
    523 /// ATAPI_IDENTIFY
    524 ///
    525 typedef struct {
    526   UINT16                            Raw[256];     ///< Raw data from the IDE IdentifyDrive command.
    527 } ATAPI_IDENTIFY;
    528 
    529 ///
    530 /// HDD_INFO
    531 ///
    532 typedef struct {
    533   ///
    534   /// Status of IDE device. Values are defined below. There is one HDD_INFO structure
    535   /// per IDE controller. The IdentifyDrive is per drive. Index 0 is master and index
    536   /// 1 is slave.
    537   ///
    538   UINT16                            Status;
    539 
    540   ///
    541   /// PCI bus of IDE controller.
    542   ///
    543   UINT32                            Bus;
    544 
    545   ///
    546   /// PCI device of IDE controller.
    547   ///
    548   UINT32                            Device;
    549 
    550   ///
    551   /// PCI function of IDE controller.
    552   ///
    553   UINT32                            Function;
    554 
    555   ///
    556   /// Command ports base address.
    557   ///
    558   UINT16                            CommandBaseAddress;
    559 
    560   ///
    561   /// Control ports base address.
    562   ///
    563   UINT16                            ControlBaseAddress;
    564 
    565   ///
    566   /// Bus master address.
    567   ///
    568   UINT16                            BusMasterAddress;
    569 
    570   UINT8                             HddIrq;
    571 
    572   ///
    573   /// Data that identifies the drive data; one per possible attached drive.
    574   ///
    575   ATAPI_IDENTIFY                    IdentifyDrive[2];
    576 } HDD_INFO;
    577 
    578 ///
    579 /// HDD_INFO status bits
    580 ///
    581 #define HDD_PRIMARY               0x01
    582 #define HDD_SECONDARY             0x02
    583 #define HDD_MASTER_ATAPI_CDROM    0x04
    584 #define HDD_SLAVE_ATAPI_CDROM     0x08
    585 #define HDD_MASTER_IDE            0x20
    586 #define HDD_SLAVE_IDE             0x40
    587 #define HDD_MASTER_ATAPI_ZIPDISK  0x10
    588 #define HDD_SLAVE_ATAPI_ZIPDISK   0x80
    589 
    590 ///
    591 /// BBS_STATUS_FLAGS;\.
    592 ///
    593 typedef struct {
    594   UINT16                            OldPosition : 4;    ///< Prior priority.
    595   UINT16                            Reserved1 : 4;      ///< Reserved for future use.
    596   UINT16                            Enabled : 1;        ///< If 0, ignore this entry.
    597   UINT16                            Failed : 1;         ///< 0 = Not known if boot failure occurred.
    598                                                         ///< 1 = Boot attempted failed.
    599 
    600   ///
    601   /// State of media present.
    602   ///   00 = No bootable media is present in the device.
    603   ///   01 = Unknown if a bootable media present.
    604   ///   10 = Media is present and appears bootable.
    605   ///   11 = Reserved.
    606   ///
    607   UINT16                            MediaPresent : 2;
    608   UINT16                            Reserved2 : 4;      ///< Reserved for future use.
    609 } BBS_STATUS_FLAGS;
    610 
    611 ///
    612 /// BBS_TABLE, device type values & boot priority values.
    613 ///
    614 typedef struct {
    615   ///
    616   /// The boot priority for this boot device. Values are defined below.
    617   ///
    618   UINT16                            BootPriority;
    619 
    620   ///
    621   /// The PCI bus for this boot device.
    622   ///
    623   UINT32                            Bus;
    624 
    625   ///
    626   /// The PCI device for this boot device.
    627   ///
    628   UINT32                            Device;
    629 
    630   ///
    631   /// The PCI function for the boot device.
    632   ///
    633   UINT32                            Function;
    634 
    635   ///
    636   /// The PCI class for this boot device.
    637   ///
    638   UINT8                             Class;
    639 
    640   ///
    641   /// The PCI Subclass for this boot device.
    642   ///
    643   UINT8                             SubClass;
    644 
    645   ///
    646   /// Segment:offset address of an ASCIIZ description string describing the manufacturer.
    647   ///
    648   UINT16                            MfgStringOffset;
    649 
    650   ///
    651   /// Segment:offset address of an ASCIIZ description string describing the manufacturer.
    652   ///
    653   UINT16                            MfgStringSegment;
    654 
    655   ///
    656   /// BBS device type. BBS device types are defined below.
    657   ///
    658   UINT16                            DeviceType;
    659 
    660   ///
    661   /// Status of this boot device. Type BBS_STATUS_FLAGS is defined below.
    662   ///
    663   BBS_STATUS_FLAGS                  StatusFlags;
    664 
    665   ///
    666   /// Segment:Offset address of boot loader for IPL devices or install INT13 handler for
    667   /// BCV devices.
    668   ///
    669   UINT16                            BootHandlerOffset;
    670 
    671   ///
    672   /// Segment:Offset address of boot loader for IPL devices or install INT13 handler for
    673   /// BCV devices.
    674   ///
    675   UINT16                            BootHandlerSegment;
    676 
    677   ///
    678   /// Segment:offset address of an ASCIIZ description string describing this device.
    679   ///
    680   UINT16                            DescStringOffset;
    681 
    682   ///
    683   /// Segment:offset address of an ASCIIZ description string describing this device.
    684   ///
    685   UINT16                            DescStringSegment;
    686 
    687   ///
    688   /// Reserved.
    689   ///
    690   UINT32                            InitPerReserved;
    691 
    692   ///
    693   /// The use of these fields is IBV dependent. They can be used to flag that an OpROM
    694   /// has hooked the specified IRQ. The OpROM may be BBS compliant as some SCSI
    695   /// BBS-compliant OpROMs also hook IRQ vectors in order to run their BIOS Setup
    696   ///
    697   UINT32                            AdditionalIrq13Handler;
    698 
    699   ///
    700   /// The use of these fields is IBV dependent. They can be used to flag that an OpROM
    701   /// has hooked the specified IRQ. The OpROM may be BBS compliant as some SCSI
    702   /// BBS-compliant OpROMs also hook IRQ vectors in order to run their BIOS Setup
    703   ///
    704   UINT32                            AdditionalIrq18Handler;
    705 
    706   ///
    707   /// The use of these fields is IBV dependent. They can be used to flag that an OpROM
    708   /// has hooked the specified IRQ. The OpROM may be BBS compliant as some SCSI
    709   /// BBS-compliant OpROMs also hook IRQ vectors in order to run their BIOS Setup
    710   ///
    711   UINT32                            AdditionalIrq19Handler;
    712 
    713   ///
    714   /// The use of these fields is IBV dependent. They can be used to flag that an OpROM
    715   /// has hooked the specified IRQ. The OpROM may be BBS compliant as some SCSI
    716   /// BBS-compliant OpROMs also hook IRQ vectors in order to run their BIOS Setup
    717   ///
    718   UINT32                            AdditionalIrq40Handler;
    719   UINT8                             AssignedDriveNumber;
    720   UINT32                            AdditionalIrq41Handler;
    721   UINT32                            AdditionalIrq46Handler;
    722   UINT32                            IBV1;
    723   UINT32                            IBV2;
    724 } BBS_TABLE;
    725 
    726 ///
    727 /// BBS device type values
    728 ///@{
    729 #define BBS_FLOPPY              0x01
    730 #define BBS_HARDDISK            0x02
    731 #define BBS_CDROM               0x03
    732 #define BBS_PCMCIA              0x04
    733 #define BBS_USB                 0x05
    734 #define BBS_EMBED_NETWORK       0x06
    735 #define BBS_BEV_DEVICE          0x80
    736 #define BBS_UNKNOWN             0xff
    737 ///@}
    738 
    739 ///
    740 /// BBS boot priority values
    741 ///@{
    742 #define BBS_DO_NOT_BOOT_FROM    0xFFFC
    743 #define BBS_LOWEST_PRIORITY     0xFFFD
    744 #define BBS_UNPRIORITIZED_ENTRY 0xFFFE
    745 #define BBS_IGNORE_ENTRY        0xFFFF
    746 ///@}
    747 
    748 ///
    749 /// SMM_ATTRIBUTES
    750 ///
    751 typedef struct {
    752   ///
    753   /// Access mechanism used to generate the soft SMI. Defined types are below. The other
    754   /// values are reserved for future usage.
    755   ///
    756   UINT16                            Type : 3;
    757 
    758   ///
    759   /// The size of "port" in bits. Defined values are below.
    760   ///
    761   UINT16                            PortGranularity : 3;
    762 
    763   ///
    764   /// The size of data in bits. Defined values are below.
    765   ///
    766   UINT16                            DataGranularity : 3;
    767 
    768   ///
    769   /// Reserved for future use.
    770   ///
    771   UINT16                            Reserved : 7;
    772 } SMM_ATTRIBUTES;
    773 
    774 ///
    775 /// SMM_ATTRIBUTES type values.
    776 ///@{
    777 #define STANDARD_IO       0x00
    778 #define STANDARD_MEMORY   0x01
    779 ///@}
    780 
    781 ///
    782 /// SMM_ATTRIBUTES port size constants.
    783 ///@{
    784 #define PORT_SIZE_8       0x00
    785 #define PORT_SIZE_16      0x01
    786 #define PORT_SIZE_32      0x02
    787 #define PORT_SIZE_64      0x03
    788 ///@}
    789 
    790 ///
    791 /// SMM_ATTRIBUTES data size constants.
    792 ///@{
    793 #define DATA_SIZE_8       0x00
    794 #define DATA_SIZE_16      0x01
    795 #define DATA_SIZE_32      0x02
    796 #define DATA_SIZE_64      0x03
    797 ///@}
    798 
    799 ///
    800 /// SMM_FUNCTION & relating constants.
    801 ///
    802 typedef struct {
    803   UINT16                            Function : 15;
    804   UINT16                            Owner : 1;
    805 } SMM_FUNCTION;
    806 
    807 ///
    808 /// SMM_FUNCTION Function constants.
    809 ///@{
    810 #define INT15_D042        0x0000
    811 #define GET_USB_BOOT_INFO 0x0001
    812 #define DMI_PNP_50_57     0x0002
    813 ///@}
    814 
    815 ///
    816 /// SMM_FUNCTION Owner constants.
    817 ///@{
    818 #define STANDARD_OWNER    0x0
    819 #define OEM_OWNER         0x1
    820 ///@}
    821 
    822 ///
    823 /// This structure assumes both port and data sizes are 1. SmmAttribute must be
    824 /// properly to reflect that assumption.
    825 ///
    826 typedef struct {
    827   ///
    828   /// Describes the access mechanism, SmmPort, and SmmData sizes. Type
    829   /// SMM_ATTRIBUTES is defined below.
    830   ///
    831   SMM_ATTRIBUTES                    SmmAttributes;
    832 
    833   ///
    834   /// Function Soft SMI is to perform. Type SMM_FUNCTION is defined below.
    835   ///
    836   SMM_FUNCTION                      SmmFunction;
    837 
    838   ///
    839   /// SmmPort size depends upon SmmAttributes and ranges from2 bytes to 16 bytes.
    840   ///
    841   UINT8                             SmmPort;
    842 
    843   ///
    844   /// SmmData size depends upon SmmAttributes and ranges from2 bytes to 16 bytes.
    845   ///
    846   UINT8                             SmmData;
    847 } SMM_ENTRY;
    848 
    849 ///
    850 /// SMM_TABLE
    851 ///
    852 typedef struct {
    853   UINT16                            NumSmmEntries;    ///< Number of entries represented by SmmEntry.
    854   SMM_ENTRY                         SmmEntry;         ///< One entry per function. Type SMM_ENTRY is defined below.
    855 } SMM_TABLE;
    856 
    857 ///
    858 /// UDC_ATTRIBUTES
    859 ///
    860 typedef struct {
    861   ///
    862   /// This bit set indicates that the ServiceAreaData is valid.
    863   ///
    864   UINT8                             DirectoryServiceValidity : 1;
    865 
    866   ///
    867   /// This bit set indicates to use the Reserve Area Boot Code Address (RACBA) only if
    868   /// DirectoryServiceValidity is 0.
    869   ///
    870   UINT8                             RabcaUsedFlag : 1;
    871 
    872   ///
    873   /// This bit set indicates to execute hard disk diagnostics.
    874   ///
    875   UINT8                             ExecuteHddDiagnosticsFlag : 1;
    876 
    877   ///
    878   /// Reserved for future use. Set to 0.
    879   ///
    880   UINT8                             Reserved : 5;
    881 } UDC_ATTRIBUTES;
    882 
    883 ///
    884 /// UD_TABLE
    885 ///
    886 typedef struct {
    887   ///
    888   /// This field contains the bit-mapped attributes of the PARTIES information. Type
    889   /// UDC_ATTRIBUTES is defined below.
    890   ///
    891   UDC_ATTRIBUTES                    Attributes;
    892 
    893   ///
    894   /// This field contains the zero-based device on which the selected
    895   /// ServiceDataArea is present. It is 0 for master and 1 for the slave device.
    896   ///
    897   UINT8                             DeviceNumber;
    898 
    899   ///
    900   /// This field contains the zero-based index into the BbsTable for the parent device.
    901   /// This index allows the user to reference the parent device information such as PCI
    902   /// bus, device function.
    903   ///
    904   UINT8                             BbsTableEntryNumberForParentDevice;
    905 
    906   ///
    907   /// This field contains the zero-based index into the BbsTable for the boot entry.
    908   ///
    909   UINT8                             BbsTableEntryNumberForBoot;
    910 
    911   ///
    912   /// This field contains the zero-based index into the BbsTable for the HDD diagnostics entry.
    913   ///
    914   UINT8                             BbsTableEntryNumberForHddDiag;
    915 
    916   ///
    917   /// The raw Beer data.
    918   ///
    919   UINT8                             BeerData[128];
    920 
    921   ///
    922   /// The raw data of selected service area.
    923   ///
    924   UINT8                             ServiceAreaData[64];
    925 } UD_TABLE;
    926 
    927 #define EFI_TO_LEGACY_MAJOR_VERSION 0x02
    928 #define EFI_TO_LEGACY_MINOR_VERSION 0x00
    929 #define MAX_IDE_CONTROLLER          8
    930 
    931 ///
    932 /// EFI_TO_COMPATIBILITY16_BOOT_TABLE
    933 ///
    934 typedef struct {
    935   UINT16                            MajorVersion;                 ///< The EfiCompatibility major version number.
    936   UINT16                            MinorVersion;                 ///< The EfiCompatibility minor version number.
    937   UINT32                            AcpiTable;                    ///< The location of the RSDT ACPI table. < 4G range.
    938   UINT32                            SmbiosTable;                  ///< The location of the SMBIOS table in EFI memory. < 4G range.
    939   UINT32                            SmbiosTableLength;
    940   //
    941   // Legacy SIO state
    942   //
    943   DEVICE_PRODUCER_DATA_HEADER       SioData;                      ///< Standard traditional device information.
    944   UINT16                            DevicePathType;               ///< The default boot type.
    945   UINT16                            PciIrqMask;                   ///< Mask of which IRQs have been assigned to PCI.
    946   UINT32                            NumberE820Entries;            ///< Number of E820 entries. The number can change from the
    947                                                                   ///< Compatibility16InitializeYourself() function.
    948   //
    949   // Controller & Drive Identify[2] per controller information
    950   //
    951   HDD_INFO                          HddInfo[MAX_IDE_CONTROLLER];  ///< Hard disk drive information, including raw Identify Drive data.
    952   UINT32                            NumberBbsEntries;             ///< Number of entries in the BBS table
    953   UINT32                            BbsTable;                     ///< A pointer to the BBS table. Type BBS_TABLE is defined below.
    954   UINT32                            SmmTable;                     ///< A pointer to the SMM table. Type SMM_TABLE is defined below.
    955   UINT32                            OsMemoryAbove1Mb;             ///< The amount of usable memory above 1 MB, i.e. E820 type 1 memory. This value can
    956                                                                   ///< differ from the value in EFI_TO_COMPATIBILITY16_INIT_TABLE as more
    957                                                                   ///< memory may have been discovered.
    958   UINT32                            UnconventionalDeviceTable;    ///< Information to boot off an unconventional device like a PARTIES partition. Type
    959                                                                   ///< UD_TABLE is defined below.
    960 } EFI_TO_COMPATIBILITY16_BOOT_TABLE;
    961 
    962 ///
    963 /// EFI_LEGACY_INSTALL_PCI_HANDLER
    964 ///
    965 typedef struct {
    966   UINT8                             PciBus;             ///< The PCI bus of the device.
    967   UINT8                             PciDeviceFun;       ///< The PCI device in bits 7:3 and function in bits 2:0.
    968   UINT8                             PciSegment;         ///< The PCI segment of the device.
    969   UINT8                             PciClass;           ///< The PCI class code of the device.
    970   UINT8                             PciSubclass;        ///< The PCI subclass code of the device.
    971   UINT8                             PciInterface;       ///< The PCI interface code of the device.
    972   //
    973   // Primary section
    974   //
    975   UINT8                             PrimaryIrq;         ///< The primary device IRQ.
    976   UINT8                             PrimaryReserved;    ///< Reserved.
    977   UINT16                            PrimaryControl;     ///< The primary device control I/O base.
    978   UINT16                            PrimaryBase;        ///< The primary device I/O base.
    979   UINT16                            PrimaryBusMaster;   ///< The primary device bus master I/O base.
    980   //
    981   // Secondary Section
    982   //
    983   UINT8                             SecondaryIrq;       ///< The secondary device IRQ.
    984   UINT8                             SecondaryReserved;  ///< Reserved.
    985   UINT16                            SecondaryControl;   ///< The secondary device control I/O base.
    986   UINT16                            SecondaryBase;      ///< The secondary device I/O base.
    987   UINT16                            SecondaryBusMaster; ///< The secondary device bus master I/O base.
    988 } EFI_LEGACY_INSTALL_PCI_HANDLER;
    989 
    990 //
    991 // Restore default pack value
    992 //
    993 #pragma pack()
    994 
    995 #define EFI_LEGACY_BIOS_PROTOCOL_GUID \
    996   { \
    997     0xdb9a1e3d, 0x45cb, 0x4abb, {0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d } \
    998   }
    999 
   1000 typedef struct _EFI_LEGACY_BIOS_PROTOCOL EFI_LEGACY_BIOS_PROTOCOL;
   1001 
   1002 ///
   1003 /// Flags returned by CheckPciRom().
   1004 ///
   1005 #define NO_ROM            0x00
   1006 #define ROM_FOUND         0x01
   1007 #define VALID_LEGACY_ROM  0x02
   1008 #define ROM_WITH_CONFIG   0x04     ///< Not defined in the Framework CSM Specification.
   1009 
   1010 ///
   1011 /// The following macros do not appear in the Framework CSM Specification and
   1012 /// are kept for backward compatibility only.  They convert 32-bit address (_Adr)
   1013 /// to Segment:Offset 16-bit form.
   1014 ///
   1015 ///@{
   1016 #define EFI_SEGMENT(_Adr)     (UINT16) ((UINT16) (((UINTN) (_Adr)) >> 4) & 0xf000)
   1017 #define EFI_OFFSET(_Adr)      (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xffff)
   1018 ///@}
   1019 
   1020 #define CARRY_FLAG            0x01
   1021 
   1022 ///
   1023 /// EFI_EFLAGS_REG
   1024 ///
   1025 typedef struct {
   1026   UINT32 CF:1;
   1027   UINT32 Reserved1:1;
   1028   UINT32 PF:1;
   1029   UINT32 Reserved2:1;
   1030   UINT32 AF:1;
   1031   UINT32 Reserved3:1;
   1032   UINT32 ZF:1;
   1033   UINT32 SF:1;
   1034   UINT32 TF:1;
   1035   UINT32 IF:1;
   1036   UINT32 DF:1;
   1037   UINT32 OF:1;
   1038   UINT32 IOPL:2;
   1039   UINT32 NT:1;
   1040   UINT32 Reserved4:2;
   1041   UINT32 VM:1;
   1042   UINT32 Reserved5:14;
   1043 } EFI_EFLAGS_REG;
   1044 
   1045 ///
   1046 /// EFI_DWORD_REGS
   1047 ///
   1048 typedef struct {
   1049     UINT32           EAX;
   1050     UINT32           EBX;
   1051     UINT32           ECX;
   1052     UINT32           EDX;
   1053     UINT32           ESI;
   1054     UINT32           EDI;
   1055     EFI_EFLAGS_REG   EFlags;
   1056     UINT16           ES;
   1057     UINT16           CS;
   1058     UINT16           SS;
   1059     UINT16           DS;
   1060     UINT16           FS;
   1061     UINT16           GS;
   1062     UINT32           EBP;
   1063     UINT32           ESP;
   1064 } EFI_DWORD_REGS;
   1065 
   1066 ///
   1067 /// EFI_FLAGS_REG
   1068 ///
   1069 typedef struct {
   1070   UINT16     CF:1;
   1071   UINT16     Reserved1:1;
   1072   UINT16     PF:1;
   1073   UINT16     Reserved2:1;
   1074   UINT16     AF:1;
   1075   UINT16     Reserved3:1;
   1076   UINT16     ZF:1;
   1077   UINT16     SF:1;
   1078   UINT16     TF:1;
   1079   UINT16     IF:1;
   1080   UINT16     DF:1;
   1081   UINT16     OF:1;
   1082   UINT16     IOPL:2;
   1083   UINT16     NT:1;
   1084   UINT16     Reserved4:1;
   1085 } EFI_FLAGS_REG;
   1086 
   1087 ///
   1088 /// EFI_WORD_REGS
   1089 ///
   1090 typedef struct {
   1091     UINT16           AX;
   1092     UINT16           ReservedAX;
   1093     UINT16           BX;
   1094     UINT16           ReservedBX;
   1095     UINT16           CX;
   1096     UINT16           ReservedCX;
   1097     UINT16           DX;
   1098     UINT16           ReservedDX;
   1099     UINT16           SI;
   1100     UINT16           ReservedSI;
   1101     UINT16           DI;
   1102     UINT16           ReservedDI;
   1103     EFI_FLAGS_REG    Flags;
   1104     UINT16           ReservedFlags;
   1105     UINT16           ES;
   1106     UINT16           CS;
   1107     UINT16           SS;
   1108     UINT16           DS;
   1109     UINT16           FS;
   1110     UINT16           GS;
   1111     UINT16           BP;
   1112     UINT16           ReservedBP;
   1113     UINT16           SP;
   1114     UINT16           ReservedSP;
   1115 } EFI_WORD_REGS;
   1116 
   1117 ///
   1118 /// EFI_BYTE_REGS
   1119 ///
   1120 typedef struct {
   1121     UINT8   AL, AH;
   1122     UINT16  ReservedAX;
   1123     UINT8   BL, BH;
   1124     UINT16  ReservedBX;
   1125     UINT8   CL, CH;
   1126     UINT16  ReservedCX;
   1127     UINT8   DL, DH;
   1128     UINT16  ReservedDX;
   1129 } EFI_BYTE_REGS;
   1130 
   1131 ///
   1132 /// EFI_IA32_REGISTER_SET
   1133 ///
   1134 typedef union {
   1135   EFI_DWORD_REGS  E;
   1136   EFI_WORD_REGS   X;
   1137   EFI_BYTE_REGS   H;
   1138 } EFI_IA32_REGISTER_SET;
   1139 
   1140 /**
   1141   Thunk to 16-bit real mode and execute a software interrupt with a vector
   1142   of BiosInt. Regs will contain the 16-bit register context on entry and
   1143   exit.
   1144 
   1145   @param[in]     This      The protocol instance pointer.
   1146   @param[in]     BiosInt   The processor interrupt vector to invoke.
   1147   @param[in,out] Reg       Register contexted passed into (and returned) from thunk to
   1148                            16-bit mode.
   1149 
   1150   @retval TRUE                Thunk completed with no BIOS errors in the target code. See Regs for status.
   1151   @retval FALSE                  There was a BIOS error in the target code.
   1152 **/
   1153 typedef
   1154 BOOLEAN
   1155 (EFIAPI *EFI_LEGACY_BIOS_INT86)(
   1156   IN     EFI_LEGACY_BIOS_PROTOCOL  *This,
   1157   IN     UINT8                     BiosInt,
   1158   IN OUT EFI_IA32_REGISTER_SET     *Regs
   1159   );
   1160 
   1161 /**
   1162   Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
   1163   16-bit register context on entry and exit. Arguments can be passed on
   1164   the Stack argument
   1165 
   1166   @param[in] This        The protocol instance pointer.
   1167   @param[in] Segment     The segemnt of 16-bit mode call.
   1168   @param[in] Offset      The offset of 16-bit mdoe call.
   1169   @param[in] Reg         Register contexted passed into (and returned) from thunk to
   1170                          16-bit mode.
   1171   @param[in] Stack       The caller allocated stack used to pass arguments.
   1172   @param[in] StackSize   The size of Stack in bytes.
   1173 
   1174   @retval FALSE                 Thunk completed with no BIOS errors in the target code.                                See Regs for status.  @retval TRUE                  There was a BIOS error in the target code.
   1175 **/
   1176 typedef
   1177 BOOLEAN
   1178 (EFIAPI *EFI_LEGACY_BIOS_FARCALL86)(
   1179   IN EFI_LEGACY_BIOS_PROTOCOL  *This,
   1180   IN UINT16                    Segment,
   1181   IN UINT16                    Offset,
   1182   IN EFI_IA32_REGISTER_SET     *Regs,
   1183   IN VOID                      *Stack,
   1184   IN UINTN                     StackSize
   1185   );
   1186 
   1187 /**
   1188   Test to see if a legacy PCI ROM exists for this device. Optionally return
   1189   the Legacy ROM instance for this PCI device.
   1190 
   1191   @param[in]  This        The protocol instance pointer.
   1192   @param[in]  PciHandle   The PCI PC-AT OPROM from this devices ROM BAR will be loaded
   1193   @param[out] RomImage    Return the legacy PCI ROM for this device.
   1194   @param[out] RomSize     The size of ROM Image.
   1195   @param[out] Flags       Indicates if ROM found and if PC-AT. Multiple bits can be set as follows:
   1196                             - 00 = No ROM.
   1197                             - 01 = ROM Found.
   1198                             - 02 = ROM is a valid legacy ROM.
   1199 
   1200   @retval EFI_SUCCESS       The Legacy Option ROM availible for this device
   1201   @retval EFI_UNSUPPORTED   The Legacy Option ROM is not supported.
   1202 
   1203 **/
   1204 typedef
   1205 EFI_STATUS
   1206 (EFIAPI *EFI_LEGACY_BIOS_CHECK_ROM)(
   1207   IN  EFI_LEGACY_BIOS_PROTOCOL  *This,
   1208   IN  EFI_HANDLE                PciHandle,
   1209   OUT VOID                      **RomImage, OPTIONAL
   1210   OUT UINTN                     *RomSize, OPTIONAL
   1211   OUT UINTN                     *Flags
   1212   );
   1213 
   1214 /**
   1215   Load a legacy PC-AT OPROM on the PciHandle device. Return information
   1216   about how many disks were added by the OPROM and the shadow address and
   1217   size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
   1218 
   1219   @param[in]  This               The protocol instance pointer.
   1220   @param[in]  PciHandle          The PCI PC-AT OPROM from this devices ROM BAR will be loaded.
   1221                                  This value is NULL if RomImage is non-NULL. This is the normal
   1222                                  case.
   1223   @param[in]  RomImage           A PCI PC-AT ROM image. This argument is non-NULL if there is
   1224                                  no hardware associated with the ROM and thus no PciHandle,
   1225                                  otherwise is must be NULL.
   1226                                  Example is PXE base code.
   1227   @param[out] Flags              The type of ROM discovered. Multiple bits can be set, as follows:
   1228                                    - 00 = No ROM.
   1229                                    - 01 = ROM found.
   1230                                    - 02 = ROM is a valid legacy ROM.
   1231   @param[out] DiskStart          The disk number of first device hooked by the ROM. If DiskStart
   1232                                  is the same as DiskEnd no disked were hooked.
   1233   @param[out] DiskEnd            disk number of the last device hooked by the ROM.
   1234   @param[out] RomShadowAddress   Shadow address of PC-AT ROM.
   1235   @param[out] RomShadowSize      Size of RomShadowAddress in bytes.
   1236 
   1237   @retval EFI_SUCCESS             Thunk completed, see Regs for status.
   1238   @retval EFI_INVALID_PARAMETER   PciHandle not found
   1239 
   1240 **/
   1241 typedef
   1242 EFI_STATUS
   1243 (EFIAPI *EFI_LEGACY_BIOS_INSTALL_ROM)(
   1244   IN  EFI_LEGACY_BIOS_PROTOCOL  *This,
   1245   IN  EFI_HANDLE                PciHandle,
   1246   IN  VOID                      **RomImage,
   1247   OUT UINTN                     *Flags,
   1248   OUT UINT8                     *DiskStart, OPTIONAL
   1249   OUT UINT8                     *DiskEnd, OPTIONAL
   1250   OUT VOID                      **RomShadowAddress, OPTIONAL
   1251   OUT UINT32                    *ShadowedRomSize OPTIONAL
   1252   );
   1253 
   1254 /**
   1255   This function attempts to traditionally boot the specified BootOption. If the EFI context has
   1256   been compromised, this function will not return. This procedure is not used for loading an EFI-aware
   1257   OS off a traditional device. The following actions occur:
   1258   - Get EFI SMBIOS data structures, convert them to a traditional format, and copy to
   1259     Compatibility16.
   1260   - Get a pointer to ACPI data structures and copy the Compatibility16 RSD PTR to F0000 block.
   1261   - Find the traditional SMI handler from a firmware volume and register the traditional SMI
   1262     handler with the EFI SMI handler.
   1263   - Build onboard IDE information and pass this information to the Compatibility16 code.
   1264   - Make sure all PCI Interrupt Line registers are programmed to match 8259.
   1265   - Reconfigure SIO devices from EFI mode (polled) into traditional mode (interrupt driven).
   1266   - Shadow all PCI ROMs.
   1267   - Set up BDA and EBDA standard areas before the legacy boot.
   1268   - Construct the Compatibility16 boot memory map and pass it to the Compatibility16 code.
   1269   - Invoke the Compatibility16 table function Compatibility16PrepareToBoot(). This
   1270     invocation causes a thunk into the Compatibility16 code, which sets all appropriate internal
   1271     data structures. The boot device list is a parameter.
   1272   - Invoke the Compatibility16 Table function Compatibility16Boot(). This invocation
   1273     causes a thunk into the Compatibility16 code, which does an INT19.
   1274   - If the Compatibility16Boot() function returns, then the boot failed in a graceful
   1275     manner--meaning that the EFI code is still valid. An ungraceful boot failure causes a reset because the state
   1276     of EFI code is unknown.
   1277 
   1278   @param[in] This             The protocol instance pointer.
   1279   @param[in] BootOption       The EFI Device Path from BootXXXX variable.
   1280   @param[in] LoadOptionSize   The size of LoadOption in size.
   1281   @param[in] LoadOption       LThe oadOption from BootXXXX variable.
   1282 
   1283   @retval EFI_DEVICE_ERROR      Failed to boot from any boot device and memory is uncorrupted.                                Note: This function normally does not returns. It will either boot the                                OS or reset the system if memory has been "corrupted" by loading                                a boot sector and passing control to it.
   1284 **/
   1285 typedef
   1286 EFI_STATUS
   1287 (EFIAPI *EFI_LEGACY_BIOS_BOOT)(
   1288   IN EFI_LEGACY_BIOS_PROTOCOL  *This,
   1289   IN BBS_BBS_DEVICE_PATH       *BootOption,
   1290   IN UINT32                    LoadOptionsSize,
   1291   IN VOID                      *LoadOptions
   1292   );
   1293 
   1294 /**
   1295   This function takes the Leds input parameter and sets/resets the BDA accordingly.
   1296   Leds is also passed to Compatibility16 code, in case any special processing is required.
   1297   This function is normally called from EFI Setup drivers that handle user-selectable
   1298   keyboard options such as boot with NUM LOCK on/off. This function does not
   1299   touch the keyboard or keyboard LEDs but only the BDA.
   1300 
   1301   @param[in] This   The protocol instance pointer.
   1302   @param[in] Leds   The status of current Scroll, Num & Cap lock LEDS:
   1303                       - Bit 0 is Scroll Lock 0 = Not locked.
   1304                       - Bit 1 is Num Lock.
   1305                       - Bit 2 is Caps Lock.
   1306 
   1307   @retval EFI_SUCCESS   The BDA was updated successfully.
   1308 
   1309 **/
   1310 typedef
   1311 EFI_STATUS
   1312 (EFIAPI *EFI_LEGACY_BIOS_UPDATE_KEYBOARD_LED_STATUS)(
   1313   IN EFI_LEGACY_BIOS_PROTOCOL  *This,
   1314   IN UINT8                     Leds
   1315   );
   1316 
   1317 /**
   1318   Retrieve legacy BBS info and assign boot priority.
   1319 
   1320   @param[in]     This       The protocol instance pointer.
   1321   @param[out]    HddCount   The number of HDD_INFO structures.
   1322   @param[out]    HddInfo    Onboard IDE controller information.
   1323   @param[out]    BbsCount   The number of BBS_TABLE structures.
   1324   @param[in,out] BbsTable   Points to List of BBS_TABLE.
   1325 
   1326   @retval EFI_SUCCESS   Tables were returned.
   1327 
   1328 **/
   1329 typedef
   1330 EFI_STATUS
   1331 (EFIAPI *EFI_LEGACY_BIOS_GET_BBS_INFO)(
   1332   IN     EFI_LEGACY_BIOS_PROTOCOL  *This,
   1333   OUT    UINT16                    *HddCount,
   1334   OUT    HDD_INFO                  **HddInfo,
   1335   OUT    UINT16                    *BbsCount,
   1336   IN OUT BBS_TABLE                 **BbsTable
   1337   );
   1338 
   1339 /**
   1340   Assign drive number to legacy HDD drives prior to booting an EFI
   1341   aware OS so the OS can access drives without an EFI driver.
   1342 
   1343   @param[in]  This       The protocol instance pointer.
   1344   @param[out] BbsCount   The number of BBS_TABLE structures
   1345   @param[out] BbsTable   List of BBS entries
   1346 
   1347   @retval EFI_SUCCESS   Drive numbers assigned.
   1348 
   1349 **/
   1350 typedef
   1351 EFI_STATUS
   1352 (EFIAPI *EFI_LEGACY_BIOS_PREPARE_TO_BOOT_EFI)(
   1353   IN  EFI_LEGACY_BIOS_PROTOCOL  *This,
   1354   OUT UINT16                    *BbsCount,
   1355   OUT BBS_TABLE                 **BbsTable
   1356   );
   1357 
   1358 /**
   1359   To boot from an unconventional device like parties and/or execute
   1360   HDD diagnostics.
   1361 
   1362   @param[in]  This              The protocol instance pointer.
   1363   @param[in]  Attributes        How to interpret the other input parameters.
   1364   @param[in]  BbsEntry          The 0-based index into the BbsTable for the parent
   1365                                 device.
   1366   @param[in]  BeerData          A pointer to the 128 bytes of ram BEER data.
   1367   @param[in]  ServiceAreaData   A pointer to the 64 bytes of raw Service Area data. The
   1368                                 caller must provide a pointer to the specific Service
   1369                                 Area and not the start all Service Areas.
   1370 
   1371   @retval EFI_INVALID_PARAMETER   If error. Does NOT return if no error.
   1372 
   1373 **/
   1374 typedef
   1375 EFI_STATUS
   1376 (EFIAPI *EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE)(
   1377   IN EFI_LEGACY_BIOS_PROTOCOL  *This,
   1378   IN UDC_ATTRIBUTES            Attributes,
   1379   IN UINTN                     BbsEntry,
   1380   IN VOID                      *BeerData,
   1381   IN VOID                      *ServiceAreaData
   1382   );
   1383 
   1384 /**
   1385   Shadow all legacy16 OPROMs that haven't been shadowed.
   1386   Warning: Use this with caution. This routine disconnects all EFI
   1387   drivers. If used externally, then  the caller must re-connect EFI
   1388   drivers.
   1389 
   1390   @param[in]  This   The protocol instance pointer.
   1391 
   1392   @retval EFI_SUCCESS   OPROMs were shadowed.
   1393 
   1394 **/
   1395 typedef
   1396 EFI_STATUS
   1397 (EFIAPI *EFI_LEGACY_BIOS_SHADOW_ALL_LEGACY_OPROMS)(
   1398   IN EFI_LEGACY_BIOS_PROTOCOL  *This
   1399   );
   1400 
   1401 /**
   1402   Get a region from the LegacyBios for S3 usage.
   1403 
   1404   @param[in]  This                  The protocol instance pointer.
   1405   @param[in]  LegacyMemorySize      The size of required region.
   1406   @param[in]  Region                The region to use.
   1407                                     00 = Either 0xE0000 or 0xF0000 block.
   1408                                       - Bit0 = 1 0xF0000 block.
   1409                                       - Bit1 = 1 0xE0000 block.
   1410   @param[in]  Alignment             Address alignment. Bit mapped. The first non-zero
   1411                                     bit from right is alignment.
   1412   @param[out] LegacyMemoryAddress   The Region Assigned
   1413 
   1414   @retval EFI_SUCCESS           The Region was assigned.
   1415   @retval EFI_ACCESS_DENIED     The function was previously invoked.
   1416   @retval Other                 The Region was not assigned.
   1417 
   1418 **/
   1419 typedef
   1420 EFI_STATUS
   1421 (EFIAPI *EFI_LEGACY_BIOS_GET_LEGACY_REGION)(
   1422   IN  EFI_LEGACY_BIOS_PROTOCOL  *This,
   1423   IN  UINTN                     LegacyMemorySize,
   1424   IN  UINTN                     Region,
   1425   IN  UINTN                     Alignment,
   1426   OUT VOID                      **LegacyMemoryAddress
   1427   );
   1428 
   1429 /**
   1430   Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
   1431 
   1432   @param[in]  This                        The protocol instance pointer.
   1433   @param[in]  LegacyMemorySize            The size of data to copy.
   1434   @param[in]  LegacyMemoryAddress         The Legacy Region destination address.
   1435                                           Note: must be in region assigned by
   1436                                           LegacyBiosGetLegacyRegion.
   1437   @param[in]  LegacyMemorySourceAddress   The source of the data to copy.
   1438 
   1439   @retval EFI_SUCCESS           The Region assigned.
   1440   @retval EFI_ACCESS_DENIED     Destination was outside an assigned region.
   1441 
   1442 **/
   1443 typedef
   1444 EFI_STATUS
   1445 (EFIAPI *EFI_LEGACY_BIOS_COPY_LEGACY_REGION)(
   1446   IN EFI_LEGACY_BIOS_PROTOCOL  *This,
   1447   IN UINTN                     LegacyMemorySize,
   1448   IN VOID                      *LegacyMemoryAddress,
   1449   IN VOID                      *LegacyMemorySourceAddress
   1450   );
   1451 
   1452 ///
   1453 /// Abstracts the traditional BIOS from the rest of EFI. The LegacyBoot()
   1454 /// member function allows the BDS to support booting a traditional OS.
   1455 /// EFI thunks drivers that make EFI bindings for BIOS INT services use
   1456 /// all the other member functions.
   1457 ///
   1458 struct _EFI_LEGACY_BIOS_PROTOCOL {
   1459   ///
   1460   /// Performs traditional software INT. See the Int86() function description.
   1461   ///
   1462   EFI_LEGACY_BIOS_INT86                       Int86;
   1463 
   1464   ///
   1465   /// Performs a far call into Compatibility16 or traditional OpROM code.
   1466   ///
   1467   EFI_LEGACY_BIOS_FARCALL86                   FarCall86;
   1468 
   1469   ///
   1470   /// Checks if a traditional OpROM exists for this device.
   1471   ///
   1472   EFI_LEGACY_BIOS_CHECK_ROM                   CheckPciRom;
   1473 
   1474   ///
   1475   /// Loads a traditional OpROM in traditional OpROM address space.
   1476   ///
   1477   EFI_LEGACY_BIOS_INSTALL_ROM                 InstallPciRom;
   1478 
   1479   ///
   1480   /// Boots a traditional OS.
   1481   ///
   1482   EFI_LEGACY_BIOS_BOOT                        LegacyBoot;
   1483 
   1484   ///
   1485   /// Updates BDA to reflect the current EFI keyboard LED status.
   1486   ///
   1487   EFI_LEGACY_BIOS_UPDATE_KEYBOARD_LED_STATUS  UpdateKeyboardLedStatus;
   1488 
   1489   ///
   1490   /// Allows an external agent, such as BIOS Setup, to get the BBS data.
   1491   ///
   1492   EFI_LEGACY_BIOS_GET_BBS_INFO                GetBbsInfo;
   1493 
   1494   ///
   1495   /// Causes all legacy OpROMs to be shadowed.
   1496   ///
   1497   EFI_LEGACY_BIOS_SHADOW_ALL_LEGACY_OPROMS    ShadowAllLegacyOproms;
   1498 
   1499   ///
   1500   /// Performs all actions prior to boot. Used when booting an EFI-aware OS
   1501   /// rather than a legacy OS.
   1502   ///
   1503   EFI_LEGACY_BIOS_PREPARE_TO_BOOT_EFI         PrepareToBootEfi;
   1504 
   1505   ///
   1506   /// Allows EFI to reserve an area in the 0xE0000 or 0xF0000 block.
   1507   ///
   1508   EFI_LEGACY_BIOS_GET_LEGACY_REGION           GetLegacyRegion;
   1509 
   1510   ///
   1511   /// Allows EFI to copy data to the area specified by GetLegacyRegion.
   1512   ///
   1513   EFI_LEGACY_BIOS_COPY_LEGACY_REGION          CopyLegacyRegion;
   1514 
   1515   ///
   1516   /// Allows the user to boot off an unconventional device such as a PARTIES partition.
   1517   ///
   1518   EFI_LEGACY_BIOS_BOOT_UNCONVENTIONAL_DEVICE  BootUnconventionalDevice;
   1519 };
   1520 
   1521 extern EFI_GUID gEfiLegacyBiosProtocolGuid;
   1522 
   1523 #endif
   1524