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