3 Copyright (c) 2006 - 2013, 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>
24 #include <Guid/SmBios.h>
25 #include <Guid/Acpi.h>
26 #include <Guid/DxeServices.h>
27 #include <Guid/LegacyBios.h>
28 #include <Guid/StatusCodeDataTypeId.h>
29 #include <Guid/ImageAuthentication.h>
31 #include <Protocol/BlockIo.h>
32 #include <Protocol/LoadedImage.h>
33 #include <Protocol/PciIo.h>
34 #include <Protocol/Cpu.h>
35 #include <Protocol/Timer.h>
36 #include <Protocol/IsaIo.h>
37 #include <Protocol/LegacyRegion2.h>
38 #include <Protocol/SimpleTextIn.h>
39 #include <Protocol/LegacyInterrupt.h>
40 #include <Protocol/LegacyBios.h>
41 #include <Protocol/DiskInfo.h>
42 #include <Protocol/GenericMemoryTest.h>
43 #include <Protocol/LegacyBiosPlatform.h>
44 #include <Protocol/DevicePath.h>
45 #include <Protocol/Legacy8259.h>
46 #include <Protocol/PciRootBridgeIo.h>
48 #include <Library/BaseLib.h>
49 #include <Library/DebugLib.h>
50 #include <Library/UefiLib.h>
51 #include <Library/BaseMemoryLib.h>
52 #include <Library/ReportStatusCodeLib.h>
53 #include <Library/UefiRuntimeServicesTableLib.h>
54 #include <Library/HobLib.h>
55 #include <Library/UefiDriverEntryPoint.h>
56 #include <Library/MemoryAllocationLib.h>
57 #include <Library/UefiBootServicesTableLib.h>
58 #include <Library/IoLib.h>
59 #include <Library/PcdLib.h>
60 #include <Library/DevicePathLib.h>
61 #include <Library/DxeServicesTableLib.h>
62 #include <Library/PeCoffLib.h>
63 #include <Library/CacheMaintenanceLib.h>
64 #include <Library/DebugAgentLib.h>
67 // BUGBUG: This entry maybe changed to PCD in future and wait for
68 // redesign of BDS library
70 #define MAX_BBS_ENTRIES 0x100
74 // (These apply only to errors with the thunk and not to the code that was
78 #define THUNK_ERR_A20_UNSUP 0x01
79 #define THUNK_ERR_A20_FAILED 0x02
82 // Vector base definitions
85 // 8259 Hardware definitions
87 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
88 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
91 // The original PC used INT8-F for master PIC. Since these mapped over
92 // processor exceptions TIANO moved the master PIC to INT68-6F.
94 // The vector base for slave PIC is set as 0x70 for PC-AT compatibility.
96 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
97 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
100 // When we call CSM16 functions, some CSM16 use es:[offset + 0xabcd] to get data passed from CSM32,
101 // offset + 0xabcd could overflow which exceeds 0xFFFF which is invalid in real mode.
102 // So this will keep offset as small as possible to avoid offset overflow in real mode.
104 #define NORMALIZE_EFI_SEGMENT(_Adr) (UINT16) (((UINTN) (_Adr)) >> 4)
105 #define NORMALIZE_EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xf)
111 #define LEGACY_BDA_TRACE 0x000
112 #define LEGACY_BIOS_TRACE 0x040
113 #define LEGACY_BOOT_TRACE 0x080
114 #define LEGACY_CMOS_TRACE 0x0C0
115 #define LEGACY_IDE_TRACE 0x100
116 #define LEGACY_MP_TRACE 0x140
117 #define LEGACY_PCI_TRACE 0x180
118 #define LEGACY_SIO_TRACE 0x1C0
120 #define LEGACY_PCI_TRACE_000 LEGACY_PCI_TRACE + 0x00
121 #define LEGACY_PCI_TRACE_001 LEGACY_PCI_TRACE + 0x01
122 #define LEGACY_PCI_TRACE_002 LEGACY_PCI_TRACE + 0x02
123 #define LEGACY_PCI_TRACE_003 LEGACY_PCI_TRACE + 0x03
124 #define LEGACY_PCI_TRACE_004 LEGACY_PCI_TRACE + 0x04
125 #define LEGACY_PCI_TRACE_005 LEGACY_PCI_TRACE + 0x05
126 #define LEGACY_PCI_TRACE_006 LEGACY_PCI_TRACE + 0x06
127 #define LEGACY_PCI_TRACE_007 LEGACY_PCI_TRACE + 0x07
128 #define LEGACY_PCI_TRACE_008 LEGACY_PCI_TRACE + 0x08
129 #define LEGACY_PCI_TRACE_009 LEGACY_PCI_TRACE + 0x09
130 #define LEGACY_PCI_TRACE_00A LEGACY_PCI_TRACE + 0x0A
131 #define LEGACY_PCI_TRACE_00B LEGACY_PCI_TRACE + 0x0B
132 #define LEGACY_PCI_TRACE_00C LEGACY_PCI_TRACE + 0x0C
133 #define LEGACY_PCI_TRACE_00D LEGACY_PCI_TRACE + 0x0D
134 #define LEGACY_PCI_TRACE_00E LEGACY_PCI_TRACE + 0x0E
135 #define LEGACY_PCI_TRACE_00F LEGACY_PCI_TRACE + 0x0F
137 #define BDA_VIDEO_MODE 0x49
139 #define IDE_PI_REGISTER_PNE BIT0
140 #define IDE_PI_REGISTER_SNE BIT2
147 UINT32 ShadowAddress
;
151 } ROM_INSTANCE_ENTRY
;
154 // Values for RealModeGdt
156 #if defined (MDE_CPU_IA32)
158 #define NUM_REAL_GDT_ENTRIES 3
159 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
160 #define INITIAL_VALUE_BELOW_1K 0x0
162 #elif defined (MDE_CPU_X64)
164 #define NUM_REAL_GDT_ENTRIES 8
165 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
166 #define INITIAL_VALUE_BELOW_1K 0x0
168 #elif defined (MDE_CPU_IPF)
170 #define NUM_REAL_GDT_ENTRIES 3
171 #define CONVENTIONAL_MEMORY_TOP 0x80000 // 512 KB
172 #define INITIAL_VALUE_BELOW_1K 0xff
179 // Define what a processor GDT looks like
192 UINT32 DefaultSize
: 1;
193 UINT32 Granularity
: 1;
207 // Define what a processor descriptor looks like
208 // This data structure must be kept in sync with ASM STRUCT in Thunk.inc
223 #define LOW_STACK_SIZE (8 * 1024) // 8k?
224 #define EFI_MAX_E820_ENTRY 100
225 #define FIRST_INSTANCE 1
226 #define NOT_FIRST_INSTANCE 0
228 #if defined (MDE_CPU_IA32)
231 // Space for the code
232 // The address of Code is also the beginning of the relocated Thunk code
234 CHAR8 Code
[4096]; // ?
236 // The address of the Reverse Thunk code
237 // Note that this member CONTAINS the address of the relocated reverse thunk
238 // code unlike the member variable 'Code', which IS the address of the Thunk
241 UINT32 LowReverseThunkStart
;
244 // Data for the code (cs releative)
246 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
247 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
251 UINT32 LowCodeSelector
; // Low code selector in GDT
252 UINT32 LowDataSelector
; // Low data selector in GDT
254 DESCRIPTOR32 RealModeIdtDesc
;
257 // real-mode GDT (temporary GDT with two real mode segment descriptors)
259 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
260 DESCRIPTOR32 RealModeGdtDesc
;
263 // Members specifically for the reverse thunk
264 // The RevReal* members are used to store the current state of real mode
265 // before performing the reverse thunk. The RevFlat* members must be set
266 // before calling the reverse thunk assembly code.
271 DESCRIPTOR32 RevRealIdtDesc
;
272 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
276 // A low memory stack
278 CHAR8 Stack
[LOW_STACK_SIZE
];
281 // Stack for flat mode after reverse thunk
282 // @bug - This may no longer be necessary if the reverse thunk interface
283 // is changed to have the flat stack in a different location.
285 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
288 // Legacy16 Init memory map info
290 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
292 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
294 CHAR8 InterruptRedirectionCode
[32];
295 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
296 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
297 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
300 #elif defined (MDE_CPU_X64)
304 // Space for the code
305 // The address of Code is also the beginning of the relocated Thunk code
307 CHAR8 Code
[4096]; // ?
310 // Data for the code (cs releative)
312 DESCRIPTOR64 X64GdtDesc
; // Protected mode GDT
313 DESCRIPTOR64 X64IdtDesc
; // Protected mode IDT
318 DESCRIPTOR32 RealModeIdtDesc
;
319 DESCRIPTOR32 RealModeGdtDesc
;
322 // real-mode GDT (temporary GDT with two real mode segment descriptors)
324 GDT64 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
325 UINT64 PageMapLevel4
;
328 // A low memory stack
330 CHAR8 Stack
[LOW_STACK_SIZE
];
333 // Legacy16 Init memory map info
335 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
337 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
339 CHAR8 InterruptRedirectionCode
[32];
340 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
341 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
342 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
345 #elif defined (MDE_CPU_IPF)
349 // Space for the code
350 // The address of Code is also the beginning of the relocated Thunk code
352 CHAR8 Code
[4096]; // ?
354 // The address of the Reverse Thunk code
355 // Note that this member CONTAINS the address of the relocated reverse thunk
356 // code unlike the member variable 'Code', which IS the address of the Thunk
359 UINT32 LowReverseThunkStart
;
362 // Data for the code (cs releative)
364 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
365 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
369 UINT32 LowCodeSelector
; // Low code selector in GDT
370 UINT32 LowDataSelector
; // Low data selector in GDT
372 DESCRIPTOR32 RealModeIdtDesc
;
375 // real-mode GDT (temporary GDT with two real mode segment descriptors)
377 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
378 DESCRIPTOR32 RealModeGdtDesc
;
381 // Members specifically for the reverse thunk
382 // The RevReal* members are used to store the current state of real mode
383 // before performing the reverse thunk. The RevFlat* members must be set
384 // before calling the reverse thunk assembly code.
389 DESCRIPTOR32 RevRealIdtDesc
;
390 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
394 // A low memory stack
396 CHAR8 Stack
[LOW_STACK_SIZE
];
399 // Stack for flat mode after reverse thunk
400 // @bug - This may no longer be necessary if the reverse thunk interface
401 // is changed to have the flat stack in a different location.
403 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
406 // Legacy16 Init memory map info
408 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
410 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
412 CHAR8 InterruptRedirectionCode
[32];
413 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
414 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
415 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
421 // PnP Expansion Header
432 UINT16 ProductNamePointer
;
436 UINT8 DeviceIndicators
;
438 UINT16 DisconnectVector
;
441 UINT16 StaticResourceVector
;
442 } LEGACY_PNP_EXPANSION_HEADER
;
458 UINTN ManufacturerString
;
459 UINTN ProductNameString
;
460 } LEGACY_ROM_AND_BBS_TABLE
;
463 // Structure how EFI has mapped a devices HDD drive numbers.
464 // Boot to EFI aware OS or shell requires this mapping when
465 // 16-bit CSM assigns drive numbers.
466 // This mapping is ignored booting to a legacy OS.
473 UINT8 StartDriveNumber
;
474 UINT8 EndDriveNumber
;
475 } LEGACY_EFI_HDD_TABLE
;
478 // This data is passed to Leacy16Boot
481 EfiAcpiAddressRangeMemory
= 1,
482 EfiAcpiAddressRangeReserved
= 2,
483 EfiAcpiAddressRangeACPI
= 3,
484 EfiAcpiAddressRangeNVS
= 4
485 } EFI_ACPI_MEMORY_TYPE
;
490 EFI_ACPI_MEMORY_TYPE Type
;
498 EFI_ACPI_MEMORY_TYPE Type
;
503 extern BBS_TABLE
*mBbsTable
;
505 extern EFI_GENERIC_MEMORY_TEST_PROTOCOL
*gGenMemoryTest
;
510 #define CMOS_0A 0x0a ///< Status register A
511 #define CMOS_0D 0x0d ///< Status register D
512 #define CMOS_0E 0x0e ///< Diagnostic Status
513 #define CMOS_0F 0x0f ///< Shutdown status
514 #define CMOS_10 0x10 ///< Floppy type
515 #define CMOS_12 0x12 ///< IDE type
516 #define CMOS_14 0x14 ///< Same as BDA 40:10
517 #define CMOS_15 0x15 ///< Low byte of base memory in 1k increments
518 #define CMOS_16 0x16 ///< High byte of base memory in 1k increments
519 #define CMOS_17 0x17 ///< Low byte of 1MB+ memory in 1k increments - max 15 MB
520 #define CMOS_18 0x18 ///< High byte of 1MB+ memory in 1k increments - max 15 MB
521 #define CMOS_19 0x19 ///< C: extended drive type
522 #define CMOS_1A 0x1a ///< D: extended drive type
523 #define CMOS_2E 0x2e ///< Most significient byte of standard checksum
524 #define CMOS_2F 0x2f ///< Least significient byte of standard checksum
525 #define CMOS_30 0x30 ///< CMOS 0x17
526 #define CMOS_31 0x31 ///< CMOS 0x18
527 #define CMOS_32 0x32 ///< Century byte
530 // 8254 Timer registers
532 #define TIMER0_COUNT_PORT 0x40
533 #define TIMER1_COUNT_PORT 0x41
534 #define TIMER2_COUNT_PORT 0x42
535 #define TIMER_CONTROL_PORT 0x43
538 // Timer 0, Read/Write LSB then MSB, Square wave output, binary count use.
540 #define TIMER0_CONTROL_WORD 0x36
542 #define LEGACY_BIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('L', 'B', 'I', 'T')
547 EFI_LEGACY_BIOS_PROTOCOL LegacyBios
;
549 EFI_HANDLE ImageHandle
;
552 // CPU Architectural Protocol
554 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
557 // Timer Architectural Protocol
559 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
560 BOOLEAN TimerUses8254
;
563 // Protocol to Lock and Unlock 0xc0000 - 0xfffff
565 EFI_LEGACY_REGION2_PROTOCOL
*LegacyRegion
;
567 EFI_LEGACY_BIOS_PLATFORM_PROTOCOL
*LegacyBiosPlatform
;
570 // Interrupt control for thunk and PCI IRQ
572 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
575 // PCI Interrupt PIRQ control
577 EFI_LEGACY_INTERRUPT_PROTOCOL
*LegacyInterrupt
;
580 // Generic Memory Test
582 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenericMemoryTest
;
585 // TRUE if PCI Interupt Line registers have been programmed.
587 BOOLEAN PciInterruptLine
;
590 // Code space below 1MB needed by thunker to transition to real mode.
591 // Contains stack and real mode code fragments
593 LOW_MEMORY_THUNK
*IntThunk
;
596 // Starting shadow address of the Legacy BIOS
599 UINT32 LegacyBiosImageSize
;
602 // Start of variables used by CsmItp.mac ITP macro file and/os LegacyBios
607 // $EFI Legacy16 code entry info in memory < 1 MB;
609 EFI_COMPATIBILITY16_TABLE
*Legacy16Table
;
610 VOID
*Legacy16InitPtr
;
611 VOID
*Legacy16BootPtr
;
612 VOID
*InternalIrqRoutingTable
;
613 UINT32 NumberIrqRoutingEntries
;
616 UINT32 NumberHddControllers
;
619 // Cached copy of Legacy16 entry point
621 UINT16 Legacy16CallSegment
;
622 UINT16 Legacy16CallOffset
;
625 // Returned from $EFI and passed in to OPROMS
627 UINT16 PnPInstallationCheckSegment
;
628 UINT16 PnPInstallationCheckOffset
;
633 EFI_E820_ENTRY E820Table
[EFI_MAX_E820_ENTRY
];
634 UINT32 NumberE820Entries
;
637 // True if legacy VGA INT 10h handler installed
639 BOOLEAN VgaInstalled
;
642 // Number of IDE drives
647 // Current Free Option ROM space. An option ROM must NOT go past
653 // Save Legacy16 unexpected interrupt vector. Reprogram INT 68-6F from
654 // EFI values to legacy value just before boot.
656 UINT32 BiosUnexpectedInt
;
657 UINT32 ThunkSavedInt
[8];
659 LEGACY_EFI_HDD_TABLE
*LegacyEfiHddTable
;
660 UINT16 LegacyEfiHddTableIndex
;
667 // Indicate that whether GenericLegacyBoot is entered or not
669 BOOLEAN LegacyBootEntered
;
672 // CSM16 PCI Interface Version
674 UINT16 Csm16PciInterfaceVersion
;
676 } LEGACY_BIOS_INSTANCE
;
689 40:0E-0E Ebda segment
690 40:10-11 MachineConfig
692 40:13-14 MemSize below 1MB
693 40:15-16 Bda15_16 - skip
694 40:17 Keyboard Shift status
695 40:18-19 Bda18_19 - skip
696 40:1A-1B Key buffer head
697 40:1C-1D Key buffer tail
698 40:1E-3D Bda1E_3D- key buffer -skip
699 40:3E-3F FloppyData 3E = Calibration status 3F = Motor status
701 40:41-74 Bda41_74 - skip
702 40:75 Number of HDD drives
703 40:76-77 Bda76_77 - skip
704 40:78-79 78 = Lpt1 timeout, 79 = Lpt2 timeout
705 40:7A-7B 7A = Lpt3 timeout, 7B = Lpt4 timeout
706 40:7C-7D 7C = Com1 timeout, 7D = Com2 timeout
707 40:7E-7F 7E = Com3 timeout, 7F = Com4 timeout
708 40:80-81 Pointer to start of key buffer
709 40:82-83 Pointer to end of key buffer
710 40:84-87 Bda84_87 - skip
711 40:88 HDD Data Xmit rate
713 40:90 Floppy data rate
715 40:96 Keyboard Status
728 UINT16 MachineConfig
;
731 UINT8 Bda15_16
[0x02];
733 UINT8 Bda18_19
[0x02];
736 UINT16 Bda1E_3D
[0x10];
739 UINT8 Bda41_74
[0x34];
740 UINT8 NumberOfDrives
;
741 UINT8 Bda76_77
[0x02];
742 UINT16 Lpt1_2Timeout
;
743 UINT16 Lpt3_4Timeout
;
744 UINT16 Com1_2Timeout
;
745 UINT16 Com3_4Timeout
;
750 UINT8 Bda89_8F
[0x07];
752 UINT8 Bda91_95
[0x05];
753 UINT8 KeyboardStatus
;
758 #define LEGACY_BIOS_INSTANCE_FROM_THIS(this) CR (this, LEGACY_BIOS_INSTANCE, LegacyBios, LEGACY_BIOS_INSTANCE_SIGNATURE)
761 Thunk to 16-bit real mode and execute a software interrupt with a vector
762 of BiosInt. Regs will contain the 16-bit register context on entry and
765 @param This Protocol instance pointer.
766 @param BiosInt Processor interrupt vector to invoke
767 @param Regs Register contexted passed into (and returned) from thunk to
770 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
772 @retval TRUE There was a BIOS erro in the target code.
778 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
780 IN EFI_IA32_REGISTER_SET
*Regs
785 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
786 16-bit register context on entry and exit. Arguments can be passed on
789 @param This Protocol instance pointer.
790 @param Segment Segemnt of 16-bit mode call
791 @param Offset Offset of 16-bit mdoe call
792 @param Regs Register contexted passed into (and returned) from
794 @param Stack Caller allocated stack used to pass arguments
795 @param StackSize Size of Stack in bytes
797 @retval FALSE Thunk completed, and there were no BIOS errors in
798 the target code. See Regs for status.
799 @retval TRUE There was a BIOS erro in the target code.
804 LegacyBiosFarCall86 (
805 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
808 IN EFI_IA32_REGISTER_SET
*Regs
,
815 Test to see if a legacy PCI ROM exists for this device. Optionally return
816 the Legacy ROM instance for this PCI device.
818 @param This Protocol instance pointer.
819 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
821 @param RomImage Return the legacy PCI ROM for this device
822 @param RomSize Size of ROM Image
823 @param Flags Indicates if ROM found and if PC-AT.
825 @retval EFI_SUCCESS Legacy Option ROM availible for this device
826 @retval EFI_UNSUPPORTED Legacy Option ROM not supported.
831 LegacyBiosCheckPciRom (
832 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
833 IN EFI_HANDLE PciHandle
,
834 OUT VOID
**RomImage
, OPTIONAL
835 OUT UINTN
*RomSize
, OPTIONAL
841 Assign drive number to legacy HDD drives prior to booting an EFI
842 aware OS so the OS can access drives without an EFI driver.
843 Note: BBS compliant drives ARE NOT available until this call by
846 @param This Protocol instance pointer.
847 @param BbsCount Number of BBS_TABLE structures
848 @param BbsTable List BBS entries
850 @retval EFI_SUCCESS Drive numbers assigned
855 LegacyBiosPrepareToBootEfi (
856 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
857 OUT UINT16
*BbsCount
,
858 OUT BBS_TABLE
**BbsTable
863 To boot from an unconventional device like parties and/or execute
866 @param This Protocol instance pointer.
867 @param Attributes How to interpret the other input parameters
868 @param BbsEntry The 0-based index into the BbsTable for the parent
870 @param BeerData Pointer to the 128 bytes of ram BEER data.
871 @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
872 The caller must provide a pointer to the specific
873 Service Area and not the start all Service Areas.
874 EFI_INVALID_PARAMETER if error. Does NOT return if no error.
879 LegacyBiosBootUnconventionalDevice (
880 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
881 IN UDC_ATTRIBUTES Attributes
,
884 IN VOID
*ServiceAreaData
889 Load a legacy PC-AT OPROM on the PciHandle device. Return information
890 about how many disks were added by the OPROM and the shadow address and
891 size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
893 @param This Protocol instance pointer.
894 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
895 be loaded. This value is NULL if RomImage is
896 non-NULL. This is the normal case.
897 @param RomImage A PCI PC-AT ROM image. This argument is non-NULL
898 if there is no hardware associated with the ROM
899 and thus no PciHandle, otherwise is must be NULL.
900 Example is PXE base code.
901 @param Flags Indicates if ROM found and if PC-AT.
902 @param DiskStart Disk number of first device hooked by the ROM. If
903 DiskStart is the same as DiskEnd no disked were
905 @param DiskEnd Disk number of the last device hooked by the ROM.
906 @param RomShadowAddress Shadow address of PC-AT ROM
907 @param RomShadowedSize Size of RomShadowAddress in bytes
909 @retval EFI_SUCCESS Legacy ROM loaded for this device
910 @retval EFI_INVALID_PARAMETER PciHandle not found
911 @retval EFI_UNSUPPORTED There is no PCI ROM in the ROM BAR or no onboard
917 LegacyBiosInstallPciRom (
918 IN EFI_LEGACY_BIOS_PROTOCOL
* This
,
919 IN EFI_HANDLE PciHandle
,
922 OUT UINT8
*DiskStart
, OPTIONAL
923 OUT UINT8
*DiskEnd
, OPTIONAL
924 OUT VOID
**RomShadowAddress
, OPTIONAL
925 OUT UINT32
*RomShadowedSize OPTIONAL
930 Fill in the standard BDA for Keyboard LEDs
932 @param This Protocol instance pointer.
933 @param Leds Current LED status
935 @retval EFI_SUCCESS It should always work.
940 LegacyBiosUpdateKeyboardLedStatus (
941 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
949 @param This Protocol instance pointer.
950 @param HddCount Number of HDD_INFO structures
951 @param HddInfo Onboard IDE controller information
952 @param BbsCount Number of BBS_TABLE structures
953 @param BbsTable List BBS entries
955 @retval EFI_SUCCESS Tables returned
956 @retval EFI_NOT_FOUND resource not found
957 @retval EFI_DEVICE_ERROR can not get BBS table
962 LegacyBiosGetBbsInfo (
963 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
964 OUT UINT16
*HddCount
,
965 OUT HDD_INFO
**HddInfo
,
966 OUT UINT16
*BbsCount
,
967 OUT BBS_TABLE
**BbsTable
972 Shadow all legacy16 OPROMs that haven't been shadowed.
973 Warning: Use this with caution. This routine disconnects all EFI
974 drivers. If used externally then caller must re-connect EFI
977 @param This Protocol instance pointer.
979 @retval EFI_SUCCESS OPROMs shadowed
984 LegacyBiosShadowAllLegacyOproms (
985 IN EFI_LEGACY_BIOS_PROTOCOL
*This
990 Attempt to legacy boot the BootOption. If the EFI contexted has been
991 compromised this function will not return.
993 @param This Protocol instance pointer.
994 @param BbsDevicePath EFI Device Path from BootXXXX variable.
995 @param LoadOptionsSize Size of LoadOption in size.
996 @param LoadOptions LoadOption from BootXXXX variable
998 @retval EFI_SUCCESS Removable media not present
1003 LegacyBiosLegacyBoot (
1004 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1005 IN BBS_BBS_DEVICE_PATH
*BbsDevicePath
,
1006 IN UINT32 LoadOptionsSize
,
1007 IN VOID
*LoadOptions
1012 Allocate memory < 1 MB and copy the thunker code into low memory. Se up
1013 all the descriptors.
1015 @param Private Private context for Legacy BIOS
1017 @retval EFI_SUCCESS Should only pass.
1021 LegacyBiosInitializeThunk (
1022 IN LEGACY_BIOS_INSTANCE
*Private
1027 Fill in the standard BDA and EBDA stuff before Legacy16 load
1029 @param Private Legacy BIOS Instance data
1031 @retval EFI_SUCCESS It should always work.
1036 IN LEGACY_BIOS_INSTANCE
*Private
1041 Collect IDE Inquiry data from the IDE disks
1043 @param Private Legacy BIOS Instance data
1044 @param HddInfo Hdd Information
1045 @param Flag Reconnect IdeController or not
1047 @retval EFI_SUCCESS It should always work.
1051 LegacyBiosBuildIdeData (
1052 IN LEGACY_BIOS_INSTANCE
*Private
,
1053 IN HDD_INFO
**HddInfo
,
1059 Enable ide controller. This gets disabled when LegacyBoot.c is about
1060 to run the Option ROMs.
1062 @param Private Legacy BIOS Instance data
1067 EnableIdeController (
1068 IN LEGACY_BIOS_INSTANCE
*Private
1073 If the IDE channel is in compatibility (legacy) mode, remove all
1074 PCI I/O BAR addresses from the controller.
1076 @param IdeController The handle of target IDE controller
1081 InitLegacyIdeController (
1082 IN EFI_HANDLE IdeController
1087 Program the interrupt routing register in all the PCI devices. On a PC AT system
1088 this register contains the 8259 IRQ vector that matches it's PCI interrupt.
1090 @param Private Legacy BIOS Instance data
1092 @retval EFI_SUCCESS Succeed.
1093 @retval EFI_ALREADY_STARTED All PCI devices have been processed.
1097 PciProgramAllInterruptLineRegisters (
1098 IN LEGACY_BIOS_INSTANCE
*Private
1103 Collect EFI Info about legacy devices.
1105 @param Private Legacy BIOS Instance data
1107 @retval EFI_SUCCESS It should always work.
1111 LegacyBiosBuildSioData (
1112 IN LEGACY_BIOS_INSTANCE
*Private
1117 Shadow all the PCI legacy ROMs. Use data from the Legacy BIOS Protocol
1118 to chose the order. Skip any devices that have already have legacy
1121 @param Private Protocol instance pointer.
1123 @retval EFI_SUCCESS Succeed.
1124 @retval EFI_UNSUPPORTED Cannot get VGA device handle.
1129 IN LEGACY_BIOS_INSTANCE
*Private
1134 Fill in the standard BDA and EBDA stuff prior to legacy Boot
1136 @param Private Legacy BIOS Instance data
1138 @retval EFI_SUCCESS It should always work.
1142 LegacyBiosCompleteBdaBeforeBoot (
1143 IN LEGACY_BIOS_INSTANCE
*Private
1148 Fill in the standard CMOS stuff before Legacy16 load
1150 @param Private Legacy BIOS Instance data
1152 @retval EFI_SUCCESS It should always work.
1156 LegacyBiosInitCmos (
1157 IN LEGACY_BIOS_INSTANCE
*Private
1162 Fill in the standard CMOS stuff prior to legacy Boot
1164 @param Private Legacy BIOS Instance data
1166 @retval EFI_SUCCESS It should always work.
1170 LegacyBiosCompleteStandardCmosBeforeBoot (
1171 IN LEGACY_BIOS_INSTANCE
*Private
1176 Contains the code that is copied into low memory (below 640K).
1177 This code reflects interrupts 0x68-0x6f to interrupts 0x08-0x0f.
1178 This template must be copied into low memory, and the IDT entries
1179 0x68-0x6F must be point to the low memory copy of this code. Each
1180 entry is 4 bytes long, so IDT entries 0x68-0x6F can be easily
1185 InterruptRedirectionTemplate (
1191 Build the E820 table.
1193 @param Private Legacy BIOS Instance data
1194 @param Size Size of E820 Table
1196 @retval EFI_SUCCESS It should always work.
1200 LegacyBiosBuildE820 (
1201 IN LEGACY_BIOS_INSTANCE
*Private
,
1206 This function is to put all AP in halt state.
1208 @param Private Legacy BIOS Instance data
1213 IN LEGACY_BIOS_INSTANCE
*Private
1217 Worker function for LegacyBiosGetFlatDescs, retrieving content of
1220 @param IntThunk Pointer to IntThunk of Legacy BIOS context.
1225 LOW_MEMORY_THUNK
*IntThunk
1229 Routine for calling real thunk code.
1231 @param RealCode The address of thunk code.
1232 @param BiosInt The Bios interrupt vector number.
1233 @param CallAddress The address of 16-bit mode call.
1235 @return Status returned by real thunk code
1246 Routine for generating soft interrupt.
1248 @param Vector The interrupt vector number.
1257 Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode
1260 @param AllocateType Allocated Legacy Memory Type
1261 @param StartPageAddress Start address of range
1262 @param Pages Number of pages to allocate
1263 @param Result Result of allocation
1265 @retval EFI_SUCCESS Legacy16 code loaded
1266 @retval Other No protocol installed, unload driver.
1270 AllocateLegacyMemory (
1271 IN EFI_ALLOCATE_TYPE AllocateType
,
1272 IN EFI_PHYSICAL_ADDRESS StartPageAddress
,
1274 OUT EFI_PHYSICAL_ADDRESS
*Result
1278 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1280 @param This Protocol instance pointer.
1281 @param LegacyMemorySize Size of required region
1282 @param Region Region to use. 00 = Either 0xE0000 or 0xF0000
1283 block Bit0 = 1 0xF0000 block Bit1 = 1 0xE0000
1285 @param Alignment Address alignment. Bit mapped. First non-zero
1286 bit from right is alignment.
1287 @param LegacyMemoryAddress Region Assigned
1289 @retval EFI_SUCCESS Region assigned
1290 @retval EFI_ACCESS_DENIED Procedure previously invoked
1291 @retval Other Region not assigned
1296 LegacyBiosGetLegacyRegion (
1297 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1298 IN UINTN LegacyMemorySize
,
1301 OUT VOID
**LegacyMemoryAddress
1305 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1307 @param This Protocol instance pointer.
1308 @param LegacyMemorySize Size of data to copy
1309 @param LegacyMemoryAddress Legacy Region destination address Note: must
1310 be in region assigned by
1311 LegacyBiosGetLegacyRegion
1312 @param LegacyMemorySourceAddress Source of data
1314 @retval EFI_SUCCESS Region assigned
1315 @retval EFI_ACCESS_DENIED Destination outside assigned region
1320 LegacyBiosCopyLegacyRegion (
1321 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1322 IN UINTN LegacyMemorySize
,
1323 IN VOID
*LegacyMemoryAddress
,
1324 IN VOID
*LegacyMemorySourceAddress
1328 Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
1329 the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
1332 @param Private Legacy BIOS context data
1334 @retval EFI_SUCCESS Legacy16 code loaded
1335 @retval Other No protocol installed, unload driver.
1339 ShadowAndStartLegacy16 (
1340 IN LEGACY_BIOS_INSTANCE
*Private
1344 Checks the state of the floppy and if media is inserted.
1346 This routine checks the state of the floppy and if media is inserted.
1348 No floppy present - Set BBS entry to ignore
1349 Floppy present & no media - Set BBS entry to lowest priority. We cannot
1350 set it to ignore since 16-bit CSM will
1351 indicate no floppy and thus drive A: is
1352 unusable. CSM-16 will not try floppy since
1353 lowest priority and thus not incur boot
1355 Floppy present & media - Set BBS entry to some priority.
1357 @return State of floppy media
1366 Identify drive data must be updated to actual parameters before boot.
1367 This requires updating the checksum, if it exists.
1369 @param IdentifyDriveData ATA Identify Data
1370 @param Checksum checksum of the ATA Identify Data
1372 @retval EFI_SUCCESS checksum calculated
1373 @retval EFI_SECURITY_VIOLATION IdentifyData invalid
1377 CalculateIdentifyDriveChecksum (
1378 IN UINT8
*IdentifyDriveData
,
1383 Identify drive data must be updated to actual parameters before boot.
1385 @param IdentifyDriveData ATA Identify Data
1389 UpdateIdentifyDriveData (
1390 IN UINT8
*IdentifyDriveData
1394 Complete build of BBS TABLE.
1396 @param Private Legacy BIOS Instance data
1397 @param BbsTable BBS Table passed to 16-bit code
1399 @retval EFI_SUCCESS Removable media not present
1403 LegacyBiosBuildBbs (
1404 IN LEGACY_BIOS_INSTANCE
*Private
,
1405 IN BBS_TABLE
*BbsTable
1409 Read CMOS register through index/data port.
1411 @param[in] Index The index of the CMOS register to read.
1413 @return The data value from the CMOS register specified by Index.
1417 LegacyReadStandardCmos (
1422 Write CMOS register through index/data port.
1424 @param[in] Index The index of the CMOS register to write.
1425 @param[in] Value The value of CMOS register to write.
1427 @return The value written to the CMOS register specified by Index.
1431 LegacyWriteStandardCmos (
1437 Calculate the new standard CMOS checksum and write it.
1439 @param Private Legacy BIOS Instance data
1441 @retval EFI_SUCCESS Calculate 16-bit checksum successfully
1445 LegacyCalculateWriteStandardCmosChecksum (
1450 Test to see if a legacy PCI ROM exists for this device. Optionally return
1451 the Legacy ROM instance for this PCI device.
1453 @param[in] This Protocol instance pointer.
1454 @param[in] PciHandle The PCI PC-AT OPROM from this devices ROM BAR will be loaded
1455 @param[out] RomImage Return the legacy PCI ROM for this device
1456 @param[out] RomSize Size of ROM Image
1457 @param[out] RuntimeImageLength Runtime size of ROM Image
1458 @param[out] Flags Indicates if ROM found and if PC-AT.
1459 @param[out] OpromRevision Revision of the PCI Rom
1460 @param[out] ConfigUtilityCodeHeaderPointer of Configuration Utility Code Header
1462 @return EFI_SUCCESS Legacy Option ROM availible for this device
1463 @return EFI_ALREADY_STARTED This device is already managed by its Oprom
1464 @return EFI_UNSUPPORTED Legacy Option ROM not supported.
1468 LegacyBiosCheckPciRomEx (
1469 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1470 IN EFI_HANDLE PciHandle
,
1471 OUT VOID
**RomImage
, OPTIONAL
1472 OUT UINTN
*RomSize
, OPTIONAL
1473 OUT UINTN
*RuntimeImageLength
, OPTIONAL
1474 OUT UINTN
*Flags
, OPTIONAL
1475 OUT UINT8
*OpromRevision
, OPTIONAL
1476 OUT VOID
**ConfigUtilityCodeHeader OPTIONAL
1480 Relocate this image under 4G memory for IPF.
1482 @param ImageHandle Handle of driver image.
1483 @param SystemTable Pointer to system table.
1485 @retval EFI_SUCCESS Image successfully relocated.
1486 @retval EFI_ABORTED Failed to relocate image.
1490 RelocateImageUnder4GIfNeeded (
1491 IN EFI_HANDLE ImageHandle
,
1492 IN EFI_SYSTEM_TABLE
*SystemTable
1496 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
1497 16-bit register context on entry and exit. Arguments can be passed on
1500 @param This Protocol instance pointer.
1501 @param Segment Segemnt of 16-bit mode call
1502 @param Offset Offset of 16-bit mdoe call
1503 @param Regs Register contexted passed into (and returned) from thunk to
1505 @param Stack Caller allocated stack used to pass arguments
1506 @param StackSize Size of Stack in bytes
1508 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
1509 See Regs for status.
1510 @retval TRUE There was a BIOS erro in the target code.
1515 InternalLegacyBiosFarCall (
1516 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1519 IN EFI_IA32_REGISTER_SET
*Regs
,
1525 Load a legacy PC-AT OpROM for VGA controller.
1527 @param Private Driver private data.
1529 @retval EFI_SUCCESS Legacy ROM successfully installed for this device.
1530 @retval EFI_DEVICE_ERROR No VGA device handle found, or native EFI video
1531 driver cannot be successfully disconnected, or VGA
1532 thunk driver cannot be successfully connected.
1536 LegacyBiosInstallVgaRom (
1537 IN LEGACY_BIOS_INSTANCE
*Private