3 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The
8 full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _LEGACY_BIOS_INTERFACE_
17 #define _LEGACY_BIOS_INTERFACE_
20 #include <FrameworkDxe.h>
21 #include <IndustryStandard/Pci.h>
22 #include <IndustryStandard/SmBios.h>
23 #include <IndustryStandard/Acpi10.h>
25 #include <Guid/SmBios.h>
26 #include <Guid/Acpi.h>
27 #include <Guid/DxeServices.h>
28 #include <Guid/LegacyBios.h>
29 #include <Guid/StatusCodeDataTypeId.h>
30 #include <Guid/ImageAuthentication.h>
32 #include <Protocol/BlockIo.h>
33 #include <Protocol/LoadedImage.h>
34 #include <Protocol/PciIo.h>
35 #include <Protocol/Cpu.h>
36 #include <Protocol/Timer.h>
37 #include <Protocol/IsaIo.h>
38 #include <Protocol/LegacyRegion2.h>
39 #include <Protocol/SimpleTextIn.h>
40 #include <Protocol/LegacyInterrupt.h>
41 #include <Protocol/LegacyBios.h>
42 #include <Protocol/DiskInfo.h>
43 #include <Protocol/GenericMemoryTest.h>
44 #include <Protocol/LegacyBiosPlatform.h>
45 #include <Protocol/DevicePath.h>
46 #include <Protocol/Legacy8259.h>
47 #include <Protocol/PciRootBridgeIo.h>
48 #include <Protocol/SerialIo.h>
49 #include <Protocol/SuperIo.h>
50 #include <Protocol/IoMmu.h>
52 #include <Library/BaseLib.h>
53 #include <Library/DebugLib.h>
54 #include <Library/UefiLib.h>
55 #include <Library/BaseMemoryLib.h>
56 #include <Library/ReportStatusCodeLib.h>
57 #include <Library/UefiRuntimeServicesTableLib.h>
58 #include <Library/HobLib.h>
59 #include <Library/UefiDriverEntryPoint.h>
60 #include <Library/MemoryAllocationLib.h>
61 #include <Library/UefiBootServicesTableLib.h>
62 #include <Library/IoLib.h>
63 #include <Library/PcdLib.h>
64 #include <Library/DevicePathLib.h>
65 #include <Library/DxeServicesTableLib.h>
66 #include <Library/PeCoffLib.h>
67 #include <Library/CacheMaintenanceLib.h>
68 #include <Library/DebugAgentLib.h>
71 // BUGBUG: This entry maybe changed to PCD in future and wait for
72 // redesign of BDS library
74 #define MAX_BBS_ENTRIES 0x100
78 // (These apply only to errors with the thunk and not to the code that was
82 #define THUNK_ERR_A20_UNSUP 0x01
83 #define THUNK_ERR_A20_FAILED 0x02
86 // Vector base definitions
89 // 8259 Hardware definitions
91 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
92 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
95 // The original PC used INT8-F for master PIC. Since these mapped over
96 // processor exceptions TIANO moved the master PIC to INT68-6F.
98 // The vector base for slave PIC is set as 0x70 for PC-AT compatibility.
100 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
101 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
104 // When we call CSM16 functions, some CSM16 use es:[offset + 0xabcd] to get data passed from CSM32,
105 // offset + 0xabcd could overflow which exceeds 0xFFFF which is invalid in real mode.
106 // So this will keep offset as small as possible to avoid offset overflow in real mode.
108 #define NORMALIZE_EFI_SEGMENT(_Adr) (UINT16) (((UINTN) (_Adr)) >> 4)
109 #define NORMALIZE_EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xf)
115 #define LEGACY_BDA_TRACE 0x000
116 #define LEGACY_BIOS_TRACE 0x040
117 #define LEGACY_BOOT_TRACE 0x080
118 #define LEGACY_CMOS_TRACE 0x0C0
119 #define LEGACY_IDE_TRACE 0x100
120 #define LEGACY_MP_TRACE 0x140
121 #define LEGACY_PCI_TRACE 0x180
122 #define LEGACY_SIO_TRACE 0x1C0
124 #define LEGACY_PCI_TRACE_000 LEGACY_PCI_TRACE + 0x00
125 #define LEGACY_PCI_TRACE_001 LEGACY_PCI_TRACE + 0x01
126 #define LEGACY_PCI_TRACE_002 LEGACY_PCI_TRACE + 0x02
127 #define LEGACY_PCI_TRACE_003 LEGACY_PCI_TRACE + 0x03
128 #define LEGACY_PCI_TRACE_004 LEGACY_PCI_TRACE + 0x04
129 #define LEGACY_PCI_TRACE_005 LEGACY_PCI_TRACE + 0x05
130 #define LEGACY_PCI_TRACE_006 LEGACY_PCI_TRACE + 0x06
131 #define LEGACY_PCI_TRACE_007 LEGACY_PCI_TRACE + 0x07
132 #define LEGACY_PCI_TRACE_008 LEGACY_PCI_TRACE + 0x08
133 #define LEGACY_PCI_TRACE_009 LEGACY_PCI_TRACE + 0x09
134 #define LEGACY_PCI_TRACE_00A LEGACY_PCI_TRACE + 0x0A
135 #define LEGACY_PCI_TRACE_00B LEGACY_PCI_TRACE + 0x0B
136 #define LEGACY_PCI_TRACE_00C LEGACY_PCI_TRACE + 0x0C
137 #define LEGACY_PCI_TRACE_00D LEGACY_PCI_TRACE + 0x0D
138 #define LEGACY_PCI_TRACE_00E LEGACY_PCI_TRACE + 0x0E
139 #define LEGACY_PCI_TRACE_00F LEGACY_PCI_TRACE + 0x0F
141 #define BDA_VIDEO_MODE 0x49
143 #define IDE_PI_REGISTER_PNE BIT0
144 #define IDE_PI_REGISTER_SNE BIT2
151 UINT32 ShadowAddress
;
155 } ROM_INSTANCE_ENTRY
;
158 // Values for RealModeGdt
160 #if defined (MDE_CPU_IA32)
162 #define NUM_REAL_GDT_ENTRIES 3
163 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
164 #define INITIAL_VALUE_BELOW_1K 0x0
166 #elif defined (MDE_CPU_X64)
168 #define NUM_REAL_GDT_ENTRIES 8
169 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
170 #define INITIAL_VALUE_BELOW_1K 0x0
172 #elif defined (MDE_CPU_IPF)
174 #define NUM_REAL_GDT_ENTRIES 3
175 #define CONVENTIONAL_MEMORY_TOP 0x80000 // 512 KB
176 #define INITIAL_VALUE_BELOW_1K 0xff
183 // Define what a processor GDT looks like
196 UINT32 DefaultSize
: 1;
197 UINT32 Granularity
: 1;
211 // Define what a processor descriptor looks like
212 // This data structure must be kept in sync with ASM STRUCT in Thunk.inc
227 #define LOW_STACK_SIZE (8 * 1024) // 8k?
228 #define EFI_MAX_E820_ENTRY 100
229 #define FIRST_INSTANCE 1
230 #define NOT_FIRST_INSTANCE 0
232 #if defined (MDE_CPU_IA32)
235 // Space for the code
236 // The address of Code is also the beginning of the relocated Thunk code
238 CHAR8 Code
[4096]; // ?
240 // The address of the Reverse Thunk code
241 // Note that this member CONTAINS the address of the relocated reverse thunk
242 // code unlike the member variable 'Code', which IS the address of the Thunk
245 UINT32 LowReverseThunkStart
;
248 // Data for the code (cs releative)
250 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
251 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
255 UINT32 LowCodeSelector
; // Low code selector in GDT
256 UINT32 LowDataSelector
; // Low data selector in GDT
258 DESCRIPTOR32 RealModeIdtDesc
;
261 // real-mode GDT (temporary GDT with two real mode segment descriptors)
263 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
264 DESCRIPTOR32 RealModeGdtDesc
;
267 // Members specifically for the reverse thunk
268 // The RevReal* members are used to store the current state of real mode
269 // before performing the reverse thunk. The RevFlat* members must be set
270 // before calling the reverse thunk assembly code.
275 DESCRIPTOR32 RevRealIdtDesc
;
276 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
280 // A low memory stack
282 CHAR8 Stack
[LOW_STACK_SIZE
];
285 // Stack for flat mode after reverse thunk
286 // @bug - This may no longer be necessary if the reverse thunk interface
287 // is changed to have the flat stack in a different location.
289 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
292 // Legacy16 Init memory map info
294 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
296 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
298 CHAR8 InterruptRedirectionCode
[32];
299 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
300 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
301 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
304 #elif defined (MDE_CPU_X64)
308 // Space for the code
309 // The address of Code is also the beginning of the relocated Thunk code
311 CHAR8 Code
[4096]; // ?
314 // Data for the code (cs releative)
316 DESCRIPTOR64 X64GdtDesc
; // Protected mode GDT
317 DESCRIPTOR64 X64IdtDesc
; // Protected mode IDT
322 DESCRIPTOR32 RealModeIdtDesc
;
323 DESCRIPTOR32 RealModeGdtDesc
;
326 // real-mode GDT (temporary GDT with two real mode segment descriptors)
328 GDT64 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
329 UINT64 PageMapLevel4
;
332 // A low memory stack
334 CHAR8 Stack
[LOW_STACK_SIZE
];
337 // Legacy16 Init memory map info
339 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
341 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
343 CHAR8 InterruptRedirectionCode
[32];
344 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
345 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
346 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
349 #elif defined (MDE_CPU_IPF)
353 // Space for the code
354 // The address of Code is also the beginning of the relocated Thunk code
356 CHAR8 Code
[4096]; // ?
358 // The address of the Reverse Thunk code
359 // Note that this member CONTAINS the address of the relocated reverse thunk
360 // code unlike the member variable 'Code', which IS the address of the Thunk
363 UINT32 LowReverseThunkStart
;
366 // Data for the code (cs releative)
368 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
369 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
373 UINT32 LowCodeSelector
; // Low code selector in GDT
374 UINT32 LowDataSelector
; // Low data selector in GDT
376 DESCRIPTOR32 RealModeIdtDesc
;
379 // real-mode GDT (temporary GDT with two real mode segment descriptors)
381 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
382 DESCRIPTOR32 RealModeGdtDesc
;
385 // Members specifically for the reverse thunk
386 // The RevReal* members are used to store the current state of real mode
387 // before performing the reverse thunk. The RevFlat* members must be set
388 // before calling the reverse thunk assembly code.
393 DESCRIPTOR32 RevRealIdtDesc
;
394 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
398 // A low memory stack
400 CHAR8 Stack
[LOW_STACK_SIZE
];
403 // Stack for flat mode after reverse thunk
404 // @bug - This may no longer be necessary if the reverse thunk interface
405 // is changed to have the flat stack in a different location.
407 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
410 // Legacy16 Init memory map info
412 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
414 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
416 CHAR8 InterruptRedirectionCode
[32];
417 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
418 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
419 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
425 // PnP Expansion Header
436 UINT16 ProductNamePointer
;
440 UINT8 DeviceIndicators
;
442 UINT16 DisconnectVector
;
445 UINT16 StaticResourceVector
;
446 } LEGACY_PNP_EXPANSION_HEADER
;
462 UINTN ManufacturerString
;
463 UINTN ProductNameString
;
464 } LEGACY_ROM_AND_BBS_TABLE
;
467 // Structure how EFI has mapped a devices HDD drive numbers.
468 // Boot to EFI aware OS or shell requires this mapping when
469 // 16-bit CSM assigns drive numbers.
470 // This mapping is ignored booting to a legacy OS.
477 UINT8 StartDriveNumber
;
478 UINT8 EndDriveNumber
;
479 } LEGACY_EFI_HDD_TABLE
;
482 // This data is passed to Leacy16Boot
485 EfiAcpiAddressRangeMemory
= 1,
486 EfiAcpiAddressRangeReserved
= 2,
487 EfiAcpiAddressRangeACPI
= 3,
488 EfiAcpiAddressRangeNVS
= 4,
489 EfiAddressRangePersistentMemory
= 7
490 } EFI_ACPI_MEMORY_TYPE
;
495 EFI_ACPI_MEMORY_TYPE Type
;
503 EFI_ACPI_MEMORY_TYPE Type
;
508 extern BBS_TABLE
*mBbsTable
;
510 extern EFI_GENERIC_MEMORY_TEST_PROTOCOL
*gGenMemoryTest
;
515 #define CMOS_0A 0x0a ///< Status register A
516 #define CMOS_0D 0x0d ///< Status register D
517 #define CMOS_0E 0x0e ///< Diagnostic Status
518 #define CMOS_0F 0x0f ///< Shutdown status
519 #define CMOS_10 0x10 ///< Floppy type
520 #define CMOS_12 0x12 ///< IDE type
521 #define CMOS_14 0x14 ///< Same as BDA 40:10
522 #define CMOS_15 0x15 ///< Low byte of base memory in 1k increments
523 #define CMOS_16 0x16 ///< High byte of base memory in 1k increments
524 #define CMOS_17 0x17 ///< Low byte of 1MB+ memory in 1k increments - max 15 MB
525 #define CMOS_18 0x18 ///< High byte of 1MB+ memory in 1k increments - max 15 MB
526 #define CMOS_19 0x19 ///< C: extended drive type
527 #define CMOS_1A 0x1a ///< D: extended drive type
528 #define CMOS_2E 0x2e ///< Most significient byte of standard checksum
529 #define CMOS_2F 0x2f ///< Least significient byte of standard checksum
530 #define CMOS_30 0x30 ///< CMOS 0x17
531 #define CMOS_31 0x31 ///< CMOS 0x18
532 #define CMOS_32 0x32 ///< Century byte
535 // 8254 Timer registers
537 #define TIMER0_COUNT_PORT 0x40
538 #define TIMER1_COUNT_PORT 0x41
539 #define TIMER2_COUNT_PORT 0x42
540 #define TIMER_CONTROL_PORT 0x43
543 // Timer 0, Read/Write LSB then MSB, Square wave output, binary count use.
545 #define TIMER0_CONTROL_WORD 0x36
547 #define LEGACY_BIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('L', 'B', 'I', 'T')
552 EFI_LEGACY_BIOS_PROTOCOL LegacyBios
;
554 EFI_HANDLE ImageHandle
;
557 // CPU Architectural Protocol
559 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
562 // Timer Architectural Protocol
564 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
565 BOOLEAN TimerUses8254
;
568 // Protocol to Lock and Unlock 0xc0000 - 0xfffff
570 EFI_LEGACY_REGION2_PROTOCOL
*LegacyRegion
;
572 EFI_LEGACY_BIOS_PLATFORM_PROTOCOL
*LegacyBiosPlatform
;
575 // Interrupt control for thunk and PCI IRQ
577 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
580 // PCI Interrupt PIRQ control
582 EFI_LEGACY_INTERRUPT_PROTOCOL
*LegacyInterrupt
;
585 // Generic Memory Test
587 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenericMemoryTest
;
590 // TRUE if PCI Interupt Line registers have been programmed.
592 BOOLEAN PciInterruptLine
;
595 // Code space below 1MB needed by thunker to transition to real mode.
596 // Contains stack and real mode code fragments
598 LOW_MEMORY_THUNK
*IntThunk
;
601 // Starting shadow address of the Legacy BIOS
604 UINT32 LegacyBiosImageSize
;
607 // Start of variables used by CsmItp.mac ITP macro file and/os LegacyBios
612 // $EFI Legacy16 code entry info in memory < 1 MB;
614 EFI_COMPATIBILITY16_TABLE
*Legacy16Table
;
615 VOID
*Legacy16InitPtr
;
616 VOID
*Legacy16BootPtr
;
617 VOID
*InternalIrqRoutingTable
;
618 UINT32 NumberIrqRoutingEntries
;
621 UINT32 NumberHddControllers
;
624 // Cached copy of Legacy16 entry point
626 UINT16 Legacy16CallSegment
;
627 UINT16 Legacy16CallOffset
;
630 // Returned from $EFI and passed in to OPROMS
632 UINT16 PnPInstallationCheckSegment
;
633 UINT16 PnPInstallationCheckOffset
;
638 EFI_E820_ENTRY E820Table
[EFI_MAX_E820_ENTRY
];
639 UINT32 NumberE820Entries
;
642 // True if legacy VGA INT 10h handler installed
644 BOOLEAN VgaInstalled
;
647 // Number of IDE drives
652 // Current Free Option ROM space. An option ROM must NOT go past
658 // Save Legacy16 unexpected interrupt vector. Reprogram INT 68-6F from
659 // EFI values to legacy value just before boot.
661 UINT32 BiosUnexpectedInt
;
662 UINT32 ThunkSavedInt
[8];
664 LEGACY_EFI_HDD_TABLE
*LegacyEfiHddTable
;
665 UINT16 LegacyEfiHddTableIndex
;
672 // Indicate that whether GenericLegacyBoot is entered or not
674 BOOLEAN LegacyBootEntered
;
677 // CSM16 PCI Interface Version
679 UINT16 Csm16PciInterfaceVersion
;
681 } LEGACY_BIOS_INSTANCE
;
694 40:0E-0E Ebda segment
695 40:10-11 MachineConfig
697 40:13-14 MemSize below 1MB
698 40:15-16 Bda15_16 - skip
699 40:17 Keyboard Shift status
700 40:18-19 Bda18_19 - skip
701 40:1A-1B Key buffer head
702 40:1C-1D Key buffer tail
703 40:1E-3D Bda1E_3D- key buffer -skip
704 40:3E-3F FloppyData 3E = Calibration status 3F = Motor status
706 40:41-74 Bda41_74 - skip
707 40:75 Number of HDD drives
708 40:76-77 Bda76_77 - skip
709 40:78-79 78 = Lpt1 timeout, 79 = Lpt2 timeout
710 40:7A-7B 7A = Lpt3 timeout, 7B = Lpt4 timeout
711 40:7C-7D 7C = Com1 timeout, 7D = Com2 timeout
712 40:7E-7F 7E = Com3 timeout, 7F = Com4 timeout
713 40:80-81 Pointer to start of key buffer
714 40:82-83 Pointer to end of key buffer
715 40:84-87 Bda84_87 - skip
716 40:88 HDD Data Xmit rate
718 40:90 Floppy data rate
720 40:96 Keyboard Status
733 UINT16 MachineConfig
;
736 UINT8 Bda15_16
[0x02];
738 UINT8 Bda18_19
[0x02];
741 UINT16 Bda1E_3D
[0x10];
744 UINT8 Bda41_74
[0x34];
745 UINT8 NumberOfDrives
;
746 UINT8 Bda76_77
[0x02];
747 UINT16 Lpt1_2Timeout
;
748 UINT16 Lpt3_4Timeout
;
749 UINT16 Com1_2Timeout
;
750 UINT16 Com3_4Timeout
;
755 UINT8 Bda89_8F
[0x07];
757 UINT8 Bda91_95
[0x05];
758 UINT8 KeyboardStatus
;
763 #define LEGACY_BIOS_INSTANCE_FROM_THIS(this) CR (this, LEGACY_BIOS_INSTANCE, LegacyBios, LEGACY_BIOS_INSTANCE_SIGNATURE)
766 Thunk to 16-bit real mode and execute a software interrupt with a vector
767 of BiosInt. Regs will contain the 16-bit register context on entry and
770 @param This Protocol instance pointer.
771 @param BiosInt Processor interrupt vector to invoke
772 @param Regs Register contexted passed into (and returned) from thunk to
775 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
777 @retval TRUE There was a BIOS erro in the target code.
783 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
785 IN EFI_IA32_REGISTER_SET
*Regs
790 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
791 16-bit register context on entry and exit. Arguments can be passed on
794 @param This Protocol instance pointer.
795 @param Segment Segemnt of 16-bit mode call
796 @param Offset Offset of 16-bit mdoe call
797 @param Regs Register contexted passed into (and returned) from
799 @param Stack Caller allocated stack used to pass arguments
800 @param StackSize Size of Stack in bytes
802 @retval FALSE Thunk completed, and there were no BIOS errors in
803 the target code. See Regs for status.
804 @retval TRUE There was a BIOS erro in the target code.
809 LegacyBiosFarCall86 (
810 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
813 IN EFI_IA32_REGISTER_SET
*Regs
,
820 Test to see if a legacy PCI ROM exists for this device. Optionally return
821 the Legacy ROM instance for this PCI device.
823 @param This Protocol instance pointer.
824 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
826 @param RomImage Return the legacy PCI ROM for this device
827 @param RomSize Size of ROM Image
828 @param Flags Indicates if ROM found and if PC-AT.
830 @retval EFI_SUCCESS Legacy Option ROM available for this device
831 @retval EFI_UNSUPPORTED Legacy Option ROM not supported.
836 LegacyBiosCheckPciRom (
837 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
838 IN EFI_HANDLE PciHandle
,
839 OUT VOID
**RomImage
, OPTIONAL
840 OUT UINTN
*RomSize
, OPTIONAL
846 Assign drive number to legacy HDD drives prior to booting an EFI
847 aware OS so the OS can access drives without an EFI driver.
848 Note: BBS compliant drives ARE NOT available until this call by
851 @param This Protocol instance pointer.
852 @param BbsCount Number of BBS_TABLE structures
853 @param BbsTable List BBS entries
855 @retval EFI_SUCCESS Drive numbers assigned
860 LegacyBiosPrepareToBootEfi (
861 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
862 OUT UINT16
*BbsCount
,
863 OUT BBS_TABLE
**BbsTable
868 To boot from an unconventional device like parties and/or execute
871 @param This Protocol instance pointer.
872 @param Attributes How to interpret the other input parameters
873 @param BbsEntry The 0-based index into the BbsTable for the parent
875 @param BeerData Pointer to the 128 bytes of ram BEER data.
876 @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
877 The caller must provide a pointer to the specific
878 Service Area and not the start all Service Areas.
879 EFI_INVALID_PARAMETER if error. Does NOT return if no error.
884 LegacyBiosBootUnconventionalDevice (
885 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
886 IN UDC_ATTRIBUTES Attributes
,
889 IN VOID
*ServiceAreaData
894 Load a legacy PC-AT OPROM on the PciHandle device. Return information
895 about how many disks were added by the OPROM and the shadow address and
896 size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
898 @param This Protocol instance pointer.
899 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
900 be loaded. This value is NULL if RomImage is
901 non-NULL. This is the normal case.
902 @param RomImage A PCI PC-AT ROM image. This argument is non-NULL
903 if there is no hardware associated with the ROM
904 and thus no PciHandle, otherwise is must be NULL.
905 Example is PXE base code.
906 @param Flags Indicates if ROM found and if PC-AT.
907 @param DiskStart Disk number of first device hooked by the ROM. If
908 DiskStart is the same as DiskEnd no disked were
910 @param DiskEnd Disk number of the last device hooked by the ROM.
911 @param RomShadowAddress Shadow address of PC-AT ROM
912 @param RomShadowedSize Size of RomShadowAddress in bytes
914 @retval EFI_SUCCESS Legacy ROM loaded for this device
915 @retval EFI_INVALID_PARAMETER PciHandle not found
916 @retval EFI_UNSUPPORTED There is no PCI ROM in the ROM BAR or no onboard
922 LegacyBiosInstallPciRom (
923 IN EFI_LEGACY_BIOS_PROTOCOL
* This
,
924 IN EFI_HANDLE PciHandle
,
927 OUT UINT8
*DiskStart
, OPTIONAL
928 OUT UINT8
*DiskEnd
, OPTIONAL
929 OUT VOID
**RomShadowAddress
, OPTIONAL
930 OUT UINT32
*RomShadowedSize OPTIONAL
935 Fill in the standard BDA for Keyboard LEDs
937 @param This Protocol instance pointer.
938 @param Leds Current LED status
940 @retval EFI_SUCCESS It should always work.
945 LegacyBiosUpdateKeyboardLedStatus (
946 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
954 @param This Protocol instance pointer.
955 @param HddCount Number of HDD_INFO structures
956 @param HddInfo Onboard IDE controller information
957 @param BbsCount Number of BBS_TABLE structures
958 @param BbsTable List BBS entries
960 @retval EFI_SUCCESS Tables returned
961 @retval EFI_NOT_FOUND resource not found
962 @retval EFI_DEVICE_ERROR can not get BBS table
967 LegacyBiosGetBbsInfo (
968 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
969 OUT UINT16
*HddCount
,
970 OUT HDD_INFO
**HddInfo
,
971 OUT UINT16
*BbsCount
,
972 OUT BBS_TABLE
**BbsTable
977 Shadow all legacy16 OPROMs that haven't been shadowed.
978 Warning: Use this with caution. This routine disconnects all EFI
979 drivers. If used externally then caller must re-connect EFI
982 @param This Protocol instance pointer.
984 @retval EFI_SUCCESS OPROMs shadowed
989 LegacyBiosShadowAllLegacyOproms (
990 IN EFI_LEGACY_BIOS_PROTOCOL
*This
995 Attempt to legacy boot the BootOption. If the EFI contexted has been
996 compromised this function will not return.
998 @param This Protocol instance pointer.
999 @param BbsDevicePath EFI Device Path from BootXXXX variable.
1000 @param LoadOptionsSize Size of LoadOption in size.
1001 @param LoadOptions LoadOption from BootXXXX variable
1003 @retval EFI_SUCCESS Removable media not present
1008 LegacyBiosLegacyBoot (
1009 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1010 IN BBS_BBS_DEVICE_PATH
*BbsDevicePath
,
1011 IN UINT32 LoadOptionsSize
,
1012 IN VOID
*LoadOptions
1017 Allocate memory < 1 MB and copy the thunker code into low memory. Se up
1018 all the descriptors.
1020 @param Private Private context for Legacy BIOS
1022 @retval EFI_SUCCESS Should only pass.
1026 LegacyBiosInitializeThunk (
1027 IN LEGACY_BIOS_INSTANCE
*Private
1032 Fill in the standard BDA and EBDA stuff before Legacy16 load
1034 @param Private Legacy BIOS Instance data
1036 @retval EFI_SUCCESS It should always work.
1041 IN LEGACY_BIOS_INSTANCE
*Private
1046 Collect IDE Inquiry data from the IDE disks
1048 @param Private Legacy BIOS Instance data
1049 @param HddInfo Hdd Information
1050 @param Flag Reconnect IdeController or not
1052 @retval EFI_SUCCESS It should always work.
1056 LegacyBiosBuildIdeData (
1057 IN LEGACY_BIOS_INSTANCE
*Private
,
1058 IN HDD_INFO
**HddInfo
,
1064 Enable ide controller. This gets disabled when LegacyBoot.c is about
1065 to run the Option ROMs.
1067 @param Private Legacy BIOS Instance data
1072 EnableIdeController (
1073 IN LEGACY_BIOS_INSTANCE
*Private
1078 If the IDE channel is in compatibility (legacy) mode, remove all
1079 PCI I/O BAR addresses from the controller.
1081 @param IdeController The handle of target IDE controller
1086 InitLegacyIdeController (
1087 IN EFI_HANDLE IdeController
1092 Program the interrupt routing register in all the PCI devices. On a PC AT system
1093 this register contains the 8259 IRQ vector that matches it's PCI interrupt.
1095 @param Private Legacy BIOS Instance data
1097 @retval EFI_SUCCESS Succeed.
1098 @retval EFI_ALREADY_STARTED All PCI devices have been processed.
1102 PciProgramAllInterruptLineRegisters (
1103 IN LEGACY_BIOS_INSTANCE
*Private
1108 Collect EFI Info about legacy devices.
1110 @param Private Legacy BIOS Instance data
1112 @retval EFI_SUCCESS It should always work.
1116 LegacyBiosBuildSioData (
1117 IN LEGACY_BIOS_INSTANCE
*Private
1122 Shadow all the PCI legacy ROMs. Use data from the Legacy BIOS Protocol
1123 to chose the order. Skip any devices that have already have legacy
1126 @param Private Protocol instance pointer.
1128 @retval EFI_SUCCESS Succeed.
1129 @retval EFI_UNSUPPORTED Cannot get VGA device handle.
1134 IN LEGACY_BIOS_INSTANCE
*Private
1139 Fill in the standard BDA and EBDA stuff prior to legacy Boot
1141 @param Private Legacy BIOS Instance data
1143 @retval EFI_SUCCESS It should always work.
1147 LegacyBiosCompleteBdaBeforeBoot (
1148 IN LEGACY_BIOS_INSTANCE
*Private
1153 Fill in the standard CMOS stuff before Legacy16 load
1155 @param Private Legacy BIOS Instance data
1157 @retval EFI_SUCCESS It should always work.
1161 LegacyBiosInitCmos (
1162 IN LEGACY_BIOS_INSTANCE
*Private
1167 Fill in the standard CMOS stuff prior to legacy Boot
1169 @param Private Legacy BIOS Instance data
1171 @retval EFI_SUCCESS It should always work.
1175 LegacyBiosCompleteStandardCmosBeforeBoot (
1176 IN LEGACY_BIOS_INSTANCE
*Private
1181 Contains the code that is copied into low memory (below 640K).
1182 This code reflects interrupts 0x68-0x6f to interrupts 0x08-0x0f.
1183 This template must be copied into low memory, and the IDT entries
1184 0x68-0x6F must be point to the low memory copy of this code. Each
1185 entry is 4 bytes long, so IDT entries 0x68-0x6F can be easily
1190 InterruptRedirectionTemplate (
1196 Build the E820 table.
1198 @param Private Legacy BIOS Instance data
1199 @param Size Size of E820 Table
1201 @retval EFI_SUCCESS It should always work.
1205 LegacyBiosBuildE820 (
1206 IN LEGACY_BIOS_INSTANCE
*Private
,
1211 This function is to put all AP in halt state.
1213 @param Private Legacy BIOS Instance data
1218 IN LEGACY_BIOS_INSTANCE
*Private
1222 Worker function for LegacyBiosGetFlatDescs, retrieving content of
1225 @param IntThunk Pointer to IntThunk of Legacy BIOS context.
1230 LOW_MEMORY_THUNK
*IntThunk
1234 Routine for calling real thunk code.
1236 @param RealCode The address of thunk code.
1237 @param BiosInt The Bios interrupt vector number.
1238 @param CallAddress The address of 16-bit mode call.
1240 @return Status returned by real thunk code
1251 Routine for generating soft interrupt.
1253 @param Vector The interrupt vector number.
1262 Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode
1265 @param AllocateType Allocated Legacy Memory Type
1266 @param StartPageAddress Start address of range
1267 @param Pages Number of pages to allocate
1268 @param Result Result of allocation
1270 @retval EFI_SUCCESS Legacy16 code loaded
1271 @retval Other No protocol installed, unload driver.
1275 AllocateLegacyMemory (
1276 IN EFI_ALLOCATE_TYPE AllocateType
,
1277 IN EFI_PHYSICAL_ADDRESS StartPageAddress
,
1279 OUT EFI_PHYSICAL_ADDRESS
*Result
1283 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1285 @param This Protocol instance pointer.
1286 @param LegacyMemorySize Size of required region
1287 @param Region Region to use. 00 = Either 0xE0000 or 0xF0000
1288 block Bit0 = 1 0xF0000 block Bit1 = 1 0xE0000
1290 @param Alignment Address alignment. Bit mapped. First non-zero
1291 bit from right is alignment.
1292 @param LegacyMemoryAddress Region Assigned
1294 @retval EFI_SUCCESS Region assigned
1295 @retval EFI_ACCESS_DENIED Procedure previously invoked
1296 @retval Other Region not assigned
1301 LegacyBiosGetLegacyRegion (
1302 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1303 IN UINTN LegacyMemorySize
,
1306 OUT VOID
**LegacyMemoryAddress
1310 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1312 @param This Protocol instance pointer.
1313 @param LegacyMemorySize Size of data to copy
1314 @param LegacyMemoryAddress Legacy Region destination address Note: must
1315 be in region assigned by
1316 LegacyBiosGetLegacyRegion
1317 @param LegacyMemorySourceAddress Source of data
1319 @retval EFI_SUCCESS Region assigned
1320 @retval EFI_ACCESS_DENIED Destination outside assigned region
1325 LegacyBiosCopyLegacyRegion (
1326 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1327 IN UINTN LegacyMemorySize
,
1328 IN VOID
*LegacyMemoryAddress
,
1329 IN VOID
*LegacyMemorySourceAddress
1333 Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
1334 the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
1337 @param Private Legacy BIOS context data
1339 @retval EFI_SUCCESS Legacy16 code loaded
1340 @retval Other No protocol installed, unload driver.
1344 ShadowAndStartLegacy16 (
1345 IN LEGACY_BIOS_INSTANCE
*Private
1349 Checks the state of the floppy and if media is inserted.
1351 This routine checks the state of the floppy and if media is inserted.
1353 No floppy present - Set BBS entry to ignore
1354 Floppy present & no media - Set BBS entry to lowest priority. We cannot
1355 set it to ignore since 16-bit CSM will
1356 indicate no floppy and thus drive A: is
1357 unusable. CSM-16 will not try floppy since
1358 lowest priority and thus not incur boot
1360 Floppy present & media - Set BBS entry to some priority.
1362 @return State of floppy media
1371 Identify drive data must be updated to actual parameters before boot.
1372 This requires updating the checksum, if it exists.
1374 @param IdentifyDriveData ATA Identify Data
1375 @param Checksum checksum of the ATA Identify Data
1377 @retval EFI_SUCCESS checksum calculated
1378 @retval EFI_SECURITY_VIOLATION IdentifyData invalid
1382 CalculateIdentifyDriveChecksum (
1383 IN UINT8
*IdentifyDriveData
,
1388 Identify drive data must be updated to actual parameters before boot.
1390 @param IdentifyDriveData ATA Identify Data
1394 UpdateIdentifyDriveData (
1395 IN UINT8
*IdentifyDriveData
1399 Complete build of BBS TABLE.
1401 @param Private Legacy BIOS Instance data
1402 @param BbsTable BBS Table passed to 16-bit code
1404 @retval EFI_SUCCESS Removable media not present
1408 LegacyBiosBuildBbs (
1409 IN LEGACY_BIOS_INSTANCE
*Private
,
1410 IN BBS_TABLE
*BbsTable
1414 Read CMOS register through index/data port.
1416 @param[in] Index The index of the CMOS register to read.
1418 @return The data value from the CMOS register specified by Index.
1422 LegacyReadStandardCmos (
1427 Write CMOS register through index/data port.
1429 @param[in] Index The index of the CMOS register to write.
1430 @param[in] Value The value of CMOS register to write.
1432 @return The value written to the CMOS register specified by Index.
1436 LegacyWriteStandardCmos (
1442 Calculate the new standard CMOS checksum and write it.
1444 @param Private Legacy BIOS Instance data
1446 @retval EFI_SUCCESS Calculate 16-bit checksum successfully
1450 LegacyCalculateWriteStandardCmosChecksum (
1455 Test to see if a legacy PCI ROM exists for this device. Optionally return
1456 the Legacy ROM instance for this PCI device.
1458 @param[in] This Protocol instance pointer.
1459 @param[in] PciHandle The PCI PC-AT OPROM from this devices ROM BAR will be loaded
1460 @param[out] RomImage Return the legacy PCI ROM for this device
1461 @param[out] RomSize Size of ROM Image
1462 @param[out] RuntimeImageLength Runtime size of ROM Image
1463 @param[out] Flags Indicates if ROM found and if PC-AT.
1464 @param[out] OpromRevision Revision of the PCI Rom
1465 @param[out] ConfigUtilityCodeHeaderPointer of Configuration Utility Code Header
1467 @return EFI_SUCCESS Legacy Option ROM available for this device
1468 @return EFI_ALREADY_STARTED This device is already managed by its Oprom
1469 @return EFI_UNSUPPORTED Legacy Option ROM not supported.
1473 LegacyBiosCheckPciRomEx (
1474 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1475 IN EFI_HANDLE PciHandle
,
1476 OUT VOID
**RomImage
, OPTIONAL
1477 OUT UINTN
*RomSize
, OPTIONAL
1478 OUT UINTN
*RuntimeImageLength
, OPTIONAL
1479 OUT UINTN
*Flags
, OPTIONAL
1480 OUT UINT8
*OpromRevision
, OPTIONAL
1481 OUT VOID
**ConfigUtilityCodeHeader OPTIONAL
1485 Relocate this image under 4G memory for IPF.
1487 @param ImageHandle Handle of driver image.
1488 @param SystemTable Pointer to system table.
1490 @retval EFI_SUCCESS Image successfully relocated.
1491 @retval EFI_ABORTED Failed to relocate image.
1495 RelocateImageUnder4GIfNeeded (
1496 IN EFI_HANDLE ImageHandle
,
1497 IN EFI_SYSTEM_TABLE
*SystemTable
1501 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
1502 16-bit register context on entry and exit. Arguments can be passed on
1505 @param This Protocol instance pointer.
1506 @param Segment Segemnt of 16-bit mode call
1507 @param Offset Offset of 16-bit mdoe call
1508 @param Regs Register contexted passed into (and returned) from thunk to
1510 @param Stack Caller allocated stack used to pass arguments
1511 @param StackSize Size of Stack in bytes
1513 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
1514 See Regs for status.
1515 @retval TRUE There was a BIOS erro in the target code.
1520 InternalLegacyBiosFarCall (
1521 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1524 IN EFI_IA32_REGISTER_SET
*Regs
,
1530 Load a legacy PC-AT OpROM for VGA controller.
1532 @param Private Driver private data.
1534 @retval EFI_SUCCESS Legacy ROM successfully installed for this device.
1535 @retval EFI_DEVICE_ERROR No VGA device handle found, or native EFI video
1536 driver cannot be successfully disconnected, or VGA
1537 thunk driver cannot be successfully connected.
1541 LegacyBiosInstallVgaRom (
1542 IN LEGACY_BIOS_INSTANCE
*Private