3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _LEGACY_BIOS_INTERFACE_
10 #define _LEGACY_BIOS_INTERFACE_
12 #include <FrameworkDxe.h>
13 #include <IndustryStandard/Pci.h>
14 #include <IndustryStandard/SmBios.h>
15 #include <IndustryStandard/Acpi10.h>
17 #include <Guid/SmBios.h>
18 #include <Guid/Acpi.h>
19 #include <Guid/DxeServices.h>
20 #include <Guid/LegacyBios.h>
21 #include <Guid/StatusCodeDataTypeId.h>
22 #include <Guid/ImageAuthentication.h>
24 #include <Protocol/BlockIo.h>
25 #include <Protocol/LoadedImage.h>
26 #include <Protocol/PciIo.h>
27 #include <Protocol/Cpu.h>
28 #include <Protocol/Timer.h>
29 #include <Protocol/IsaIo.h>
30 #include <Protocol/LegacyRegion2.h>
31 #include <Protocol/SimpleTextIn.h>
32 #include <Protocol/LegacyInterrupt.h>
33 #include <Protocol/LegacyBios.h>
34 #include <Protocol/DiskInfo.h>
35 #include <Protocol/GenericMemoryTest.h>
36 #include <Protocol/LegacyBiosPlatform.h>
37 #include <Protocol/DevicePath.h>
38 #include <Protocol/Legacy8259.h>
39 #include <Protocol/PciRootBridgeIo.h>
40 #include <Protocol/SerialIo.h>
41 #include <Protocol/SuperIo.h>
42 #include <Protocol/IoMmu.h>
44 #include <Library/BaseLib.h>
45 #include <Library/DebugLib.h>
46 #include <Library/UefiLib.h>
47 #include <Library/BaseMemoryLib.h>
48 #include <Library/ReportStatusCodeLib.h>
49 #include <Library/UefiRuntimeServicesTableLib.h>
50 #include <Library/HobLib.h>
51 #include <Library/UefiDriverEntryPoint.h>
52 #include <Library/MemoryAllocationLib.h>
53 #include <Library/UefiBootServicesTableLib.h>
54 #include <Library/IoLib.h>
55 #include <Library/PcdLib.h>
56 #include <Library/DevicePathLib.h>
57 #include <Library/DxeServicesTableLib.h>
58 #include <Library/DebugAgentLib.h>
61 // BUGBUG: This entry maybe changed to PCD in future and wait for
62 // redesign of BDS library
64 #define MAX_BBS_ENTRIES 0x100
68 // (These apply only to errors with the thunk and not to the code that was
72 #define THUNK_ERR_A20_UNSUP 0x01
73 #define THUNK_ERR_A20_FAILED 0x02
76 // Vector base definitions
79 // 8259 Hardware definitions
81 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
82 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
85 // The original PC used INT8-F for master PIC. Since these mapped over
86 // processor exceptions TIANO moved the master PIC to INT68-6F.
88 // The vector base for slave PIC is set as 0x70 for PC-AT compatibility.
90 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
91 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
94 // When we call CSM16 functions, some CSM16 use es:[offset + 0xabcd] to get data passed from CSM32,
95 // offset + 0xabcd could overflow which exceeds 0xFFFF which is invalid in real mode.
96 // So this will keep offset as small as possible to avoid offset overflow in real mode.
98 #define NORMALIZE_EFI_SEGMENT(_Adr) (UINT16) (((UINTN) (_Adr)) >> 4)
99 #define NORMALIZE_EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xf)
105 #define LEGACY_BDA_TRACE 0x000
106 #define LEGACY_BIOS_TRACE 0x040
107 #define LEGACY_BOOT_TRACE 0x080
108 #define LEGACY_CMOS_TRACE 0x0C0
109 #define LEGACY_IDE_TRACE 0x100
110 #define LEGACY_MP_TRACE 0x140
111 #define LEGACY_PCI_TRACE 0x180
112 #define LEGACY_SIO_TRACE 0x1C0
114 #define LEGACY_PCI_TRACE_000 LEGACY_PCI_TRACE + 0x00
115 #define LEGACY_PCI_TRACE_001 LEGACY_PCI_TRACE + 0x01
116 #define LEGACY_PCI_TRACE_002 LEGACY_PCI_TRACE + 0x02
117 #define LEGACY_PCI_TRACE_003 LEGACY_PCI_TRACE + 0x03
118 #define LEGACY_PCI_TRACE_004 LEGACY_PCI_TRACE + 0x04
119 #define LEGACY_PCI_TRACE_005 LEGACY_PCI_TRACE + 0x05
120 #define LEGACY_PCI_TRACE_006 LEGACY_PCI_TRACE + 0x06
121 #define LEGACY_PCI_TRACE_007 LEGACY_PCI_TRACE + 0x07
122 #define LEGACY_PCI_TRACE_008 LEGACY_PCI_TRACE + 0x08
123 #define LEGACY_PCI_TRACE_009 LEGACY_PCI_TRACE + 0x09
124 #define LEGACY_PCI_TRACE_00A LEGACY_PCI_TRACE + 0x0A
125 #define LEGACY_PCI_TRACE_00B LEGACY_PCI_TRACE + 0x0B
126 #define LEGACY_PCI_TRACE_00C LEGACY_PCI_TRACE + 0x0C
127 #define LEGACY_PCI_TRACE_00D LEGACY_PCI_TRACE + 0x0D
128 #define LEGACY_PCI_TRACE_00E LEGACY_PCI_TRACE + 0x0E
129 #define LEGACY_PCI_TRACE_00F LEGACY_PCI_TRACE + 0x0F
131 #define BDA_VIDEO_MODE 0x49
133 #define IDE_PI_REGISTER_PNE BIT0
134 #define IDE_PI_REGISTER_SNE BIT2
141 UINT32 ShadowAddress
;
145 } ROM_INSTANCE_ENTRY
;
148 // Values for RealModeGdt
150 #if defined (MDE_CPU_IA32)
152 #define NUM_REAL_GDT_ENTRIES 3
153 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
154 #define INITIAL_VALUE_BELOW_1K 0x0
156 #elif defined (MDE_CPU_X64)
158 #define NUM_REAL_GDT_ENTRIES 8
159 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
160 #define INITIAL_VALUE_BELOW_1K 0x0
167 // Define what a processor GDT looks like
180 UINT32 DefaultSize
: 1;
181 UINT32 Granularity
: 1;
195 // Define what a processor descriptor looks like
196 // This data structure must be kept in sync with ASM STRUCT in Thunk.inc
211 #define LOW_STACK_SIZE (8 * 1024) // 8k?
212 #define EFI_MAX_E820_ENTRY 100
213 #define FIRST_INSTANCE 1
214 #define NOT_FIRST_INSTANCE 0
216 #if defined (MDE_CPU_IA32)
219 // Space for the code
220 // The address of Code is also the beginning of the relocated Thunk code
222 CHAR8 Code
[4096]; // ?
224 // The address of the Reverse Thunk code
225 // Note that this member CONTAINS the address of the relocated reverse thunk
226 // code unlike the member variable 'Code', which IS the address of the Thunk
229 UINT32 LowReverseThunkStart
;
232 // Data for the code (cs releative)
234 DESCRIPTOR32 GdtDesc
; // Protected mode GDT
235 DESCRIPTOR32 IdtDesc
; // Protected mode IDT
239 UINT32 LowCodeSelector
; // Low code selector in GDT
240 UINT32 LowDataSelector
; // Low data selector in GDT
242 DESCRIPTOR32 RealModeIdtDesc
;
245 // real-mode GDT (temporary GDT with two real mode segment descriptors)
247 GDT32 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
248 DESCRIPTOR32 RealModeGdtDesc
;
251 // Members specifically for the reverse thunk
252 // The RevReal* members are used to store the current state of real mode
253 // before performing the reverse thunk. The RevFlat* members must be set
254 // before calling the reverse thunk assembly code.
259 DESCRIPTOR32 RevRealIdtDesc
;
260 UINT16 RevFlatDataSelector
; // Flat data selector in GDT
264 // A low memory stack
266 CHAR8 Stack
[LOW_STACK_SIZE
];
269 // Stack for flat mode after reverse thunk
270 // @bug - This may no longer be necessary if the reverse thunk interface
271 // is changed to have the flat stack in a different location.
273 CHAR8 RevThunkStack
[LOW_STACK_SIZE
];
276 // Legacy16 Init memory map info
278 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
280 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
282 CHAR8 InterruptRedirectionCode
[32];
283 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
284 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
285 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
288 #elif defined (MDE_CPU_X64)
292 // Space for the code
293 // The address of Code is also the beginning of the relocated Thunk code
295 CHAR8 Code
[4096]; // ?
298 // Data for the code (cs releative)
300 DESCRIPTOR64 X64GdtDesc
; // Protected mode GDT
301 DESCRIPTOR64 X64IdtDesc
; // Protected mode IDT
306 DESCRIPTOR32 RealModeIdtDesc
;
307 DESCRIPTOR32 RealModeGdtDesc
;
310 // real-mode GDT (temporary GDT with two real mode segment descriptors)
312 GDT64 RealModeGdt
[NUM_REAL_GDT_ENTRIES
];
313 UINT64 PageMapLevel4
;
316 // A low memory stack
318 CHAR8 Stack
[LOW_STACK_SIZE
];
321 // Legacy16 Init memory map info
323 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable
;
325 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable
;
327 CHAR8 InterruptRedirectionCode
[32];
328 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler
;
329 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable
;
330 BBS_TABLE BbsTable
[MAX_BBS_ENTRIES
];
336 // PnP Expansion Header
347 UINT16 ProductNamePointer
;
351 UINT8 DeviceIndicators
;
353 UINT16 DisconnectVector
;
356 UINT16 StaticResourceVector
;
357 } LEGACY_PNP_EXPANSION_HEADER
;
373 UINTN ManufacturerString
;
374 UINTN ProductNameString
;
375 } LEGACY_ROM_AND_BBS_TABLE
;
378 // Structure how EFI has mapped a devices HDD drive numbers.
379 // Boot to EFI aware OS or shell requires this mapping when
380 // 16-bit CSM assigns drive numbers.
381 // This mapping is ignored booting to a legacy OS.
388 UINT8 StartDriveNumber
;
389 UINT8 EndDriveNumber
;
390 } LEGACY_EFI_HDD_TABLE
;
393 // This data is passed to Leacy16Boot
396 EfiAcpiAddressRangeMemory
= 1,
397 EfiAcpiAddressRangeReserved
= 2,
398 EfiAcpiAddressRangeACPI
= 3,
399 EfiAcpiAddressRangeNVS
= 4,
400 EfiAddressRangePersistentMemory
= 7
401 } EFI_ACPI_MEMORY_TYPE
;
406 EFI_ACPI_MEMORY_TYPE Type
;
414 EFI_ACPI_MEMORY_TYPE Type
;
419 extern BBS_TABLE
*mBbsTable
;
421 extern EFI_GENERIC_MEMORY_TEST_PROTOCOL
*gGenMemoryTest
;
423 extern BOOLEAN mEndOfDxe
;
428 #define CMOS_0A 0x0a ///< Status register A
429 #define CMOS_0D 0x0d ///< Status register D
430 #define CMOS_0E 0x0e ///< Diagnostic Status
431 #define CMOS_0F 0x0f ///< Shutdown status
432 #define CMOS_10 0x10 ///< Floppy type
433 #define CMOS_12 0x12 ///< IDE type
434 #define CMOS_14 0x14 ///< Same as BDA 40:10
435 #define CMOS_15 0x15 ///< Low byte of base memory in 1k increments
436 #define CMOS_16 0x16 ///< High byte of base memory in 1k increments
437 #define CMOS_17 0x17 ///< Low byte of 1MB+ memory in 1k increments - max 15 MB
438 #define CMOS_18 0x18 ///< High byte of 1MB+ memory in 1k increments - max 15 MB
439 #define CMOS_19 0x19 ///< C: extended drive type
440 #define CMOS_1A 0x1a ///< D: extended drive type
441 #define CMOS_2E 0x2e ///< Most significient byte of standard checksum
442 #define CMOS_2F 0x2f ///< Least significient byte of standard checksum
443 #define CMOS_30 0x30 ///< CMOS 0x17
444 #define CMOS_31 0x31 ///< CMOS 0x18
445 #define CMOS_32 0x32 ///< Century byte
448 // 8254 Timer registers
450 #define TIMER0_COUNT_PORT 0x40
451 #define TIMER1_COUNT_PORT 0x41
452 #define TIMER2_COUNT_PORT 0x42
453 #define TIMER_CONTROL_PORT 0x43
456 // Timer 0, Read/Write LSB then MSB, Square wave output, binary count use.
458 #define TIMER0_CONTROL_WORD 0x36
460 #define LEGACY_BIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('L', 'B', 'I', 'T')
465 EFI_LEGACY_BIOS_PROTOCOL LegacyBios
;
467 EFI_HANDLE ImageHandle
;
470 // CPU Architectural Protocol
472 EFI_CPU_ARCH_PROTOCOL
*Cpu
;
475 // Timer Architectural Protocol
477 EFI_TIMER_ARCH_PROTOCOL
*Timer
;
478 BOOLEAN TimerUses8254
;
481 // Protocol to Lock and Unlock 0xc0000 - 0xfffff
483 EFI_LEGACY_REGION2_PROTOCOL
*LegacyRegion
;
485 EFI_LEGACY_BIOS_PLATFORM_PROTOCOL
*LegacyBiosPlatform
;
488 // Interrupt control for thunk and PCI IRQ
490 EFI_LEGACY_8259_PROTOCOL
*Legacy8259
;
493 // PCI Interrupt PIRQ control
495 EFI_LEGACY_INTERRUPT_PROTOCOL
*LegacyInterrupt
;
498 // Generic Memory Test
500 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenericMemoryTest
;
503 // TRUE if PCI Interrupt Line registers have been programmed.
505 BOOLEAN PciInterruptLine
;
508 // Code space below 1MB needed by thunker to transition to real mode.
509 // Contains stack and real mode code fragments
511 LOW_MEMORY_THUNK
*IntThunk
;
514 // Starting shadow address of the Legacy BIOS
517 UINT32 LegacyBiosImageSize
;
520 // Start of variables used by CsmItp.mac ITP macro file and/os LegacyBios
525 // $EFI Legacy16 code entry info in memory < 1 MB;
527 EFI_COMPATIBILITY16_TABLE
*Legacy16Table
;
528 VOID
*Legacy16InitPtr
;
529 VOID
*Legacy16BootPtr
;
530 VOID
*InternalIrqRoutingTable
;
531 UINT32 NumberIrqRoutingEntries
;
534 UINT32 NumberHddControllers
;
537 // Cached copy of Legacy16 entry point
539 UINT16 Legacy16CallSegment
;
540 UINT16 Legacy16CallOffset
;
543 // Returned from $EFI and passed in to OPROMS
545 UINT16 PnPInstallationCheckSegment
;
546 UINT16 PnPInstallationCheckOffset
;
551 EFI_E820_ENTRY E820Table
[EFI_MAX_E820_ENTRY
];
552 UINT32 NumberE820Entries
;
555 // True if legacy VGA INT 10h handler installed
557 BOOLEAN VgaInstalled
;
560 // Number of IDE drives
565 // Current Free Option ROM space. An option ROM must NOT go past
571 // Save Legacy16 unexpected interrupt vector. Reprogram INT 68-6F from
572 // EFI values to legacy value just before boot.
574 UINT32 BiosUnexpectedInt
;
575 UINT32 ThunkSavedInt
[8];
577 LEGACY_EFI_HDD_TABLE
*LegacyEfiHddTable
;
578 UINT16 LegacyEfiHddTableIndex
;
585 // Indicate that whether GenericLegacyBoot is entered or not
587 BOOLEAN LegacyBootEntered
;
590 // CSM16 PCI Interface Version
592 UINT16 Csm16PciInterfaceVersion
;
593 } LEGACY_BIOS_INSTANCE
;
605 40:0E-0E Ebda segment
606 40:10-11 MachineConfig
608 40:13-14 MemSize below 1MB
609 40:15-16 Bda15_16 - skip
610 40:17 Keyboard Shift status
611 40:18-19 Bda18_19 - skip
612 40:1A-1B Key buffer head
613 40:1C-1D Key buffer tail
614 40:1E-3D Bda1E_3D- key buffer -skip
615 40:3E-3F FloppyData 3E = Calibration status 3F = Motor status
617 40:41-74 Bda41_74 - skip
618 40:75 Number of HDD drives
619 40:76-77 Bda76_77 - skip
620 40:78-79 78 = Lpt1 timeout, 79 = Lpt2 timeout
621 40:7A-7B 7A = Lpt3 timeout, 7B = Lpt4 timeout
622 40:7C-7D 7C = Com1 timeout, 7D = Com2 timeout
623 40:7E-7F 7E = Com3 timeout, 7F = Com4 timeout
624 40:80-81 Pointer to start of key buffer
625 40:82-83 Pointer to end of key buffer
626 40:84-87 Bda84_87 - skip
627 40:88 HDD Data Xmit rate
629 40:90 Floppy data rate
631 40:96 Keyboard Status
644 UINT16 MachineConfig
;
647 UINT8 Bda15_16
[0x02];
649 UINT8 Bda18_19
[0x02];
652 UINT16 Bda1E_3D
[0x10];
655 UINT8 Bda41_74
[0x34];
656 UINT8 NumberOfDrives
;
657 UINT8 Bda76_77
[0x02];
658 UINT16 Lpt1_2Timeout
;
659 UINT16 Lpt3_4Timeout
;
660 UINT16 Com1_2Timeout
;
661 UINT16 Com3_4Timeout
;
666 UINT8 Bda89_8F
[0x07];
668 UINT8 Bda91_95
[0x05];
669 UINT8 KeyboardStatus
;
674 #define LEGACY_BIOS_INSTANCE_FROM_THIS(this) CR (this, LEGACY_BIOS_INSTANCE, LegacyBios, LEGACY_BIOS_INSTANCE_SIGNATURE)
677 Thunk to 16-bit real mode and execute a software interrupt with a vector
678 of BiosInt. Regs will contain the 16-bit register context on entry and
681 @param This Protocol instance pointer.
682 @param BiosInt Processor interrupt vector to invoke
683 @param Regs Register contexted passed into (and returned) from thunk to
686 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
688 @retval TRUE There was a BIOS erro in the target code.
694 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
696 IN EFI_IA32_REGISTER_SET
*Regs
700 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
701 16-bit register context on entry and exit. Arguments can be passed on
704 @param This Protocol instance pointer.
705 @param Segment Segment of 16-bit mode call
706 @param Offset Offset of 16-bit mdoe call
707 @param Regs Register contexted passed into (and returned) from
709 @param Stack Caller allocated stack used to pass arguments
710 @param StackSize Size of Stack in bytes
712 @retval FALSE Thunk completed, and there were no BIOS errors in
713 the target code. See Regs for status.
714 @retval TRUE There was a BIOS erro in the target code.
719 LegacyBiosFarCall86 (
720 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
723 IN EFI_IA32_REGISTER_SET
*Regs
,
729 Test to see if a legacy PCI ROM exists for this device. Optionally return
730 the Legacy ROM instance for this PCI device.
732 @param This Protocol instance pointer.
733 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
735 @param RomImage Return the legacy PCI ROM for this device
736 @param RomSize Size of ROM Image
737 @param Flags Indicates if ROM found and if PC-AT.
739 @retval EFI_SUCCESS Legacy Option ROM available for this device
740 @retval EFI_UNSUPPORTED Legacy Option ROM not supported.
745 LegacyBiosCheckPciRom (
746 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
747 IN EFI_HANDLE PciHandle
,
748 OUT VOID
**RomImage OPTIONAL
,
749 OUT UINTN
*RomSize OPTIONAL
,
754 Assign drive number to legacy HDD drives prior to booting an EFI
755 aware OS so the OS can access drives without an EFI driver.
756 Note: BBS compliant drives ARE NOT available until this call by
759 @param This Protocol instance pointer.
760 @param BbsCount Number of BBS_TABLE structures
761 @param BbsTable List BBS entries
763 @retval EFI_SUCCESS Drive numbers assigned
768 LegacyBiosPrepareToBootEfi (
769 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
770 OUT UINT16
*BbsCount
,
771 OUT BBS_TABLE
**BbsTable
775 To boot from an unconventional device like parties and/or execute
778 @param This Protocol instance pointer.
779 @param Attributes How to interpret the other input parameters
780 @param BbsEntry The 0-based index into the BbsTable for the parent
782 @param BeerData Pointer to the 128 bytes of ram BEER data.
783 @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
784 The caller must provide a pointer to the specific
785 Service Area and not the start all Service Areas.
786 EFI_INVALID_PARAMETER if error. Does NOT return if no error.
791 LegacyBiosBootUnconventionalDevice (
792 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
793 IN UDC_ATTRIBUTES Attributes
,
796 IN VOID
*ServiceAreaData
800 Load a legacy PC-AT OPROM on the PciHandle device. Return information
801 about how many disks were added by the OPROM and the shadow address and
802 size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
804 @param This Protocol instance pointer.
805 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
806 be loaded. This value is NULL if RomImage is
807 non-NULL. This is the normal case.
808 @param RomImage A PCI PC-AT ROM image. This argument is non-NULL
809 if there is no hardware associated with the ROM
810 and thus no PciHandle, otherwise is must be NULL.
811 Example is PXE base code.
812 @param Flags Indicates if ROM found and if PC-AT.
813 @param DiskStart Disk number of first device hooked by the ROM. If
814 DiskStart is the same as DiskEnd no disked were
816 @param DiskEnd Disk number of the last device hooked by the ROM.
817 @param RomShadowAddress Shadow address of PC-AT ROM
818 @param RomShadowedSize Size of RomShadowAddress in bytes
820 @retval EFI_SUCCESS Legacy ROM loaded for this device
821 @retval EFI_INVALID_PARAMETER PciHandle not found
822 @retval EFI_UNSUPPORTED There is no PCI ROM in the ROM BAR or no onboard
828 LegacyBiosInstallPciRom (
829 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
830 IN EFI_HANDLE PciHandle
,
833 OUT UINT8
*DiskStart OPTIONAL
,
834 OUT UINT8
*DiskEnd OPTIONAL
,
835 OUT VOID
**RomShadowAddress OPTIONAL
,
836 OUT UINT32
*RomShadowedSize OPTIONAL
840 Fill in the standard BDA for Keyboard LEDs
842 @param This Protocol instance pointer.
843 @param Leds Current LED status
845 @retval EFI_SUCCESS It should always work.
850 LegacyBiosUpdateKeyboardLedStatus (
851 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
858 @param This Protocol instance pointer.
859 @param HddCount Number of HDD_INFO structures
860 @param HddInfo Onboard IDE controller information
861 @param BbsCount Number of BBS_TABLE structures
862 @param BbsTable List BBS entries
864 @retval EFI_SUCCESS Tables returned
865 @retval EFI_NOT_FOUND resource not found
866 @retval EFI_DEVICE_ERROR can not get BBS table
871 LegacyBiosGetBbsInfo (
872 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
873 OUT UINT16
*HddCount
,
874 OUT HDD_INFO
**HddInfo
,
875 OUT UINT16
*BbsCount
,
876 OUT BBS_TABLE
**BbsTable
880 Shadow all legacy16 OPROMs that haven't been shadowed.
881 Warning: Use this with caution. This routine disconnects all EFI
882 drivers. If used externally then caller must re-connect EFI
885 @param This Protocol instance pointer.
887 @retval EFI_SUCCESS OPROMs shadowed
892 LegacyBiosShadowAllLegacyOproms (
893 IN EFI_LEGACY_BIOS_PROTOCOL
*This
897 Attempt to legacy boot the BootOption. If the EFI contexted has been
898 compromised this function will not return.
900 @param This Protocol instance pointer.
901 @param BbsDevicePath EFI Device Path from BootXXXX variable.
902 @param LoadOptionsSize Size of LoadOption in size.
903 @param LoadOptions LoadOption from BootXXXX variable
905 @retval EFI_SUCCESS Removable media not present
910 LegacyBiosLegacyBoot (
911 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
912 IN BBS_BBS_DEVICE_PATH
*BbsDevicePath
,
913 IN UINT32 LoadOptionsSize
,
918 Allocate memory < 1 MB and copy the thunker code into low memory. Se up
921 @param Private Private context for Legacy BIOS
923 @retval EFI_SUCCESS Should only pass.
927 LegacyBiosInitializeThunk (
928 IN LEGACY_BIOS_INSTANCE
*Private
932 Fill in the standard BDA and EBDA stuff before Legacy16 load
934 @param Private Legacy BIOS Instance data
936 @retval EFI_SUCCESS It should always work.
941 IN LEGACY_BIOS_INSTANCE
*Private
945 Collect IDE Inquiry data from the IDE disks
947 @param Private Legacy BIOS Instance data
948 @param HddInfo Hdd Information
949 @param Flag Reconnect IdeController or not
951 @retval EFI_SUCCESS It should always work.
955 LegacyBiosBuildIdeData (
956 IN LEGACY_BIOS_INSTANCE
*Private
,
957 IN HDD_INFO
**HddInfo
,
962 Enable ide controller. This gets disabled when LegacyBoot.c is about
963 to run the Option ROMs.
965 @param Private Legacy BIOS Instance data
970 EnableIdeController (
971 IN LEGACY_BIOS_INSTANCE
*Private
975 If the IDE channel is in compatibility (legacy) mode, remove all
976 PCI I/O BAR addresses from the controller.
978 @param IdeController The handle of target IDE controller
983 InitLegacyIdeController (
984 IN EFI_HANDLE IdeController
988 Program the interrupt routing register in all the PCI devices. On a PC AT system
989 this register contains the 8259 IRQ vector that matches its PCI interrupt.
991 @param Private Legacy BIOS Instance data
993 @retval EFI_SUCCESS Succeed.
994 @retval EFI_ALREADY_STARTED All PCI devices have been processed.
998 PciProgramAllInterruptLineRegisters (
999 IN LEGACY_BIOS_INSTANCE
*Private
1003 Collect EFI Info about legacy devices.
1005 @param Private Legacy BIOS Instance data
1007 @retval EFI_SUCCESS It should always work.
1011 LegacyBiosBuildSioData (
1012 IN LEGACY_BIOS_INSTANCE
*Private
1016 Shadow all the PCI legacy ROMs. Use data from the Legacy BIOS Protocol
1017 to chose the order. Skip any devices that have already have legacy
1020 @param Private Protocol instance pointer.
1022 @retval EFI_SUCCESS Succeed.
1023 @retval EFI_UNSUPPORTED Cannot get VGA device handle.
1028 IN LEGACY_BIOS_INSTANCE
*Private
1032 Fill in the standard BDA and EBDA stuff prior to legacy Boot
1034 @param Private Legacy BIOS Instance data
1036 @retval EFI_SUCCESS It should always work.
1040 LegacyBiosCompleteBdaBeforeBoot (
1041 IN LEGACY_BIOS_INSTANCE
*Private
1045 Fill in the standard CMOS stuff before Legacy16 load
1047 @param Private Legacy BIOS Instance data
1049 @retval EFI_SUCCESS It should always work.
1053 LegacyBiosInitCmos (
1054 IN LEGACY_BIOS_INSTANCE
*Private
1058 Fill in the standard CMOS stuff prior to legacy Boot
1060 @param Private Legacy BIOS Instance data
1062 @retval EFI_SUCCESS It should always work.
1066 LegacyBiosCompleteStandardCmosBeforeBoot (
1067 IN LEGACY_BIOS_INSTANCE
*Private
1071 Contains the code that is copied into low memory (below 640K).
1072 This code reflects interrupts 0x68-0x6f to interrupts 0x08-0x0f.
1073 This template must be copied into low memory, and the IDT entries
1074 0x68-0x6F must be point to the low memory copy of this code. Each
1075 entry is 4 bytes long, so IDT entries 0x68-0x6F can be easily
1080 InterruptRedirectionTemplate (
1085 Build the E820 table.
1087 @param Private Legacy BIOS Instance data
1088 @param Size Size of E820 Table
1090 @retval EFI_SUCCESS It should always work.
1094 LegacyBiosBuildE820 (
1095 IN LEGACY_BIOS_INSTANCE
*Private
,
1100 This function is to put all AP in halt state.
1102 @param Private Legacy BIOS Instance data
1107 IN LEGACY_BIOS_INSTANCE
*Private
1111 Worker function for LegacyBiosGetFlatDescs, retrieving content of
1114 @param IntThunk Pointer to IntThunk of Legacy BIOS context.
1119 LOW_MEMORY_THUNK
*IntThunk
1123 Routine for calling real thunk code.
1125 @param RealCode The address of thunk code.
1126 @param BiosInt The Bios interrupt vector number.
1127 @param CallAddress The address of 16-bit mode call.
1129 @return Status returned by real thunk code
1140 Routine for generating soft interrupt.
1142 @param Vector The interrupt vector number.
1151 Allocate memory for legacy usage.
1153 @param AllocateType The type of allocation to perform.
1154 @param MemoryType The type of memory to allocate.
1155 @param StartPageAddress Start address of range
1156 @param Pages Number of pages to allocate
1157 @param Result Result of allocation
1159 @retval EFI_SUCCESS Legacy16 code loaded
1160 @retval Other No protocol installed, unload driver.
1164 AllocateLegacyMemory (
1165 IN EFI_ALLOCATE_TYPE AllocateType
,
1166 IN EFI_MEMORY_TYPE MemoryType
,
1167 IN EFI_PHYSICAL_ADDRESS StartPageAddress
,
1169 OUT EFI_PHYSICAL_ADDRESS
*Result
1173 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1175 @param This Protocol instance pointer.
1176 @param LegacyMemorySize Size of required region
1177 @param Region Region to use. 00 = Either 0xE0000 or 0xF0000
1178 block Bit0 = 1 0xF0000 block Bit1 = 1 0xE0000
1180 @param Alignment Address alignment. Bit mapped. First non-zero
1181 bit from right is alignment.
1182 @param LegacyMemoryAddress Region Assigned
1184 @retval EFI_SUCCESS Region assigned
1185 @retval EFI_ACCESS_DENIED Procedure previously invoked
1186 @retval Other Region not assigned
1191 LegacyBiosGetLegacyRegion (
1192 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1193 IN UINTN LegacyMemorySize
,
1196 OUT VOID
**LegacyMemoryAddress
1200 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1202 @param This Protocol instance pointer.
1203 @param LegacyMemorySize Size of data to copy
1204 @param LegacyMemoryAddress Legacy Region destination address Note: must
1205 be in region assigned by
1206 LegacyBiosGetLegacyRegion
1207 @param LegacyMemorySourceAddress Source of data
1209 @retval EFI_SUCCESS Region assigned
1210 @retval EFI_ACCESS_DENIED Destination outside assigned region
1215 LegacyBiosCopyLegacyRegion (
1216 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1217 IN UINTN LegacyMemorySize
,
1218 IN VOID
*LegacyMemoryAddress
,
1219 IN VOID
*LegacyMemorySourceAddress
1223 Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
1224 the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
1227 @param Private Legacy BIOS context data
1229 @retval EFI_SUCCESS Legacy16 code loaded
1230 @retval Other No protocol installed, unload driver.
1234 ShadowAndStartLegacy16 (
1235 IN LEGACY_BIOS_INSTANCE
*Private
1239 Checks the state of the floppy and if media is inserted.
1241 This routine checks the state of the floppy and if media is inserted.
1243 No floppy present - Set BBS entry to ignore
1244 Floppy present & no media - Set BBS entry to lowest priority. We cannot
1245 set it to ignore since 16-bit CSM will
1246 indicate no floppy and thus drive A: is
1247 unusable. CSM-16 will not try floppy since
1248 lowest priority and thus not incur boot
1250 Floppy present & media - Set BBS entry to some priority.
1252 @return State of floppy media
1261 Identify drive data must be updated to actual parameters before boot.
1262 This requires updating the checksum, if it exists.
1264 @param IdentifyDriveData ATA Identify Data
1265 @param Checksum checksum of the ATA Identify Data
1267 @retval EFI_SUCCESS checksum calculated
1268 @retval EFI_SECURITY_VIOLATION IdentifyData invalid
1272 CalculateIdentifyDriveChecksum (
1273 IN UINT8
*IdentifyDriveData
,
1278 Identify drive data must be updated to actual parameters before boot.
1280 @param IdentifyDriveData ATA Identify Data
1284 UpdateIdentifyDriveData (
1285 IN UINT8
*IdentifyDriveData
1289 Complete build of BBS TABLE.
1291 @param Private Legacy BIOS Instance data
1292 @param BbsTable BBS Table passed to 16-bit code
1294 @retval EFI_SUCCESS Removable media not present
1298 LegacyBiosBuildBbs (
1299 IN LEGACY_BIOS_INSTANCE
*Private
,
1300 IN BBS_TABLE
*BbsTable
1304 Read CMOS register through index/data port.
1306 @param[in] Index The index of the CMOS register to read.
1308 @return The data value from the CMOS register specified by Index.
1312 LegacyReadStandardCmos (
1317 Write CMOS register through index/data port.
1319 @param[in] Index The index of the CMOS register to write.
1320 @param[in] Value The value of CMOS register to write.
1322 @return The value written to the CMOS register specified by Index.
1326 LegacyWriteStandardCmos (
1332 Calculate the new standard CMOS checksum and write it.
1334 @param Private Legacy BIOS Instance data
1336 @retval EFI_SUCCESS Calculate 16-bit checksum successfully
1340 LegacyCalculateWriteStandardCmosChecksum (
1345 Test to see if a legacy PCI ROM exists for this device. Optionally return
1346 the Legacy ROM instance for this PCI device.
1348 @param[in] This Protocol instance pointer.
1349 @param[in] PciHandle The PCI PC-AT OPROM from this devices ROM BAR will be loaded
1350 @param[out] RomImage Return the legacy PCI ROM for this device
1351 @param[out] RomSize Size of ROM Image
1352 @param[out] RuntimeImageLength Runtime size of ROM Image
1353 @param[out] Flags Indicates if ROM found and if PC-AT.
1354 @param[out] OpromRevision Revision of the PCI Rom
1355 @param[out] ConfigUtilityCodeHeaderPointer of Configuration Utility Code Header
1357 @return EFI_SUCCESS Legacy Option ROM available for this device
1358 @return EFI_ALREADY_STARTED This device is already managed by its Oprom
1359 @return EFI_UNSUPPORTED Legacy Option ROM not supported.
1363 LegacyBiosCheckPciRomEx (
1364 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1365 IN EFI_HANDLE PciHandle
,
1366 OUT VOID
**RomImage OPTIONAL
,
1367 OUT UINTN
*RomSize OPTIONAL
,
1368 OUT UINTN
*RuntimeImageLength OPTIONAL
,
1369 OUT UINTN
*Flags OPTIONAL
,
1370 OUT UINT8
*OpromRevision OPTIONAL
,
1371 OUT VOID
**ConfigUtilityCodeHeader OPTIONAL
1375 Relocate this image under 4G memory for IPF.
1377 @param ImageHandle Handle of driver image.
1378 @param SystemTable Pointer to system table.
1380 @retval EFI_SUCCESS Image successfully relocated.
1381 @retval EFI_ABORTED Failed to relocate image.
1385 RelocateImageUnder4GIfNeeded (
1386 IN EFI_HANDLE ImageHandle
,
1387 IN EFI_SYSTEM_TABLE
*SystemTable
1391 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
1392 16-bit register context on entry and exit. Arguments can be passed on
1395 @param This Protocol instance pointer.
1396 @param Segment Segment of 16-bit mode call
1397 @param Offset Offset of 16-bit mdoe call
1398 @param Regs Register contexted passed into (and returned) from thunk to
1400 @param Stack Caller allocated stack used to pass arguments
1401 @param StackSize Size of Stack in bytes
1403 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
1404 See Regs for status.
1405 @retval TRUE There was a BIOS erro in the target code.
1410 InternalLegacyBiosFarCall (
1411 IN EFI_LEGACY_BIOS_PROTOCOL
*This
,
1414 IN EFI_IA32_REGISTER_SET
*Regs
,
1420 Load a legacy PC-AT OpROM for VGA controller.
1422 @param Private Driver private data.
1424 @retval EFI_SUCCESS Legacy ROM successfully installed for this device.
1425 @retval EFI_DEVICE_ERROR No VGA device handle found, or native EFI video
1426 driver cannot be successfully disconnected, or VGA
1427 thunk driver cannot be successfully connected.
1431 LegacyBiosInstallVgaRom (
1432 IN LEGACY_BIOS_INSTANCE
*Private