]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBiosInterface.h
When CSM uses EFI_SEGMENT and EFI_OFFSET to call CSM16 function, some CSM16 use es...
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyBiosInterface.h
1 /** @file
2
3 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
4
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
10
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.
13
14 **/
15
16 #ifndef _LEGACY_BIOS_INTERFACE_
17 #define _LEGACY_BIOS_INTERFACE_
18
19
20 #include <FrameworkDxe.h>
21
22 #include <Guid/SmBios.h>
23 #include <Guid/Acpi.h>
24 #include <Guid/DxeServices.h>
25 #include <Guid/LegacyBios.h>
26 #include <Guid/StatusCodeDataTypeId.h>
27
28 #include <Protocol/BlockIo.h>
29 #include <Protocol/LoadedImage.h>
30 #include <Protocol/PciIo.h>
31 #include <Protocol/Cpu.h>
32 #include <Protocol/Timer.h>
33 #include <Protocol/IsaIo.h>
34 #include <Protocol/LegacyRegion2.h>
35 #include <Protocol/SimpleTextIn.h>
36 #include <Protocol/LegacyInterrupt.h>
37 #include <Protocol/LegacyBios.h>
38 #include <Protocol/DiskInfo.h>
39 #include <Protocol/GenericMemoryTest.h>
40 #include <Protocol/LegacyBiosPlatform.h>
41 #include <Protocol/DevicePath.h>
42 #include <Protocol/Legacy8259.h>
43 #include <Protocol/PciRootBridgeIo.h>
44
45 #include <Library/BaseLib.h>
46 #include <Library/DebugLib.h>
47 #include <Library/UefiLib.h>
48 #include <Library/BaseMemoryLib.h>
49 #include <Library/ReportStatusCodeLib.h>
50 #include <Library/UefiRuntimeServicesTableLib.h>
51 #include <Library/HobLib.h>
52 #include <Library/UefiDriverEntryPoint.h>
53 #include <Library/MemoryAllocationLib.h>
54 #include <Library/UefiBootServicesTableLib.h>
55 #include <Library/IoLib.h>
56 #include <Library/PcdLib.h>
57 #include <Library/DevicePathLib.h>
58 #include <Library/DxeServicesTableLib.h>
59 #include <Library/PeCoffLib.h>
60 #include <Library/CacheMaintenanceLib.h>
61 #include <Library/DebugAgentLib.h>
62
63 //
64 // BUGBUG: This entry maybe changed to PCD in future and wait for
65 // redesign of BDS library
66 //
67 #define MAX_BBS_ENTRIES 0x100
68
69 //
70 // Thunk Status Codes
71 // (These apply only to errors with the thunk and not to the code that was
72 // thunked to.)
73 //
74 #define THUNK_OK 0x00
75 #define THUNK_ERR_A20_UNSUP 0x01
76 #define THUNK_ERR_A20_FAILED 0x02
77
78 //
79 // Vector base definitions
80 //
81 //
82 // 8259 Hardware definitions
83 //
84 #define LEGACY_MODE_BASE_VECTOR_MASTER 0x08
85 #define LEGACY_MODE_BASE_VECTOR_SLAVE 0x70
86
87 //
88 // The original PC used INT8-F for master PIC. Since these mapped over
89 // processor exceptions TIANO moved the master PIC to INT68-6F.
90 //
91 // The vector base for slave PIC is set as 0x70 for PC-AT compatibility.
92 //
93 #define PROTECTED_MODE_BASE_VECTOR_MASTER 0x68
94 #define PROTECTED_MODE_BASE_VECTOR_SLAVE 0x70
95
96 //
97 // When we call CSM16 functions, some CSM16 use es:[offset + 0xabcd] to get data passed from CSM32,
98 // offset + 0xabcd could overflow which exceeds 0xFFFF which is invalid in real mode.
99 // So this will keep offset as small as possible to avoid offset overflow in real mode.
100 //
101 #define NORMALIZE_EFI_SEGMENT(_Adr) (UINT16) (((UINTN) (_Adr)) >> 4)
102 #define NORMALIZE_EFI_OFFSET(_Adr) (UINT16) (((UINT16) ((UINTN) (_Adr))) & 0xf)
103
104 //
105 // Trace defines
106 //
107 //
108 #define LEGACY_BDA_TRACE 0x000
109 #define LEGACY_BIOS_TRACE 0x040
110 #define LEGACY_BOOT_TRACE 0x080
111 #define LEGACY_CMOS_TRACE 0x0C0
112 #define LEGACY_IDE_TRACE 0x100
113 #define LEGACY_MP_TRACE 0x140
114 #define LEGACY_PCI_TRACE 0x180
115 #define LEGACY_SIO_TRACE 0x1C0
116
117 #define LEGACY_PCI_TRACE_000 LEGACY_PCI_TRACE + 0x00
118 #define LEGACY_PCI_TRACE_001 LEGACY_PCI_TRACE + 0x01
119 #define LEGACY_PCI_TRACE_002 LEGACY_PCI_TRACE + 0x02
120 #define LEGACY_PCI_TRACE_003 LEGACY_PCI_TRACE + 0x03
121 #define LEGACY_PCI_TRACE_004 LEGACY_PCI_TRACE + 0x04
122 #define LEGACY_PCI_TRACE_005 LEGACY_PCI_TRACE + 0x05
123 #define LEGACY_PCI_TRACE_006 LEGACY_PCI_TRACE + 0x06
124 #define LEGACY_PCI_TRACE_007 LEGACY_PCI_TRACE + 0x07
125 #define LEGACY_PCI_TRACE_008 LEGACY_PCI_TRACE + 0x08
126 #define LEGACY_PCI_TRACE_009 LEGACY_PCI_TRACE + 0x09
127 #define LEGACY_PCI_TRACE_00A LEGACY_PCI_TRACE + 0x0A
128 #define LEGACY_PCI_TRACE_00B LEGACY_PCI_TRACE + 0x0B
129 #define LEGACY_PCI_TRACE_00C LEGACY_PCI_TRACE + 0x0C
130 #define LEGACY_PCI_TRACE_00D LEGACY_PCI_TRACE + 0x0D
131 #define LEGACY_PCI_TRACE_00E LEGACY_PCI_TRACE + 0x0E
132 #define LEGACY_PCI_TRACE_00F LEGACY_PCI_TRACE + 0x0F
133
134
135 typedef struct {
136 UINTN PciSegment;
137 UINTN PciBus;
138 UINTN PciDevice;
139 UINTN PciFunction;
140 UINT32 ShadowAddress;
141 UINT32 ShadowedSize;
142 UINT8 DiskStart;
143 UINT8 DiskEnd;
144 } ROM_INSTANCE_ENTRY;
145
146 //
147 // Values for RealModeGdt
148 //
149 #if defined (MDE_CPU_IA32)
150
151 #define NUM_REAL_GDT_ENTRIES 3
152 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
153 #define INITIAL_VALUE_BELOW_1K 0x0
154
155 #elif defined (MDE_CPU_X64)
156
157 #define NUM_REAL_GDT_ENTRIES 8
158 #define CONVENTIONAL_MEMORY_TOP 0xA0000 // 640 KB
159 #define INITIAL_VALUE_BELOW_1K 0x0
160
161 #elif defined (MDE_CPU_IPF)
162
163 #define NUM_REAL_GDT_ENTRIES 3
164 #define CONVENTIONAL_MEMORY_TOP 0x80000 // 512 KB
165 #define INITIAL_VALUE_BELOW_1K 0xff
166
167 #endif
168
169 #pragma pack(1)
170
171 //
172 // Define what a processor GDT looks like
173 //
174 typedef struct {
175 UINT32 LimitLo : 16;
176 UINT32 BaseLo : 16;
177 UINT32 BaseMid : 8;
178 UINT32 Type : 4;
179 UINT32 System : 1;
180 UINT32 Dpl : 2;
181 UINT32 Present : 1;
182 UINT32 LimitHi : 4;
183 UINT32 Software : 1;
184 UINT32 Reserved : 1;
185 UINT32 DefaultSize : 1;
186 UINT32 Granularity : 1;
187 UINT32 BaseHi : 8;
188 } GDT32;
189
190 typedef struct {
191 UINT16 LimitLow;
192 UINT16 BaseLow;
193 UINT8 BaseMid;
194 UINT8 Attribute;
195 UINT8 LimitHi;
196 UINT8 BaseHi;
197 } GDT64;
198
199 //
200 // Define what a processor descriptor looks like
201 // This data structure must be kept in sync with ASM STRUCT in Thunk.inc
202 //
203 typedef struct {
204 UINT16 Limit;
205 UINT64 Base;
206 } DESCRIPTOR64;
207
208 typedef struct {
209 UINT16 Limit;
210 UINT32 Base;
211 } DESCRIPTOR32;
212
213 //
214 // Low stub lay out
215 //
216 #define LOW_STACK_SIZE (8 * 1024) // 8k?
217 #define EFI_MAX_E820_ENTRY 100
218 #define FIRST_INSTANCE 1
219 #define NOT_FIRST_INSTANCE 0
220
221 #if defined (MDE_CPU_IA32)
222 typedef struct {
223 //
224 // Space for the code
225 // The address of Code is also the beginning of the relocated Thunk code
226 //
227 CHAR8 Code[4096]; // ?
228 //
229 // The address of the Reverse Thunk code
230 // Note that this member CONTAINS the address of the relocated reverse thunk
231 // code unlike the member variable 'Code', which IS the address of the Thunk
232 // code.
233 //
234 UINT32 LowReverseThunkStart;
235
236 //
237 // Data for the code (cs releative)
238 //
239 DESCRIPTOR32 GdtDesc; // Protected mode GDT
240 DESCRIPTOR32 IdtDesc; // Protected mode IDT
241 UINT32 FlatSs;
242 UINT32 FlatEsp;
243
244 UINT32 LowCodeSelector; // Low code selector in GDT
245 UINT32 LowDataSelector; // Low data selector in GDT
246 UINT32 LowStack;
247 DESCRIPTOR32 RealModeIdtDesc;
248
249 //
250 // real-mode GDT (temporary GDT with two real mode segment descriptors)
251 //
252 GDT32 RealModeGdt[NUM_REAL_GDT_ENTRIES];
253 DESCRIPTOR32 RealModeGdtDesc;
254
255 //
256 // Members specifically for the reverse thunk
257 // The RevReal* members are used to store the current state of real mode
258 // before performing the reverse thunk. The RevFlat* members must be set
259 // before calling the reverse thunk assembly code.
260 //
261 UINT16 RevRealDs;
262 UINT16 RevRealSs;
263 UINT32 RevRealEsp;
264 DESCRIPTOR32 RevRealIdtDesc;
265 UINT16 RevFlatDataSelector; // Flat data selector in GDT
266 UINT32 RevFlatStack;
267
268 //
269 // A low memory stack
270 //
271 CHAR8 Stack[LOW_STACK_SIZE];
272
273 //
274 // Stack for flat mode after reverse thunk
275 // @bug - This may no longer be necessary if the reverse thunk interface
276 // is changed to have the flat stack in a different location.
277 //
278 CHAR8 RevThunkStack[LOW_STACK_SIZE];
279
280 //
281 // Legacy16 Init memory map info
282 //
283 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable;
284
285 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable;
286
287 CHAR8 InterruptRedirectionCode[32];
288 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler;
289 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable;
290 BBS_TABLE BbsTable[MAX_BBS_ENTRIES];
291 } LOW_MEMORY_THUNK;
292
293 #elif defined (MDE_CPU_X64)
294
295 typedef struct {
296 //
297 // Space for the code
298 // The address of Code is also the beginning of the relocated Thunk code
299 //
300 CHAR8 Code[4096]; // ?
301
302 //
303 // Data for the code (cs releative)
304 //
305 DESCRIPTOR64 X64GdtDesc; // Protected mode GDT
306 DESCRIPTOR64 X64IdtDesc; // Protected mode IDT
307 UINTN X64Ss;
308 UINTN X64Esp;
309
310 UINTN RealStack;
311 DESCRIPTOR32 RealModeIdtDesc;
312 DESCRIPTOR32 RealModeGdtDesc;
313
314 //
315 // real-mode GDT (temporary GDT with two real mode segment descriptors)
316 //
317 GDT64 RealModeGdt[NUM_REAL_GDT_ENTRIES];
318 UINT64 PageMapLevel4;
319
320 //
321 // A low memory stack
322 //
323 CHAR8 Stack[LOW_STACK_SIZE];
324
325 //
326 // Legacy16 Init memory map info
327 //
328 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable;
329
330 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable;
331
332 CHAR8 InterruptRedirectionCode[32];
333 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler;
334 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable;
335 BBS_TABLE BbsTable[MAX_BBS_ENTRIES];
336 } LOW_MEMORY_THUNK;
337
338 #elif defined (MDE_CPU_IPF)
339
340 typedef struct {
341 //
342 // Space for the code
343 // The address of Code is also the beginning of the relocated Thunk code
344 //
345 CHAR8 Code[4096]; // ?
346 //
347 // The address of the Reverse Thunk code
348 // Note that this member CONTAINS the address of the relocated reverse thunk
349 // code unlike the member variable 'Code', which IS the address of the Thunk
350 // code.
351 //
352 UINT32 LowReverseThunkStart;
353
354 //
355 // Data for the code (cs releative)
356 //
357 DESCRIPTOR32 GdtDesc; // Protected mode GDT
358 DESCRIPTOR32 IdtDesc; // Protected mode IDT
359 UINT32 FlatSs;
360 UINT32 FlatEsp;
361
362 UINT32 LowCodeSelector; // Low code selector in GDT
363 UINT32 LowDataSelector; // Low data selector in GDT
364 UINT32 LowStack;
365 DESCRIPTOR32 RealModeIdtDesc;
366
367 //
368 // real-mode GDT (temporary GDT with two real mode segment descriptors)
369 //
370 GDT32 RealModeGdt[NUM_REAL_GDT_ENTRIES];
371 DESCRIPTOR32 RealModeGdtDesc;
372
373 //
374 // Members specifically for the reverse thunk
375 // The RevReal* members are used to store the current state of real mode
376 // before performing the reverse thunk. The RevFlat* members must be set
377 // before calling the reverse thunk assembly code.
378 //
379 UINT16 RevRealDs;
380 UINT16 RevRealSs;
381 UINT32 RevRealEsp;
382 DESCRIPTOR32 RevRealIdtDesc;
383 UINT16 RevFlatDataSelector; // Flat data selector in GDT
384 UINT32 RevFlatStack;
385
386 //
387 // A low memory stack
388 //
389 CHAR8 Stack[LOW_STACK_SIZE];
390
391 //
392 // Stack for flat mode after reverse thunk
393 // @bug - This may no longer be necessary if the reverse thunk interface
394 // is changed to have the flat stack in a different location.
395 //
396 CHAR8 RevThunkStack[LOW_STACK_SIZE];
397
398 //
399 // Legacy16 Init memory map info
400 //
401 EFI_TO_COMPATIBILITY16_INIT_TABLE EfiToLegacy16InitTable;
402
403 EFI_TO_COMPATIBILITY16_BOOT_TABLE EfiToLegacy16BootTable;
404
405 CHAR8 InterruptRedirectionCode[32];
406 EFI_LEGACY_INSTALL_PCI_HANDLER PciHandler;
407 EFI_DISPATCH_OPROM_TABLE DispatchOpromTable;
408 BBS_TABLE BbsTable[MAX_BBS_ENTRIES];
409 } LOW_MEMORY_THUNK;
410
411 #endif
412
413 //
414 // PnP Expansion Header
415 //
416 typedef struct {
417 UINT32 PnpSignature;
418 UINT8 Revision;
419 UINT8 Length;
420 UINT16 NextHeader;
421 UINT8 Reserved1;
422 UINT8 Checksum;
423 UINT32 DeviceId;
424 UINT16 MfgPointer;
425 UINT16 ProductNamePointer;
426 UINT8 Class;
427 UINT8 SubClass;
428 UINT8 Interface;
429 UINT8 DeviceIndicators;
430 UINT16 Bcv;
431 UINT16 DisconnectVector;
432 UINT16 Bev;
433 UINT16 Reserved2;
434 UINT16 StaticResourceVector;
435 } LEGACY_PNP_EXPANSION_HEADER;
436
437 typedef struct {
438 UINT8 PciSegment;
439 UINT8 PciBus;
440 UINT8 PciDevice;
441 UINT8 PciFunction;
442 UINT16 Vid;
443 UINT16 Did;
444 UINT16 SysSid;
445 UINT16 SVid;
446 UINT8 Class;
447 UINT8 SubClass;
448 UINT8 Interface;
449 UINT8 Reserved;
450 UINTN RomStart;
451 UINTN ManufacturerString;
452 UINTN ProductNameString;
453 } LEGACY_ROM_AND_BBS_TABLE;
454
455 //
456 // Structure how EFI has mapped a devices HDD drive numbers.
457 // Boot to EFI aware OS or shell requires this mapping when
458 // 16-bit CSM assigns drive numbers.
459 // This mapping is ignored booting to a legacy OS.
460 //
461 typedef struct {
462 UINT8 PciSegment;
463 UINT8 PciBus;
464 UINT8 PciDevice;
465 UINT8 PciFunction;
466 UINT8 StartDriveNumber;
467 UINT8 EndDriveNumber;
468 } LEGACY_EFI_HDD_TABLE;
469
470 //
471 // This data is passed to Leacy16Boot
472 //
473 typedef enum {
474 EfiAcpiAddressRangeMemory = 1,
475 EfiAcpiAddressRangeReserved = 2,
476 EfiAcpiAddressRangeACPI = 3,
477 EfiAcpiAddressRangeNVS = 4
478 } EFI_ACPI_MEMORY_TYPE;
479
480 typedef struct {
481 UINT64 BaseAddr;
482 UINT64 Length;
483 EFI_ACPI_MEMORY_TYPE Type;
484 } EFI_E820_ENTRY64;
485
486 typedef struct {
487 UINT32 BassAddrLow;
488 UINT32 BaseAddrHigh;
489 UINT32 LengthLow;
490 UINT32 LengthHigh;
491 EFI_ACPI_MEMORY_TYPE Type;
492 } EFI_E820_ENTRY;
493
494 #pragma pack()
495
496 extern BBS_TABLE *mBbsTable;
497
498 extern EFI_GENERIC_MEMORY_TEST_PROTOCOL *gGenMemoryTest;
499
500 #define PORT_70 0x70
501 #define PORT_71 0x71
502
503 #define CMOS_0A 0x0a ///< Status register A
504 #define CMOS_0D 0x0d ///< Status register D
505 #define CMOS_0E 0x0e ///< Diagnostic Status
506 #define CMOS_0F 0x0f ///< Shutdown status
507 #define CMOS_10 0x10 ///< Floppy type
508 #define CMOS_12 0x12 ///< IDE type
509 #define CMOS_14 0x14 ///< Same as BDA 40:10
510 #define CMOS_15 0x15 ///< Low byte of base memory in 1k increments
511 #define CMOS_16 0x16 ///< High byte of base memory in 1k increments
512 #define CMOS_17 0x17 ///< Low byte of 1MB+ memory in 1k increments - max 15 MB
513 #define CMOS_18 0x18 ///< High byte of 1MB+ memory in 1k increments - max 15 MB
514 #define CMOS_19 0x19 ///< C: extended drive type
515 #define CMOS_1A 0x1a ///< D: extended drive type
516 #define CMOS_2E 0x2e ///< Most significient byte of standard checksum
517 #define CMOS_2F 0x2f ///< Least significient byte of standard checksum
518 #define CMOS_30 0x30 ///< CMOS 0x17
519 #define CMOS_31 0x31 ///< CMOS 0x18
520 #define CMOS_32 0x32 ///< Century byte
521
522 //
523 // 8254 Timer registers
524 //
525 #define TIMER0_COUNT_PORT 0x40
526 #define TIMER1_COUNT_PORT 0x41
527 #define TIMER2_COUNT_PORT 0x42
528 #define TIMER_CONTROL_PORT 0x43
529
530 //
531 // Timer 0, Read/Write LSB then MSB, Square wave output, binary count use.
532 //
533 #define TIMER0_CONTROL_WORD 0x36
534
535 #define LEGACY_BIOS_INSTANCE_SIGNATURE SIGNATURE_32 ('L', 'B', 'I', 'T')
536 typedef struct {
537 UINTN Signature;
538
539 EFI_HANDLE Handle;
540 EFI_LEGACY_BIOS_PROTOCOL LegacyBios;
541
542 EFI_HANDLE ImageHandle;
543
544 //
545 // CPU Architectural Protocol
546 //
547 EFI_CPU_ARCH_PROTOCOL *Cpu;
548
549 //
550 // Timer Architectural Protocol
551 //
552 EFI_TIMER_ARCH_PROTOCOL *Timer;
553 BOOLEAN TimerUses8254;
554
555 //
556 // Protocol to Lock and Unlock 0xc0000 - 0xfffff
557 //
558 EFI_LEGACY_REGION2_PROTOCOL *LegacyRegion;
559
560 EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *LegacyBiosPlatform;
561
562 //
563 // Interrupt control for thunk and PCI IRQ
564 //
565 EFI_LEGACY_8259_PROTOCOL *Legacy8259;
566
567 //
568 // PCI Interrupt PIRQ control
569 //
570 EFI_LEGACY_INTERRUPT_PROTOCOL *LegacyInterrupt;
571
572 //
573 // Generic Memory Test
574 //
575 EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenericMemoryTest;
576
577 //
578 // TRUE if PCI Interupt Line registers have been programmed.
579 //
580 BOOLEAN PciInterruptLine;
581
582 //
583 // Code space below 1MB needed by thunker to transition to real mode.
584 // Contains stack and real mode code fragments
585 //
586 LOW_MEMORY_THUNK *IntThunk;
587
588 //
589 // Starting shadow address of the Legacy BIOS
590 //
591 UINT32 BiosStart;
592 UINT32 LegacyBiosImageSize;
593
594 //
595 // Start of variables used by CsmItp.mac ITP macro file and/os LegacyBios
596 //
597 UINT8 Dump[4];
598
599 //
600 // $EFI Legacy16 code entry info in memory < 1 MB;
601 //
602 EFI_COMPATIBILITY16_TABLE *Legacy16Table;
603 VOID *Legacy16InitPtr;
604 VOID *Legacy16BootPtr;
605 VOID *InternalIrqRoutingTable;
606 UINT32 NumberIrqRoutingEntries;
607 VOID *BbsTablePtr;
608 VOID *HddTablePtr;
609 UINT32 NumberHddControllers;
610
611 //
612 // Cached copy of Legacy16 entry point
613 //
614 UINT16 Legacy16CallSegment;
615 UINT16 Legacy16CallOffset;
616
617 //
618 // Returned from $EFI and passed in to OPROMS
619 //
620 UINT16 PnPInstallationCheckSegment;
621 UINT16 PnPInstallationCheckOffset;
622
623 //
624 // E820 table
625 //
626 EFI_E820_ENTRY E820Table[EFI_MAX_E820_ENTRY];
627 UINT32 NumberE820Entries;
628
629 //
630 // True if legacy VGA INT 10h handler installed
631 //
632 BOOLEAN VgaInstalled;
633
634 //
635 // Number of IDE drives
636 //
637 UINT8 IdeDriveCount;
638
639 //
640 // Current Free Option ROM space. An option ROM must NOT go past
641 // BiosStart.
642 //
643 UINT32 OptionRom;
644
645 //
646 // Save Legacy16 unexpected interrupt vector. Reprogram INT 68-6F from
647 // EFI values to legacy value just before boot.
648 //
649 UINT32 BiosUnexpectedInt;
650 UINT32 ThunkSavedInt[8];
651 UINT16 ThunkSeg;
652 LEGACY_EFI_HDD_TABLE *LegacyEfiHddTable;
653 UINT16 LegacyEfiHddTableIndex;
654 UINT8 DiskEnd;
655 UINT8 Disk4075;
656 UINT16 TraceIndex;
657 UINT16 Trace[0x200];
658
659 //
660 // Indicate that whether GenericLegacyBoot is entered or not
661 //
662 BOOLEAN LegacyBootEntered;
663
664 //
665 // CSM16 PCI Interface Version
666 //
667 UINT16 Csm16PciInterfaceVersion;
668
669 } LEGACY_BIOS_INSTANCE;
670
671
672 #pragma pack(1)
673
674 /*
675 40:00-01 Com1
676 40:02-03 Com2
677 40:04-05 Com3
678 40:06-07 Com4
679 40:08-09 Lpt1
680 40:0A-0B Lpt2
681 40:0C-0D Lpt3
682 40:0E-0E Ebda segment
683 40:10-11 MachineConfig
684 40:12 Bda12 - skip
685 40:13-14 MemSize below 1MB
686 40:15-16 Bda15_16 - skip
687 40:17 Keyboard Shift status
688 40:18-19 Bda18_19 - skip
689 40:1A-1B Key buffer head
690 40:1C-1D Key buffer tail
691 40:1E-3D Bda1E_3D- key buffer -skip
692 40:3E-3F FloppyData 3E = Calibration status 3F = Motor status
693 40:40 FloppyTimeout
694 40:41-74 Bda41_74 - skip
695 40:75 Number of HDD drives
696 40:76-77 Bda76_77 - skip
697 40:78-79 78 = Lpt1 timeout, 79 = Lpt2 timeout
698 40:7A-7B 7A = Lpt3 timeout, 7B = Lpt4 timeout
699 40:7C-7D 7C = Com1 timeout, 7D = Com2 timeout
700 40:7E-7F 7E = Com3 timeout, 7F = Com4 timeout
701 40:80-81 Pointer to start of key buffer
702 40:82-83 Pointer to end of key buffer
703 40:84-87 Bda84_87 - skip
704 40:88 HDD Data Xmit rate
705 40:89-8f skip
706 40:90 Floppy data rate
707 40:91-95 skip
708 40:96 Keyboard Status
709 40:97 LED Status
710 40:98-101 skip
711 */
712 typedef struct {
713 UINT16 Com1;
714 UINT16 Com2;
715 UINT16 Com3;
716 UINT16 Com4;
717 UINT16 Lpt1;
718 UINT16 Lpt2;
719 UINT16 Lpt3;
720 UINT16 Ebda;
721 UINT16 MachineConfig;
722 UINT8 Bda12;
723 UINT16 MemSize;
724 UINT8 Bda15_16[0x02];
725 UINT8 ShiftStatus;
726 UINT8 Bda18_19[0x02];
727 UINT16 KeyHead;
728 UINT16 KeyTail;
729 UINT16 Bda1E_3D[0x10];
730 UINT16 FloppyData;
731 UINT8 FloppyTimeout;
732 UINT8 Bda41_74[0x34];
733 UINT8 NumberOfDrives;
734 UINT8 Bda76_77[0x02];
735 UINT16 Lpt1_2Timeout;
736 UINT16 Lpt3_4Timeout;
737 UINT16 Com1_2Timeout;
738 UINT16 Com3_4Timeout;
739 UINT16 KeyStart;
740 UINT16 KeyEnd;
741 UINT8 Bda84_87[0x4];
742 UINT8 DataXmit;
743 UINT8 Bda89_8F[0x07];
744 UINT8 FloppyXRate;
745 UINT8 Bda91_95[0x05];
746 UINT8 KeyboardStatus;
747 UINT8 LedStatus;
748 } BDA_STRUC;
749 #pragma pack()
750
751 #define LEGACY_BIOS_INSTANCE_FROM_THIS(this) CR (this, LEGACY_BIOS_INSTANCE, LegacyBios, LEGACY_BIOS_INSTANCE_SIGNATURE)
752
753 /**
754 Thunk to 16-bit real mode and execute a software interrupt with a vector
755 of BiosInt. Regs will contain the 16-bit register context on entry and
756 exit.
757
758 @param This Protocol instance pointer.
759 @param BiosInt Processor interrupt vector to invoke
760 @param Regs Register contexted passed into (and returned) from thunk to
761 16-bit mode
762
763 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
764 See Regs for status.
765 @retval TRUE There was a BIOS erro in the target code.
766
767 **/
768 BOOLEAN
769 EFIAPI
770 LegacyBiosInt86 (
771 IN EFI_LEGACY_BIOS_PROTOCOL *This,
772 IN UINT8 BiosInt,
773 IN EFI_IA32_REGISTER_SET *Regs
774 );
775
776
777 /**
778 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
779 16-bit register context on entry and exit. Arguments can be passed on
780 the Stack argument
781
782 @param This Protocol instance pointer.
783 @param Segment Segemnt of 16-bit mode call
784 @param Offset Offset of 16-bit mdoe call
785 @param Regs Register contexted passed into (and returned) from
786 thunk to 16-bit mode
787 @param Stack Caller allocated stack used to pass arguments
788 @param StackSize Size of Stack in bytes
789
790 @retval FALSE Thunk completed, and there were no BIOS errors in
791 the target code. See Regs for status.
792 @retval TRUE There was a BIOS erro in the target code.
793
794 **/
795 BOOLEAN
796 EFIAPI
797 LegacyBiosFarCall86 (
798 IN EFI_LEGACY_BIOS_PROTOCOL *This,
799 IN UINT16 Segment,
800 IN UINT16 Offset,
801 IN EFI_IA32_REGISTER_SET *Regs,
802 IN VOID *Stack,
803 IN UINTN StackSize
804 );
805
806
807 /**
808 Test to see if a legacy PCI ROM exists for this device. Optionally return
809 the Legacy ROM instance for this PCI device.
810
811 @param This Protocol instance pointer.
812 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
813 be loaded
814 @param RomImage Return the legacy PCI ROM for this device
815 @param RomSize Size of ROM Image
816 @param Flags Indicates if ROM found and if PC-AT.
817
818 @retval EFI_SUCCESS Legacy Option ROM availible for this device
819 @retval EFI_UNSUPPORTED Legacy Option ROM not supported.
820
821 **/
822 EFI_STATUS
823 EFIAPI
824 LegacyBiosCheckPciRom (
825 IN EFI_LEGACY_BIOS_PROTOCOL *This,
826 IN EFI_HANDLE PciHandle,
827 OUT VOID **RomImage, OPTIONAL
828 OUT UINTN *RomSize, OPTIONAL
829 OUT UINTN *Flags
830 );
831
832
833 /**
834 Assign drive number to legacy HDD drives prior to booting an EFI
835 aware OS so the OS can access drives without an EFI driver.
836 Note: BBS compliant drives ARE NOT available until this call by
837 either shell or EFI.
838
839 @param This Protocol instance pointer.
840 @param BbsCount Number of BBS_TABLE structures
841 @param BbsTable List BBS entries
842
843 @retval EFI_SUCCESS Drive numbers assigned
844
845 **/
846 EFI_STATUS
847 EFIAPI
848 LegacyBiosPrepareToBootEfi (
849 IN EFI_LEGACY_BIOS_PROTOCOL *This,
850 OUT UINT16 *BbsCount,
851 OUT BBS_TABLE **BbsTable
852 );
853
854
855 /**
856 To boot from an unconventional device like parties and/or execute
857 HDD diagnostics.
858
859 @param This Protocol instance pointer.
860 @param Attributes How to interpret the other input parameters
861 @param BbsEntry The 0-based index into the BbsTable for the parent
862 device.
863 @param BeerData Pointer to the 128 bytes of ram BEER data.
864 @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data.
865 The caller must provide a pointer to the specific
866 Service Area and not the start all Service Areas.
867 EFI_INVALID_PARAMETER if error. Does NOT return if no error.
868
869 **/
870 EFI_STATUS
871 EFIAPI
872 LegacyBiosBootUnconventionalDevice (
873 IN EFI_LEGACY_BIOS_PROTOCOL *This,
874 IN UDC_ATTRIBUTES Attributes,
875 IN UINTN BbsEntry,
876 IN VOID *BeerData,
877 IN VOID *ServiceAreaData
878 );
879
880
881 /**
882 Load a legacy PC-AT OPROM on the PciHandle device. Return information
883 about how many disks were added by the OPROM and the shadow address and
884 size. DiskStart & DiskEnd are INT 13h drive letters. Thus 0x80 is C:
885
886 @param This Protocol instance pointer.
887 @param PciHandle The PCI PC-AT OPROM from this devices ROM BAR will
888 be loaded. This value is NULL if RomImage is
889 non-NULL. This is the normal case.
890 @param RomImage A PCI PC-AT ROM image. This argument is non-NULL
891 if there is no hardware associated with the ROM
892 and thus no PciHandle, otherwise is must be NULL.
893 Example is PXE base code.
894 @param Flags Indicates if ROM found and if PC-AT.
895 @param DiskStart Disk number of first device hooked by the ROM. If
896 DiskStart is the same as DiskEnd no disked were
897 hooked.
898 @param DiskEnd Disk number of the last device hooked by the ROM.
899 @param RomShadowAddress Shadow address of PC-AT ROM
900 @param RomShadowedSize Size of RomShadowAddress in bytes
901
902 @retval EFI_SUCCESS Legacy ROM loaded for this device
903 @retval EFI_INVALID_PARAMETER PciHandle not found
904 @retval EFI_UNSUPPORTED There is no PCI ROM in the ROM BAR or no onboard
905 ROM
906
907 **/
908 EFI_STATUS
909 EFIAPI
910 LegacyBiosInstallPciRom (
911 IN EFI_LEGACY_BIOS_PROTOCOL * This,
912 IN EFI_HANDLE PciHandle,
913 IN VOID **RomImage,
914 OUT UINTN *Flags,
915 OUT UINT8 *DiskStart, OPTIONAL
916 OUT UINT8 *DiskEnd, OPTIONAL
917 OUT VOID **RomShadowAddress, OPTIONAL
918 OUT UINT32 *RomShadowedSize OPTIONAL
919 );
920
921
922 /**
923 Fill in the standard BDA for Keyboard LEDs
924
925 @param This Protocol instance pointer.
926 @param Leds Current LED status
927
928 @retval EFI_SUCCESS It should always work.
929
930 **/
931 EFI_STATUS
932 EFIAPI
933 LegacyBiosUpdateKeyboardLedStatus (
934 IN EFI_LEGACY_BIOS_PROTOCOL *This,
935 IN UINT8 Leds
936 );
937
938
939 /**
940 Get all BBS info
941
942 @param This Protocol instance pointer.
943 @param HddCount Number of HDD_INFO structures
944 @param HddInfo Onboard IDE controller information
945 @param BbsCount Number of BBS_TABLE structures
946 @param BbsTable List BBS entries
947
948 @retval EFI_SUCCESS Tables returned
949 @retval EFI_NOT_FOUND resource not found
950 @retval EFI_DEVICE_ERROR can not get BBS table
951
952 **/
953 EFI_STATUS
954 EFIAPI
955 LegacyBiosGetBbsInfo (
956 IN EFI_LEGACY_BIOS_PROTOCOL *This,
957 OUT UINT16 *HddCount,
958 OUT HDD_INFO **HddInfo,
959 OUT UINT16 *BbsCount,
960 OUT BBS_TABLE **BbsTable
961 );
962
963
964 /**
965 Shadow all legacy16 OPROMs that haven't been shadowed.
966 Warning: Use this with caution. This routine disconnects all EFI
967 drivers. If used externally then caller must re-connect EFI
968 drivers.
969
970 @param This Protocol instance pointer.
971
972 @retval EFI_SUCCESS OPROMs shadowed
973
974 **/
975 EFI_STATUS
976 EFIAPI
977 LegacyBiosShadowAllLegacyOproms (
978 IN EFI_LEGACY_BIOS_PROTOCOL *This
979 );
980
981
982 /**
983 Attempt to legacy boot the BootOption. If the EFI contexted has been
984 compromised this function will not return.
985
986 @param This Protocol instance pointer.
987 @param BbsDevicePath EFI Device Path from BootXXXX variable.
988 @param LoadOptionsSize Size of LoadOption in size.
989 @param LoadOptions LoadOption from BootXXXX variable
990
991 @retval EFI_SUCCESS Removable media not present
992
993 **/
994 EFI_STATUS
995 EFIAPI
996 LegacyBiosLegacyBoot (
997 IN EFI_LEGACY_BIOS_PROTOCOL *This,
998 IN BBS_BBS_DEVICE_PATH *BbsDevicePath,
999 IN UINT32 LoadOptionsSize,
1000 IN VOID *LoadOptions
1001 );
1002
1003
1004 /**
1005 Allocate memory < 1 MB and copy the thunker code into low memory. Se up
1006 all the descriptors.
1007
1008 @param Private Private context for Legacy BIOS
1009
1010 @retval EFI_SUCCESS Should only pass.
1011
1012 **/
1013 EFI_STATUS
1014 LegacyBiosInitializeThunk (
1015 IN LEGACY_BIOS_INSTANCE *Private
1016 );
1017
1018
1019 /**
1020 Fill in the standard BDA and EBDA stuff before Legacy16 load
1021
1022 @param Private Legacy BIOS Instance data
1023
1024 @retval EFI_SUCCESS It should always work.
1025
1026 **/
1027 EFI_STATUS
1028 LegacyBiosInitBda (
1029 IN LEGACY_BIOS_INSTANCE *Private
1030 );
1031
1032
1033 /**
1034 Collect IDE Inquiry data from the IDE disks
1035
1036 @param Private Legacy BIOS Instance data
1037 @param HddInfo Hdd Information
1038 @param Flag Reconnect IdeController or not
1039
1040 @retval EFI_SUCCESS It should always work.
1041
1042 **/
1043 EFI_STATUS
1044 LegacyBiosBuildIdeData (
1045 IN LEGACY_BIOS_INSTANCE *Private,
1046 IN HDD_INFO **HddInfo,
1047 IN UINT16 Flag
1048 );
1049
1050
1051 /**
1052 Enable ide controller. This gets disabled when LegacyBoot.c is about
1053 to run the Option ROMs.
1054
1055 @param Private Legacy BIOS Instance data
1056
1057
1058 **/
1059 VOID
1060 EnableIdeController (
1061 IN LEGACY_BIOS_INSTANCE *Private
1062 );
1063
1064
1065 /**
1066 If the IDE channel is in compatibility (legacy) mode, remove all
1067 PCI I/O BAR addresses from the controller.
1068
1069 @param IdeController The handle of target IDE controller
1070
1071
1072 **/
1073 VOID
1074 InitLegacyIdeController (
1075 IN EFI_HANDLE IdeController
1076 );
1077
1078
1079 /**
1080 Program the interrupt routing register in all the PCI devices. On a PC AT system
1081 this register contains the 8259 IRQ vector that matches it's PCI interrupt.
1082
1083 @param Private Legacy BIOS Instance data
1084
1085 @retval EFI_SUCCESS Succeed.
1086 @retval EFI_ALREADY_STARTED All PCI devices have been processed.
1087
1088 **/
1089 EFI_STATUS
1090 PciProgramAllInterruptLineRegisters (
1091 IN LEGACY_BIOS_INSTANCE *Private
1092 );
1093
1094
1095 /**
1096 Collect EFI Info about legacy devices.
1097
1098 @param Private Legacy BIOS Instance data
1099
1100 @retval EFI_SUCCESS It should always work.
1101
1102 **/
1103 EFI_STATUS
1104 LegacyBiosBuildSioData (
1105 IN LEGACY_BIOS_INSTANCE *Private
1106 );
1107
1108
1109 /**
1110 Shadow all the PCI legacy ROMs. Use data from the Legacy BIOS Protocol
1111 to chose the order. Skip any devices that have already have legacy
1112 BIOS run.
1113
1114 @param Private Protocol instance pointer.
1115
1116 @retval EFI_SUCCESS Succeed.
1117 @retval EFI_UNSUPPORTED Cannot get VGA device handle.
1118
1119 **/
1120 EFI_STATUS
1121 PciShadowRoms (
1122 IN LEGACY_BIOS_INSTANCE *Private
1123 );
1124
1125
1126 /**
1127 Fill in the standard BDA and EBDA stuff prior to legacy Boot
1128
1129 @param Private Legacy BIOS Instance data
1130
1131 @retval EFI_SUCCESS It should always work.
1132
1133 **/
1134 EFI_STATUS
1135 LegacyBiosCompleteBdaBeforeBoot (
1136 IN LEGACY_BIOS_INSTANCE *Private
1137 );
1138
1139
1140 /**
1141 Fill in the standard CMOS stuff before Legacy16 load
1142
1143 @param Private Legacy BIOS Instance data
1144
1145 @retval EFI_SUCCESS It should always work.
1146
1147 **/
1148 EFI_STATUS
1149 LegacyBiosInitCmos (
1150 IN LEGACY_BIOS_INSTANCE *Private
1151 );
1152
1153
1154 /**
1155 Fill in the standard CMOS stuff prior to legacy Boot
1156
1157 @param Private Legacy BIOS Instance data
1158
1159 @retval EFI_SUCCESS It should always work.
1160
1161 **/
1162 EFI_STATUS
1163 LegacyBiosCompleteStandardCmosBeforeBoot (
1164 IN LEGACY_BIOS_INSTANCE *Private
1165 );
1166
1167
1168 /**
1169 Contains the code that is copied into low memory (below 640K).
1170 This code reflects interrupts 0x68-0x6f to interrupts 0x08-0x0f.
1171 This template must be copied into low memory, and the IDT entries
1172 0x68-0x6F must be point to the low memory copy of this code. Each
1173 entry is 4 bytes long, so IDT entries 0x68-0x6F can be easily
1174 computed.
1175
1176 **/
1177 VOID
1178 InterruptRedirectionTemplate (
1179 VOID
1180 );
1181
1182
1183 /**
1184 Build the E820 table.
1185
1186 @param Private Legacy BIOS Instance data
1187 @param Size Size of E820 Table
1188
1189 @retval EFI_SUCCESS It should always work.
1190
1191 **/
1192 EFI_STATUS
1193 LegacyBiosBuildE820 (
1194 IN LEGACY_BIOS_INSTANCE *Private,
1195 OUT UINTN *Size
1196 );
1197
1198 /**
1199 This function is to put all AP in halt state.
1200
1201 @param Private Legacy BIOS Instance data
1202
1203 **/
1204 VOID
1205 ShutdownAPs (
1206 IN LEGACY_BIOS_INSTANCE *Private
1207 );
1208
1209 /**
1210 Worker function for LegacyBiosGetFlatDescs, retrieving content of
1211 specific registers.
1212
1213 @param IntThunk Pointer to IntThunk of Legacy BIOS context.
1214
1215 **/
1216 VOID
1217 GetRegisters (
1218 LOW_MEMORY_THUNK *IntThunk
1219 );
1220
1221 /**
1222 Routine for calling real thunk code.
1223
1224 @param RealCode The address of thunk code.
1225 @param BiosInt The Bios interrupt vector number.
1226 @param CallAddress The address of 16-bit mode call.
1227
1228 @return Status returned by real thunk code
1229
1230 **/
1231 UINTN
1232 CallRealThunkCode (
1233 UINT8 *RealCode,
1234 UINT8 BiosInt,
1235 UINT32 CallAddress
1236 );
1237
1238 /**
1239 Routine for generating soft interrupt.
1240
1241 @param Vector The interrupt vector number.
1242
1243 **/
1244 VOID
1245 GenerateSoftInit (
1246 UINT8 Vector
1247 );
1248
1249 /**
1250 Do an AllocatePages () of type AllocateMaxAddress for EfiBootServicesCode
1251 memory.
1252
1253 @param AllocateType Allocated Legacy Memory Type
1254 @param StartPageAddress Start address of range
1255 @param Pages Number of pages to allocate
1256 @param Result Result of allocation
1257
1258 @retval EFI_SUCCESS Legacy16 code loaded
1259 @retval Other No protocol installed, unload driver.
1260
1261 **/
1262 EFI_STATUS
1263 AllocateLegacyMemory (
1264 IN EFI_ALLOCATE_TYPE AllocateType,
1265 IN EFI_PHYSICAL_ADDRESS StartPageAddress,
1266 IN UINTN Pages,
1267 OUT EFI_PHYSICAL_ADDRESS *Result
1268 );
1269
1270 /**
1271 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1272
1273 @param This Protocol instance pointer.
1274 @param LegacyMemorySize Size of required region
1275 @param Region Region to use. 00 = Either 0xE0000 or 0xF0000
1276 block Bit0 = 1 0xF0000 block Bit1 = 1 0xE0000
1277 block
1278 @param Alignment Address alignment. Bit mapped. First non-zero
1279 bit from right is alignment.
1280 @param LegacyMemoryAddress Region Assigned
1281
1282 @retval EFI_SUCCESS Region assigned
1283 @retval EFI_ACCESS_DENIED Procedure previously invoked
1284 @retval Other Region not assigned
1285
1286 **/
1287 EFI_STATUS
1288 EFIAPI
1289 LegacyBiosGetLegacyRegion (
1290 IN EFI_LEGACY_BIOS_PROTOCOL *This,
1291 IN UINTN LegacyMemorySize,
1292 IN UINTN Region,
1293 IN UINTN Alignment,
1294 OUT VOID **LegacyMemoryAddress
1295 );
1296
1297 /**
1298 Get a region from the LegacyBios for Tiano usage. Can only be invoked once.
1299
1300 @param This Protocol instance pointer.
1301 @param LegacyMemorySize Size of data to copy
1302 @param LegacyMemoryAddress Legacy Region destination address Note: must
1303 be in region assigned by
1304 LegacyBiosGetLegacyRegion
1305 @param LegacyMemorySourceAddress Source of data
1306
1307 @retval EFI_SUCCESS Region assigned
1308 @retval EFI_ACCESS_DENIED Destination outside assigned region
1309
1310 **/
1311 EFI_STATUS
1312 EFIAPI
1313 LegacyBiosCopyLegacyRegion (
1314 IN EFI_LEGACY_BIOS_PROTOCOL *This,
1315 IN UINTN LegacyMemorySize,
1316 IN VOID *LegacyMemoryAddress,
1317 IN VOID *LegacyMemorySourceAddress
1318 );
1319
1320 /**
1321 Find Legacy16 BIOS image in the FLASH device and shadow it into memory. Find
1322 the $EFI table in the shadow area. Thunk into the Legacy16 code after it had
1323 been shadowed.
1324
1325 @param Private Legacy BIOS context data
1326
1327 @retval EFI_SUCCESS Legacy16 code loaded
1328 @retval Other No protocol installed, unload driver.
1329
1330 **/
1331 EFI_STATUS
1332 ShadowAndStartLegacy16 (
1333 IN LEGACY_BIOS_INSTANCE *Private
1334 );
1335
1336 /**
1337 Checks the state of the floppy and if media is inserted.
1338
1339 This routine checks the state of the floppy and if media is inserted.
1340 There are 3 cases:
1341 No floppy present - Set BBS entry to ignore
1342 Floppy present & no media - Set BBS entry to lowest priority. We cannot
1343 set it to ignore since 16-bit CSM will
1344 indicate no floppy and thus drive A: is
1345 unusable. CSM-16 will not try floppy since
1346 lowest priority and thus not incur boot
1347 time penality.
1348 Floppy present & media - Set BBS entry to some priority.
1349
1350 @return State of floppy media
1351
1352 **/
1353 UINT8
1354 HasMediaInFloppy (
1355 VOID
1356 );
1357
1358 /**
1359 Identify drive data must be updated to actual parameters before boot.
1360 This requires updating the checksum, if it exists.
1361
1362 @param IdentifyDriveData ATA Identify Data
1363 @param Checksum checksum of the ATA Identify Data
1364
1365 @retval EFI_SUCCESS checksum calculated
1366 @retval EFI_SECURITY_VIOLATION IdentifyData invalid
1367
1368 **/
1369 EFI_STATUS
1370 CalculateIdentifyDriveChecksum (
1371 IN UINT8 *IdentifyDriveData,
1372 OUT UINT8 *Checksum
1373 );
1374
1375 /**
1376 Identify drive data must be updated to actual parameters before boot.
1377
1378 @param IdentifyDriveData ATA Identify Data
1379
1380 **/
1381 VOID
1382 UpdateIdentifyDriveData (
1383 IN UINT8 *IdentifyDriveData
1384 );
1385
1386 /**
1387 Complete build of BBS TABLE.
1388
1389 @param Private Legacy BIOS Instance data
1390 @param BbsTable BBS Table passed to 16-bit code
1391
1392 @retval EFI_SUCCESS Removable media not present
1393
1394 **/
1395 EFI_STATUS
1396 LegacyBiosBuildBbs (
1397 IN LEGACY_BIOS_INSTANCE *Private,
1398 IN BBS_TABLE *BbsTable
1399 );
1400
1401 /**
1402 Read CMOS register through index/data port.
1403
1404 @param[in] Index The index of the CMOS register to read.
1405
1406 @return The data value from the CMOS register specified by Index.
1407
1408 **/
1409 UINT8
1410 LegacyReadStandardCmos (
1411 IN UINT8 Index
1412 );
1413
1414 /**
1415 Write CMOS register through index/data port.
1416
1417 @param[in] Index The index of the CMOS register to write.
1418 @param[in] Value The value of CMOS register to write.
1419
1420 @return The value written to the CMOS register specified by Index.
1421
1422 **/
1423 UINT8
1424 LegacyWriteStandardCmos (
1425 IN UINT8 Index,
1426 IN UINT8 Value
1427 );
1428
1429 /**
1430 Calculate the new standard CMOS checksum and write it.
1431
1432 @param Private Legacy BIOS Instance data
1433
1434 @retval EFI_SUCCESS Calculate 16-bit checksum successfully
1435
1436 **/
1437 EFI_STATUS
1438 LegacyCalculateWriteStandardCmosChecksum (
1439 VOID
1440 );
1441
1442 /**
1443 Test to see if a legacy PCI ROM exists for this device. Optionally return
1444 the Legacy ROM instance for this PCI device.
1445
1446 @param[in] This Protocol instance pointer.
1447 @param[in] PciHandle The PCI PC-AT OPROM from this devices ROM BAR will be loaded
1448 @param[out] RomImage Return the legacy PCI ROM for this device
1449 @param[out] RomSize Size of ROM Image
1450 @param[out] RuntimeImageLength Runtime size of ROM Image
1451 @param[out] Flags Indicates if ROM found and if PC-AT.
1452 @param[out] OpromRevision Revision of the PCI Rom
1453 @param[out] ConfigUtilityCodeHeaderPointer of Configuration Utility Code Header
1454
1455 @return EFI_SUCCESS Legacy Option ROM availible for this device
1456 @return EFI_ALREADY_STARTED This device is already managed by its Oprom
1457 @return EFI_UNSUPPORTED Legacy Option ROM not supported.
1458
1459 **/
1460 EFI_STATUS
1461 LegacyBiosCheckPciRomEx (
1462 IN EFI_LEGACY_BIOS_PROTOCOL *This,
1463 IN EFI_HANDLE PciHandle,
1464 OUT VOID **RomImage, OPTIONAL
1465 OUT UINTN *RomSize, OPTIONAL
1466 OUT UINTN *RuntimeImageLength, OPTIONAL
1467 OUT UINTN *Flags, OPTIONAL
1468 OUT UINT8 *OpromRevision, OPTIONAL
1469 OUT VOID **ConfigUtilityCodeHeader OPTIONAL
1470 );
1471
1472 /**
1473 Relocate this image under 4G memory for IPF.
1474
1475 @param ImageHandle Handle of driver image.
1476 @param SystemTable Pointer to system table.
1477
1478 @retval EFI_SUCCESS Image successfully relocated.
1479 @retval EFI_ABORTED Failed to relocate image.
1480
1481 **/
1482 EFI_STATUS
1483 RelocateImageUnder4GIfNeeded (
1484 IN EFI_HANDLE ImageHandle,
1485 IN EFI_SYSTEM_TABLE *SystemTable
1486 );
1487
1488 /**
1489 Thunk to 16-bit real mode and call Segment:Offset. Regs will contain the
1490 16-bit register context on entry and exit. Arguments can be passed on
1491 the Stack argument
1492
1493 @param This Protocol instance pointer.
1494 @param Segment Segemnt of 16-bit mode call
1495 @param Offset Offset of 16-bit mdoe call
1496 @param Regs Register contexted passed into (and returned) from thunk to
1497 16-bit mode
1498 @param Stack Caller allocated stack used to pass arguments
1499 @param StackSize Size of Stack in bytes
1500
1501 @retval FALSE Thunk completed, and there were no BIOS errors in the target code.
1502 See Regs for status.
1503 @retval TRUE There was a BIOS erro in the target code.
1504
1505 **/
1506 BOOLEAN
1507 EFIAPI
1508 InternalLegacyBiosFarCall (
1509 IN EFI_LEGACY_BIOS_PROTOCOL *This,
1510 IN UINT16 Segment,
1511 IN UINT16 Offset,
1512 IN EFI_IA32_REGISTER_SET *Regs,
1513 IN VOID *Stack,
1514 IN UINTN StackSize
1515 );
1516
1517 #endif