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