]>
Commit | Line | Data |
---|---|---|
bcecde14 | 1 | /** @file\r |
2 | \r | |
81c0d6e9 | 3 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
bcecde14 | 4 | \r |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions\r | |
7 | of the BSD License which accompanies this distribution. The\r | |
8 | full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "LegacyBiosInterface.h"\r | |
17 | #include <IndustryStandard/Pci.h>\r | |
18 | \r | |
19 | #define BOOT_LEGACY_OS 0\r | |
20 | #define BOOT_EFI_OS 1\r | |
21 | #define BOOT_UNCONVENTIONAL_DEVICE 2\r | |
22 | \r | |
23 | UINT32 mLoadOptionsSize = 0;\r | |
24 | UINTN mBootMode = BOOT_LEGACY_OS;\r | |
25 | VOID *mLoadOptions = NULL;\r | |
26 | BBS_BBS_DEVICE_PATH *mBbsDevicePathPtr = NULL;\r | |
27 | BBS_BBS_DEVICE_PATH mBbsDevicePathNode;\r | |
28 | UDC_ATTRIBUTES mAttributes = { 0, 0, 0, 0 };\r | |
29 | UINTN mBbsEntry = 0;\r | |
30 | VOID *mBeerData = NULL;\r | |
31 | VOID *mServiceAreaData = NULL;\r | |
32 | UINT64 mLowWater = 0xffffffffffffffffULL;\r | |
33 | \r | |
34 | extern BBS_TABLE *mBbsTable;\r | |
35 | \r | |
36 | /**\r | |
37 | Print the BBS Table.\r | |
38 | \r | |
39 | @param BbsTable The BBS table.\r | |
40 | \r | |
41 | \r | |
42 | **/\r | |
43 | VOID\r | |
44 | PrintBbsTable (\r | |
45 | IN BBS_TABLE *BbsTable\r | |
46 | )\r | |
47 | {\r | |
48 | UINT16 Index;\r | |
49 | UINT16 SubIndex;\r | |
50 | CHAR8 *String;\r | |
51 | \r | |
52 | DEBUG ((EFI_D_INFO, "\n"));\r | |
53 | DEBUG ((EFI_D_INFO, " NO Prio bb/dd/ff cl/sc Type Stat segm:offs mfgs:mfgo dess:deso\n"));\r | |
54 | DEBUG ((EFI_D_INFO, "=================================================================\n"));\r | |
55 | for (Index = 0; Index < MAX_BBS_ENTRIES; Index++) {\r | |
56 | //\r | |
57 | // Filter\r | |
58 | //\r | |
59 | if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {\r | |
60 | continue;\r | |
61 | }\r | |
62 | \r | |
63 | DEBUG ((\r | |
64 | EFI_D_INFO,\r | |
65 | " %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x",\r | |
66 | (UINTN) Index,\r | |
67 | (UINTN) BbsTable[Index].BootPriority,\r | |
68 | (UINTN) BbsTable[Index].Bus,\r | |
69 | (UINTN) BbsTable[Index].Device,\r | |
70 | (UINTN) BbsTable[Index].Function,\r | |
71 | (UINTN) BbsTable[Index].Class,\r | |
72 | (UINTN) BbsTable[Index].SubClass,\r | |
73 | (UINTN) BbsTable[Index].DeviceType,\r | |
74 | (UINTN) * (UINT16 *) &BbsTable[Index].StatusFlags\r | |
75 | ));\r | |
76 | DEBUG ((\r | |
77 | EFI_D_INFO,\r | |
78 | " %04x:%04x %04x:%04x %04x:%04x",\r | |
79 | (UINTN) BbsTable[Index].BootHandlerSegment,\r | |
80 | (UINTN) BbsTable[Index].BootHandlerOffset,\r | |
81 | (UINTN) BbsTable[Index].MfgStringSegment,\r | |
82 | (UINTN) BbsTable[Index].MfgStringOffset,\r | |
83 | (UINTN) BbsTable[Index].DescStringSegment,\r | |
84 | (UINTN) BbsTable[Index].DescStringOffset\r | |
85 | ));\r | |
86 | \r | |
87 | //\r | |
88 | // Print DescString\r | |
89 | //\r | |
90 | String = (CHAR8 *)(UINTN)((BbsTable[Index].DescStringSegment << 4) + BbsTable[Index].DescStringOffset);\r | |
91 | if (String != NULL) {\r | |
92 | DEBUG ((EFI_D_INFO," ("));\r | |
93 | for (SubIndex = 0; String[SubIndex] != 0; SubIndex++) {\r | |
94 | DEBUG ((EFI_D_INFO, "%c", String[SubIndex]));\r | |
95 | }\r | |
96 | DEBUG ((EFI_D_INFO,")"));\r | |
97 | }\r | |
98 | DEBUG ((EFI_D_INFO,"\n"));\r | |
99 | }\r | |
100 | \r | |
101 | DEBUG ((EFI_D_INFO, "\n"));\r | |
102 | \r | |
103 | return ;\r | |
104 | }\r | |
105 | \r | |
106 | /**\r | |
107 | Print the BBS Table.\r | |
108 | \r | |
109 | @param HddInfo The HddInfo table.\r | |
110 | \r | |
111 | \r | |
112 | **/\r | |
113 | VOID\r | |
114 | PrintHddInfo (\r | |
115 | IN HDD_INFO *HddInfo\r | |
116 | )\r | |
117 | {\r | |
118 | UINTN Index;\r | |
119 | \r | |
120 | DEBUG ((EFI_D_INFO, "\n"));\r | |
121 | for (Index = 0; Index < MAX_IDE_CONTROLLER; Index++) {\r | |
122 | DEBUG ((EFI_D_INFO, "Index - %04x\n", Index));\r | |
123 | DEBUG ((EFI_D_INFO, " Status - %04x\n", (UINTN)HddInfo[Index].Status));\r | |
124 | DEBUG ((EFI_D_INFO, " B/D/F - %02x/%02x/%02x\n", (UINTN)HddInfo[Index].Bus, (UINTN)HddInfo[Index].Device, (UINTN)HddInfo[Index].Function));\r | |
125 | DEBUG ((EFI_D_INFO, " Command - %04x\n", HddInfo[Index].CommandBaseAddress));\r | |
126 | DEBUG ((EFI_D_INFO, " Control - %04x\n", HddInfo[Index].ControlBaseAddress));\r | |
127 | DEBUG ((EFI_D_INFO, " BusMaster - %04x\n", HddInfo[Index].BusMasterAddress));\r | |
128 | DEBUG ((EFI_D_INFO, " HddIrq - %02x\n", HddInfo[Index].HddIrq));\r | |
129 | DEBUG ((EFI_D_INFO, " IdentifyDrive[0].Raw[0] - %x\n", HddInfo[Index].IdentifyDrive[0].Raw[0]));\r | |
130 | DEBUG ((EFI_D_INFO, " IdentifyDrive[1].Raw[0] - %x\n", HddInfo[Index].IdentifyDrive[1].Raw[0]));\r | |
131 | }\r | |
132 | \r | |
133 | DEBUG ((EFI_D_INFO, "\n"));\r | |
134 | \r | |
135 | return ;\r | |
136 | }\r | |
137 | \r | |
7dad86fc RN |
138 | /**\r |
139 | Print the PCI Interrupt Line and Interrupt Pin registers.\r | |
140 | **/\r | |
141 | VOID\r | |
142 | PrintPciInterruptRegister (\r | |
143 | VOID\r | |
144 | )\r | |
145 | {\r | |
146 | EFI_STATUS Status;\r | |
147 | UINTN Index;\r | |
148 | EFI_HANDLE *Handles;\r | |
149 | UINTN HandleNum;\r | |
150 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
151 | UINT8 Interrupt[2];\r | |
152 | UINTN Segment;\r | |
153 | UINTN Bus;\r | |
154 | UINTN Device;\r | |
155 | UINTN Function;\r | |
156 | \r | |
157 | gBS->LocateHandleBuffer (\r | |
158 | ByProtocol,\r | |
159 | &gEfiPciIoProtocolGuid,\r | |
160 | NULL,\r | |
161 | &HandleNum,\r | |
162 | &Handles\r | |
163 | );\r | |
164 | \r | |
165 | Bus = 0;\r | |
166 | Device = 0;\r | |
167 | Function = 0;\r | |
168 | \r | |
169 | DEBUG ((EFI_D_INFO, "\n"));\r | |
170 | DEBUG ((EFI_D_INFO, " bb/dd/ff interrupt line interrupt pin\n"));\r | |
171 | DEBUG ((EFI_D_INFO, "======================================\n"));\r | |
172 | for (Index = 0; Index < HandleNum; Index++) {\r | |
173 | Status = gBS->HandleProtocol (Handles[Index], &gEfiPciIoProtocolGuid, (VOID **) &PciIo);\r | |
174 | if (!EFI_ERROR (Status)) {\r | |
175 | Status = PciIo->Pci.Read (\r | |
176 | PciIo,\r | |
177 | EfiPciIoWidthUint8,\r | |
178 | PCI_INT_LINE_OFFSET,\r | |
179 | 2,\r | |
180 | Interrupt\r | |
181 | );\r | |
182 | }\r | |
183 | if (!EFI_ERROR (Status)) {\r | |
184 | Status = PciIo->GetLocation (\r | |
185 | PciIo,\r | |
186 | &Segment,\r | |
187 | &Bus,\r | |
188 | &Device,\r | |
189 | &Function\r | |
190 | );\r | |
191 | }\r | |
192 | if (!EFI_ERROR (Status)) {\r | |
193 | DEBUG ((EFI_D_INFO, " %02x/%02x/%02x 0x%02x 0x%02x\n",\r | |
194 | Bus, Device, Function, Interrupt[0], Interrupt[1]));\r | |
195 | }\r | |
196 | }\r | |
197 | DEBUG ((EFI_D_INFO, "\n"));\r | |
198 | \r | |
199 | if (Handles != NULL) {\r | |
200 | FreePool (Handles);\r | |
201 | }\r | |
202 | }\r | |
203 | \r | |
bcecde14 | 204 | /**\r |
205 | Identify drive data must be updated to actual parameters before boot.\r | |
206 | \r | |
207 | @param IdentifyDriveData ATA Identify Data\r | |
208 | \r | |
209 | **/\r | |
210 | VOID\r | |
211 | UpdateIdentifyDriveData (\r | |
212 | IN UINT8 *IdentifyDriveData\r | |
213 | );\r | |
214 | \r | |
215 | /**\r | |
216 | Update SIO data.\r | |
217 | \r | |
218 | @param Private Legacy BIOS Instance data\r | |
219 | \r | |
220 | @retval EFI_SUCCESS Removable media not present\r | |
221 | \r | |
222 | **/\r | |
223 | EFI_STATUS\r | |
224 | UpdateSioData (\r | |
225 | IN LEGACY_BIOS_INSTANCE *Private\r | |
226 | )\r | |
227 | {\r | |
228 | EFI_STATUS Status;\r | |
229 | UINTN Index;\r | |
230 | UINTN Index1;\r | |
231 | UINT8 LegacyInterrupts[16];\r | |
232 | EFI_LEGACY_IRQ_ROUTING_ENTRY *RoutingTable;\r | |
233 | UINTN RoutingTableEntries;\r | |
234 | EFI_LEGACY_IRQ_PRIORITY_TABLE_ENTRY *IrqPriorityTable;\r | |
235 | UINTN NumberPriorityEntries;\r | |
236 | EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;\r | |
237 | UINT8 HddIrq;\r | |
238 | UINT16 LegacyInt;\r | |
239 | UINT16 LegMask;\r | |
240 | UINT32 Register;\r | |
241 | UINTN HandleCount;\r | |
242 | EFI_HANDLE *HandleBuffer;\r | |
243 | EFI_ISA_IO_PROTOCOL *IsaIo;\r | |
244 | \r | |
245 | LegacyInt = 0;\r | |
246 | HandleBuffer = NULL;\r | |
247 | \r | |
248 | EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;\r | |
249 | LegacyBiosBuildSioData (Private);\r | |
250 | SetMem (LegacyInterrupts, sizeof (LegacyInterrupts), 0);\r | |
251 | \r | |
252 | //\r | |
253 | // Create list of legacy interrupts.\r | |
254 | //\r | |
255 | for (Index = 0; Index < 4; Index++) {\r | |
256 | LegacyInterrupts[Index] = EfiToLegacy16BootTable->SioData.Serial[Index].Irq;\r | |
257 | }\r | |
258 | \r | |
259 | for (Index = 4; Index < 7; Index++) {\r | |
260 | LegacyInterrupts[Index] = EfiToLegacy16BootTable->SioData.Parallel[Index - 4].Irq;\r | |
261 | }\r | |
262 | \r | |
263 | LegacyInterrupts[7] = EfiToLegacy16BootTable->SioData.Floppy.Irq;\r | |
264 | \r | |
265 | //\r | |
266 | // Get Legacy Hdd IRQs. If native mode treat as PCI\r | |
267 | //\r | |
268 | for (Index = 0; Index < 2; Index++) {\r | |
269 | HddIrq = EfiToLegacy16BootTable->HddInfo[Index].HddIrq;\r | |
270 | if ((HddIrq != 0) && ((HddIrq == 15) || (HddIrq == 14))) {\r | |
271 | LegacyInterrupts[Index + 8] = HddIrq;\r | |
272 | }\r | |
273 | }\r | |
274 | \r | |
275 | Private->LegacyBiosPlatform->GetRoutingTable (\r | |
276 | Private->LegacyBiosPlatform,\r | |
277 | (VOID *) &RoutingTable,\r | |
278 | &RoutingTableEntries,\r | |
279 | NULL,\r | |
280 | NULL,\r | |
281 | (VOID **) &IrqPriorityTable,\r | |
282 | &NumberPriorityEntries\r | |
283 | );\r | |
284 | //\r | |
285 | // Remove legacy interrupts from the list of PCI interrupts available.\r | |
286 | //\r | |
287 | for (Index = 0; Index <= 0x0b; Index++) {\r | |
288 | for (Index1 = 0; Index1 <= NumberPriorityEntries; Index1++) {\r | |
289 | if (LegacyInterrupts[Index] != 0) {\r | |
290 | LegacyInt = (UINT16) (LegacyInt | (1 << LegacyInterrupts[Index]));\r | |
291 | if (LegacyInterrupts[Index] == IrqPriorityTable[Index1].Irq) {\r | |
292 | IrqPriorityTable[Index1].Used = LEGACY_USED;\r | |
293 | }\r | |
294 | }\r | |
295 | }\r | |
296 | }\r | |
297 | \r | |
298 | Private->Legacy8259->GetMask (\r | |
299 | Private->Legacy8259,\r | |
300 | &LegMask,\r | |
301 | NULL,\r | |
302 | NULL,\r | |
303 | NULL\r | |
304 | );\r | |
305 | \r | |
306 | //\r | |
307 | // Set SIO interrupts and disable mouse. Let mouse driver\r | |
308 | // re-enable it.\r | |
309 | //\r | |
310 | LegMask = (UINT16) ((LegMask &~LegacyInt) | 0x1000);\r | |
311 | Private->Legacy8259->SetMask (\r | |
312 | Private->Legacy8259,\r | |
313 | &LegMask,\r | |
314 | NULL,\r | |
315 | NULL,\r | |
316 | NULL\r | |
317 | );\r | |
318 | \r | |
319 | //\r | |
320 | // Disable mouse in keyboard controller\r | |
321 | //\r | |
322 | Register = 0xA7;\r | |
323 | Status = gBS->LocateHandleBuffer (\r | |
324 | ByProtocol,\r | |
325 | &gEfiIsaIoProtocolGuid,\r | |
326 | NULL,\r | |
327 | &HandleCount,\r | |
328 | &HandleBuffer\r | |
329 | );\r | |
330 | if (EFI_ERROR (Status)) {\r | |
331 | return Status;\r | |
332 | }\r | |
333 | \r | |
334 | for (Index = 0; Index < HandleCount; Index++) {\r | |
335 | Status = gBS->HandleProtocol (\r | |
336 | HandleBuffer[Index],\r | |
337 | &gEfiIsaIoProtocolGuid,\r | |
338 | (VOID **) &IsaIo\r | |
339 | );\r | |
340 | ASSERT_EFI_ERROR (Status);\r | |
341 | IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, 0x64, 1, &Register);\r | |
342 | \r | |
343 | }\r | |
344 | \r | |
345 | if (HandleBuffer != NULL) {\r | |
346 | FreePool (HandleBuffer);\r | |
347 | }\r | |
348 | \r | |
349 | return EFI_SUCCESS;\r | |
350 | \r | |
351 | }\r | |
352 | \r | |
353 | /**\r | |
354 | Identify drive data must be updated to actual parameters before boot.\r | |
355 | This requires updating the checksum, if it exists.\r | |
356 | \r | |
357 | @param IdentifyDriveData ATA Identify Data\r | |
358 | @param Checksum checksum of the ATA Identify Data\r | |
359 | \r | |
360 | @retval EFI_SUCCESS checksum calculated\r | |
361 | @retval EFI_SECURITY_VIOLATION IdentifyData invalid\r | |
362 | \r | |
363 | **/\r | |
364 | EFI_STATUS\r | |
365 | CalculateIdentifyDriveChecksum (\r | |
366 | IN UINT8 *IdentifyDriveData,\r | |
367 | OUT UINT8 *Checksum\r | |
368 | )\r | |
369 | {\r | |
370 | UINTN Index;\r | |
371 | UINT8 LocalChecksum;\r | |
372 | LocalChecksum = 0;\r | |
373 | *Checksum = 0;\r | |
374 | if (IdentifyDriveData[510] != 0xA5) {\r | |
375 | return EFI_SECURITY_VIOLATION;\r | |
376 | }\r | |
377 | \r | |
378 | for (Index = 0; Index < 512; Index++) {\r | |
379 | LocalChecksum = (UINT8) (LocalChecksum + IdentifyDriveData[Index]);\r | |
380 | }\r | |
381 | \r | |
382 | *Checksum = LocalChecksum;\r | |
383 | return EFI_SUCCESS;\r | |
384 | }\r | |
385 | \r | |
386 | \r | |
387 | /**\r | |
388 | Identify drive data must be updated to actual parameters before boot.\r | |
389 | \r | |
390 | @param IdentifyDriveData ATA Identify Data\r | |
391 | \r | |
392 | \r | |
393 | **/\r | |
394 | VOID\r | |
395 | UpdateIdentifyDriveData (\r | |
396 | IN UINT8 *IdentifyDriveData\r | |
397 | )\r | |
398 | {\r | |
399 | UINT16 NumberCylinders;\r | |
400 | UINT16 NumberHeads;\r | |
401 | UINT16 NumberSectorsTrack;\r | |
402 | UINT32 CapacityInSectors;\r | |
403 | UINT8 OriginalChecksum;\r | |
404 | UINT8 FinalChecksum;\r | |
405 | EFI_STATUS Status;\r | |
406 | ATAPI_IDENTIFY *ReadInfo;\r | |
407 | \r | |
408 | //\r | |
409 | // Status indicates if Integrity byte is correct. Checksum should be\r | |
410 | // 0 if valid.\r | |
411 | //\r | |
412 | ReadInfo = (ATAPI_IDENTIFY *) IdentifyDriveData;\r | |
413 | Status = CalculateIdentifyDriveChecksum (IdentifyDriveData, &OriginalChecksum);\r | |
414 | if (OriginalChecksum != 0) {\r | |
415 | Status = EFI_SECURITY_VIOLATION;\r | |
416 | }\r | |
417 | //\r | |
418 | // If NumberCylinders = 0 then do data(Controller present but don drive attached).\r | |
419 | //\r | |
420 | NumberCylinders = ReadInfo->Raw[1];\r | |
421 | if (NumberCylinders != 0) {\r | |
422 | ReadInfo->Raw[54] = NumberCylinders;\r | |
423 | \r | |
424 | NumberHeads = ReadInfo->Raw[3];\r | |
425 | ReadInfo->Raw[55] = NumberHeads;\r | |
426 | \r | |
427 | NumberSectorsTrack = ReadInfo->Raw[6];\r | |
428 | ReadInfo->Raw[56] = NumberSectorsTrack;\r | |
429 | \r | |
430 | //\r | |
431 | // Copy Multisector info and set valid bit.\r | |
432 | //\r | |
433 | ReadInfo->Raw[59] = (UINT16) (ReadInfo->Raw[47] + 0x100);\r | |
434 | CapacityInSectors = (UINT32) ((UINT32) (NumberCylinders) * (UINT32) (NumberHeads) * (UINT32) (NumberSectorsTrack));\r | |
435 | ReadInfo->Raw[57] = (UINT16) (CapacityInSectors >> 16);\r | |
436 | ReadInfo->Raw[58] = (UINT16) (CapacityInSectors & 0xffff);\r | |
437 | if (Status == EFI_SUCCESS) {\r | |
438 | //\r | |
439 | // Forece checksum byte to 0 and get new checksum.\r | |
440 | //\r | |
441 | ReadInfo->Raw[255] &= 0xff;\r | |
442 | CalculateIdentifyDriveChecksum (IdentifyDriveData, &FinalChecksum);\r | |
443 | \r | |
444 | //\r | |
445 | // Force new checksum such that sum is 0.\r | |
446 | //\r | |
447 | FinalChecksum = (UINT8) ((UINT8)0 - FinalChecksum);\r | |
448 | ReadInfo->Raw[255] = (UINT16) (ReadInfo->Raw[255] | (FinalChecksum << 8));\r | |
449 | }\r | |
450 | }\r | |
451 | }\r | |
452 | \r | |
453 | /**\r | |
454 | Identify drive data must be updated to actual parameters before boot.\r | |
455 | Do for all drives.\r | |
456 | \r | |
457 | @param Private Legacy BIOS Instance data\r | |
458 | \r | |
459 | \r | |
460 | **/\r | |
461 | VOID\r | |
462 | UpdateAllIdentifyDriveData (\r | |
463 | IN LEGACY_BIOS_INSTANCE *Private\r | |
464 | )\r | |
465 | {\r | |
466 | UINTN Index;\r | |
467 | HDD_INFO *HddInfo;\r | |
468 | \r | |
469 | HddInfo = &Private->IntThunk->EfiToLegacy16BootTable.HddInfo[0];\r | |
470 | \r | |
471 | for (Index = 0; Index < MAX_IDE_CONTROLLER; Index++) {\r | |
472 | //\r | |
473 | // Each controller can have 2 devices. Update for each device\r | |
474 | //\r | |
475 | if ((HddInfo[Index].Status & HDD_MASTER_IDE) != 0) {\r | |
476 | UpdateIdentifyDriveData ((UINT8 *) (&HddInfo[Index].IdentifyDrive[0].Raw[0]));\r | |
477 | }\r | |
478 | \r | |
479 | if ((HddInfo[Index].Status & HDD_SLAVE_IDE) != 0) {\r | |
480 | UpdateIdentifyDriveData ((UINT8 *) (&HddInfo[Index].IdentifyDrive[1].Raw[0]));\r | |
481 | }\r | |
482 | }\r | |
483 | }\r | |
484 | \r | |
485 | /**\r | |
486 | Enable ide controller. This gets disabled when LegacyBoot.c is about\r | |
487 | to run the Option ROMs.\r | |
488 | \r | |
489 | @param Private Legacy BIOS Instance data\r | |
490 | \r | |
491 | \r | |
492 | **/\r | |
493 | VOID\r | |
494 | EnableIdeController (\r | |
495 | IN LEGACY_BIOS_INSTANCE *Private\r | |
496 | )\r | |
497 | {\r | |
498 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
499 | EFI_STATUS Status;\r | |
500 | EFI_HANDLE IdeController;\r | |
501 | UINT8 ByteBuffer;\r | |
502 | UINTN HandleCount;\r | |
503 | EFI_HANDLE *HandleBuffer;\r | |
504 | \r | |
505 | Status = Private->LegacyBiosPlatform->GetPlatformHandle (\r | |
506 | Private->LegacyBiosPlatform,\r | |
507 | EfiGetPlatformIdeHandle,\r | |
508 | 0,\r | |
509 | &HandleBuffer,\r | |
510 | &HandleCount,\r | |
511 | NULL\r | |
512 | );\r | |
513 | if (!EFI_ERROR (Status)) {\r | |
514 | IdeController = HandleBuffer[0];\r | |
515 | Status = gBS->HandleProtocol (\r | |
516 | IdeController,\r | |
517 | &gEfiPciIoProtocolGuid,\r | |
518 | (VOID **) &PciIo\r | |
519 | );\r | |
520 | ByteBuffer = 0x1f;\r | |
521 | if (!EFI_ERROR (Status)) {\r | |
522 | PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 0x04, 1, &ByteBuffer);\r | |
523 | }\r | |
524 | }\r | |
525 | }\r | |
526 | \r | |
527 | \r | |
528 | /**\r | |
529 | Enable ide controller. This gets disabled when LegacyBoot.c is about\r | |
530 | to run the Option ROMs.\r | |
531 | \r | |
532 | @param Private Legacy BIOS Instance data\r | |
533 | \r | |
534 | \r | |
535 | **/\r | |
536 | VOID\r | |
537 | EnableAllControllers (\r | |
538 | IN LEGACY_BIOS_INSTANCE *Private\r | |
539 | )\r | |
540 | {\r | |
541 | UINTN HandleCount;\r | |
542 | EFI_HANDLE *HandleBuffer;\r | |
543 | UINTN Index;\r | |
544 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
545 | PCI_TYPE01 PciConfigHeader;\r | |
546 | EFI_STATUS Status;\r | |
547 | \r | |
548 | //\r | |
549 | //\r | |
550 | //\r | |
551 | EnableIdeController (Private);\r | |
552 | \r | |
553 | //\r | |
554 | // Assumption is table is built from low bus to high bus numbers.\r | |
555 | //\r | |
556 | Status = gBS->LocateHandleBuffer (\r | |
557 | ByProtocol,\r | |
558 | &gEfiPciIoProtocolGuid,\r | |
559 | NULL,\r | |
560 | &HandleCount,\r | |
561 | &HandleBuffer\r | |
562 | );\r | |
563 | ASSERT_EFI_ERROR (Status);\r | |
564 | \r | |
565 | for (Index = 0; Index < HandleCount; Index++) {\r | |
566 | Status = gBS->HandleProtocol (\r | |
567 | HandleBuffer[Index],\r | |
568 | &gEfiPciIoProtocolGuid,\r | |
569 | (VOID **) &PciIo\r | |
570 | );\r | |
571 | ASSERT_EFI_ERROR (Status);\r | |
572 | \r | |
573 | PciIo->Pci.Read (\r | |
574 | PciIo,\r | |
575 | EfiPciIoWidthUint32,\r | |
576 | 0,\r | |
577 | sizeof (PciConfigHeader) / sizeof (UINT32),\r | |
578 | &PciConfigHeader\r | |
579 | );\r | |
580 | \r | |
581 | //\r | |
582 | // We do not enable PPB here. This is for HotPlug Consideration.\r | |
583 | // The Platform HotPlug Driver is responsible for Padding enough hot plug\r | |
584 | // resources. It is also responsible for enable this bridge. If it\r | |
585 | // does not pad it. It will cause some early Windows fail to installation.\r | |
586 | // If the platform driver does not pad resource for PPB, PPB should be in\r | |
587 | // un-enabled state to let Windows know that this PPB is not configured by\r | |
588 | // BIOS. So Windows will allocate default resource for PPB.\r | |
589 | //\r | |
590 | // The reason for why we enable the command register is:\r | |
591 | // The CSM will use the IO bar to detect some IRQ status, if the command\r | |
592 | // is disabled, the IO resource will be out of scope.\r | |
593 | // For example:\r | |
594 | // We installed a legacy IRQ handle for a PCI IDE controller. When IRQ\r | |
595 | // comes up, the handle will check the IO space to identify is the\r | |
596 | // controller generated the IRQ source.\r | |
597 | // If the IO command is not enabled, the IRQ handler will has wrong\r | |
598 | // information. It will cause IRQ storm when the correctly IRQ handler fails\r | |
599 | // to run.\r | |
600 | //\r | |
601 | if (!(IS_PCI_VGA (&PciConfigHeader) ||\r | |
602 | IS_PCI_OLD_VGA (&PciConfigHeader) ||\r | |
603 | IS_PCI_IDE (&PciConfigHeader) ||\r | |
604 | IS_PCI_P2P (&PciConfigHeader) ||\r | |
605 | IS_PCI_P2P_SUB (&PciConfigHeader) ||\r | |
606 | IS_PCI_LPC (&PciConfigHeader) )) {\r | |
607 | \r | |
608 | PciConfigHeader.Hdr.Command |= 0x1f;\r | |
609 | \r | |
610 | PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, 4, 1, &PciConfigHeader.Hdr.Command);\r | |
611 | }\r | |
612 | }\r | |
613 | }\r | |
614 | \r | |
615 | /**\r | |
616 | The following routines are identical in operation, so combine\r | |
617 | for code compaction:\r | |
618 | EfiGetPlatformBinaryGetMpTable\r | |
619 | EfiGetPlatformBinaryGetOemIntData\r | |
620 | EfiGetPlatformBinaryGetOem32Data\r | |
621 | EfiGetPlatformBinaryGetOem16Data\r | |
622 | \r | |
623 | @param This Protocol instance pointer.\r | |
624 | @param Id Table/Data identifier\r | |
625 | \r | |
626 | @retval EFI_SUCCESS Success\r | |
627 | @retval EFI_INVALID_PARAMETER Invalid ID\r | |
628 | @retval EFI_OUT_OF_RESOURCES no resource to get data or table\r | |
629 | \r | |
630 | **/\r | |
631 | EFI_STATUS\r | |
632 | LegacyGetDataOrTable (\r | |
633 | IN EFI_LEGACY_BIOS_PROTOCOL *This,\r | |
634 | IN EFI_GET_PLATFORM_INFO_MODE Id\r | |
635 | )\r | |
636 | {\r | |
637 | VOID *Table;\r | |
638 | UINT32 TablePtr;\r | |
639 | UINTN TableSize;\r | |
640 | UINTN Alignment;\r | |
641 | UINTN Location;\r | |
642 | EFI_STATUS Status;\r | |
643 | EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *LegacyBiosPlatform;\r | |
644 | EFI_COMPATIBILITY16_TABLE *Legacy16Table;\r | |
645 | EFI_IA32_REGISTER_SET Regs;\r | |
646 | LEGACY_BIOS_INSTANCE *Private;\r | |
647 | \r | |
648 | Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r | |
649 | \r | |
650 | LegacyBiosPlatform = Private->LegacyBiosPlatform;\r | |
651 | Legacy16Table = Private->Legacy16Table;\r | |
652 | \r | |
653 | //\r | |
654 | // Phase 1 - get an address allocated in 16-bit code\r | |
655 | //\r | |
656 | while (TRUE) {\r | |
657 | switch (Id) {\r | |
658 | case EfiGetPlatformBinaryMpTable:\r | |
659 | case EfiGetPlatformBinaryOemIntData:\r | |
660 | case EfiGetPlatformBinaryOem32Data:\r | |
661 | case EfiGetPlatformBinaryOem16Data:\r | |
662 | {\r | |
663 | Status = LegacyBiosPlatform->GetPlatformInfo (\r | |
664 | LegacyBiosPlatform,\r | |
665 | Id,\r | |
666 | (VOID *) &Table,\r | |
667 | &TableSize,\r | |
668 | &Location,\r | |
669 | &Alignment,\r | |
670 | 0,\r | |
671 | 0\r | |
672 | );\r | |
673 | DEBUG ((EFI_D_INFO, "LegacyGetDataOrTable - ID: %x, %r\n", (UINTN)Id, Status));\r | |
674 | DEBUG ((EFI_D_INFO, " Table - %x, Size - %x, Location - %x, Alignment - %x\n", (UINTN)Table, (UINTN)TableSize, (UINTN)Location, (UINTN)Alignment));\r | |
675 | break;\r | |
676 | }\r | |
677 | \r | |
678 | default:\r | |
679 | {\r | |
680 | return EFI_INVALID_PARAMETER;\r | |
681 | }\r | |
682 | }\r | |
683 | \r | |
684 | if (EFI_ERROR (Status)) {\r | |
685 | return Status;\r | |
686 | }\r | |
687 | \r | |
688 | ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r | |
689 | Regs.X.AX = Legacy16GetTableAddress;\r | |
690 | Regs.X.CX = (UINT16) TableSize;\r | |
691 | Regs.X.BX = (UINT16) Location;\r | |
692 | Regs.X.DX = (UINT16) Alignment;\r | |
693 | Private->LegacyBios.FarCall86 (\r | |
694 | This,\r | |
695 | Private->Legacy16CallSegment,\r | |
696 | Private->Legacy16CallOffset,\r | |
697 | &Regs,\r | |
698 | NULL,\r | |
699 | 0\r | |
700 | );\r | |
701 | \r | |
702 | if (Regs.X.AX != 0) {\r | |
703 | DEBUG ((EFI_D_ERROR, "Table ID %x length insufficient\n", Id));\r | |
704 | return EFI_OUT_OF_RESOURCES;\r | |
705 | } else {\r | |
706 | break;\r | |
707 | }\r | |
708 | }\r | |
709 | //\r | |
710 | // Phase 2 Call routine second time with address to allow address adjustment\r | |
711 | //\r | |
712 | Status = LegacyBiosPlatform->GetPlatformInfo (\r | |
713 | LegacyBiosPlatform,\r | |
714 | Id,\r | |
715 | (VOID *) &Table,\r | |
716 | &TableSize,\r | |
717 | &Location,\r | |
718 | &Alignment,\r | |
719 | Regs.X.DS,\r | |
720 | Regs.X.BX\r | |
721 | );\r | |
722 | switch (Id) {\r | |
723 | case EfiGetPlatformBinaryMpTable:\r | |
724 | {\r | |
725 | Legacy16Table->MpTablePtr = (UINT32) (Regs.X.DS * 16 + Regs.X.BX);\r | |
726 | Legacy16Table->MpTableLength = (UINT32)TableSize;\r | |
727 | DEBUG ((EFI_D_INFO, "MP table in legacy region - %x\n", (UINTN)Legacy16Table->MpTablePtr));\r | |
728 | break;\r | |
729 | }\r | |
730 | \r | |
731 | case EfiGetPlatformBinaryOemIntData:\r | |
732 | {\r | |
733 | \r | |
734 | Legacy16Table->OemIntSegment = Regs.X.DS;\r | |
735 | Legacy16Table->OemIntOffset = Regs.X.BX;\r | |
736 | DEBUG ((EFI_D_INFO, "OemInt table in legacy region - %04x:%04x\n", (UINTN)Legacy16Table->OemIntSegment, (UINTN)Legacy16Table->OemIntOffset));\r | |
737 | break;\r | |
738 | }\r | |
739 | \r | |
740 | case EfiGetPlatformBinaryOem32Data:\r | |
741 | {\r | |
742 | Legacy16Table->Oem32Segment = Regs.X.DS;\r | |
743 | Legacy16Table->Oem32Offset = Regs.X.BX;\r | |
744 | DEBUG ((EFI_D_INFO, "Oem32 table in legacy region - %04x:%04x\n", (UINTN)Legacy16Table->Oem32Segment, (UINTN)Legacy16Table->Oem32Offset));\r | |
745 | break;\r | |
746 | }\r | |
747 | \r | |
748 | case EfiGetPlatformBinaryOem16Data:\r | |
749 | {\r | |
750 | //\r | |
751 | // Legacy16Table->Oem16Segment = Regs.X.DS;\r | |
752 | // Legacy16Table->Oem16Offset = Regs.X.BX;\r | |
753 | DEBUG ((EFI_D_INFO, "Oem16 table in legacy region - %04x:%04x\n", (UINTN)Legacy16Table->Oem16Segment, (UINTN)Legacy16Table->Oem16Offset));\r | |
754 | break;\r | |
755 | }\r | |
756 | \r | |
757 | default:\r | |
758 | {\r | |
759 | return EFI_INVALID_PARAMETER;\r | |
760 | }\r | |
761 | }\r | |
762 | \r | |
763 | if (EFI_ERROR (Status)) {\r | |
764 | return Status;\r | |
765 | }\r | |
766 | //\r | |
767 | // Phase 3 Copy table to final location\r | |
768 | //\r | |
769 | TablePtr = (UINT32) (Regs.X.DS * 16 + Regs.X.BX);\r | |
770 | \r | |
771 | CopyMem (\r | |
772 | (VOID *) (UINTN)TablePtr,\r | |
773 | Table,\r | |
774 | TableSize\r | |
775 | );\r | |
776 | \r | |
777 | return EFI_SUCCESS;\r | |
778 | }\r | |
779 | \r | |
780 | \r | |
781 | /**\r | |
782 | Assign drive number to legacy HDD drives prior to booting an EFI\r | |
783 | aware OS so the OS can access drives without an EFI driver.\r | |
784 | Note: BBS compliant drives ARE NOT available until this call by\r | |
785 | either shell or EFI.\r | |
786 | \r | |
787 | @param This Protocol instance pointer.\r | |
788 | \r | |
789 | @retval EFI_SUCCESS Drive numbers assigned\r | |
790 | \r | |
791 | **/\r | |
792 | EFI_STATUS\r | |
793 | GenericLegacyBoot (\r | |
794 | IN EFI_LEGACY_BIOS_PROTOCOL *This\r | |
795 | )\r | |
796 | {\r | |
797 | EFI_STATUS Status;\r | |
798 | LEGACY_BIOS_INSTANCE *Private;\r | |
799 | EFI_IA32_REGISTER_SET Regs;\r | |
800 | EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;\r | |
801 | EFI_LEGACY_BIOS_PLATFORM_PROTOCOL *LegacyBiosPlatform;\r | |
802 | UINTN CopySize;\r | |
803 | VOID *AcpiPtr;\r | |
804 | HDD_INFO *HddInfo;\r | |
805 | HDD_INFO *LocalHddInfo;\r | |
806 | UINTN Index;\r | |
807 | EFI_COMPATIBILITY16_TABLE *Legacy16Table;\r | |
808 | UINT32 *BdaPtr;\r | |
809 | UINT16 HddCount;\r | |
810 | UINT16 BbsCount;\r | |
811 | BBS_TABLE *LocalBbsTable;\r | |
812 | UINT32 *BaseVectorMaster;\r | |
813 | EFI_TIME BootTime;\r | |
814 | UINT32 LocalTime;\r | |
815 | EFI_HANDLE IdeController;\r | |
816 | UINTN HandleCount;\r | |
817 | EFI_HANDLE *HandleBuffer;\r | |
818 | VOID *SmbiosTable;\r | |
819 | VOID *AcpiTable;\r | |
820 | UINTN ShadowAddress;\r | |
821 | UINT32 Granularity;\r | |
bcecde14 | 822 | \r |
823 | LocalHddInfo = NULL;\r | |
824 | HddCount = 0;\r | |
825 | BbsCount = 0;\r | |
826 | LocalBbsTable = NULL;\r | |
bcecde14 | 827 | \r |
828 | Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r | |
829 | DEBUG_CODE (\r | |
830 | DEBUG ((EFI_D_ERROR, "Start of legacy boot\n"));\r | |
831 | );\r | |
832 | \r | |
833 | Legacy16Table = Private->Legacy16Table;\r | |
834 | EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;\r | |
835 | HddInfo = &EfiToLegacy16BootTable->HddInfo[0];\r | |
836 | \r | |
837 | LegacyBiosPlatform = Private->LegacyBiosPlatform;\r | |
838 | \r | |
839 | EfiToLegacy16BootTable->MajorVersion = EFI_TO_LEGACY_MAJOR_VERSION;\r | |
840 | EfiToLegacy16BootTable->MinorVersion = EFI_TO_LEGACY_MINOR_VERSION;\r | |
bcecde14 | 841 | \r |
842 | //\r | |
843 | // If booting to a legacy OS then force HDD drives to the appropriate\r | |
844 | // boot mode by calling GetIdeHandle.\r | |
845 | // A reconnect -r can force all HDDs back to native mode.\r | |
846 | //\r | |
847 | IdeController = NULL;\r | |
848 | if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r | |
849 | Status = LegacyBiosPlatform->GetPlatformHandle (\r | |
850 | Private->LegacyBiosPlatform,\r | |
851 | EfiGetPlatformIdeHandle,\r | |
852 | 0,\r | |
853 | &HandleBuffer,\r | |
854 | &HandleCount,\r | |
855 | NULL\r | |
856 | );\r | |
857 | if (!EFI_ERROR (Status)) {\r | |
858 | IdeController = HandleBuffer[0];\r | |
859 | } \r | |
860 | }\r | |
861 | //\r | |
862 | // Unlock the Legacy BIOS region\r | |
863 | //\r | |
864 | Private->LegacyRegion->UnLock (\r | |
865 | Private->LegacyRegion,\r | |
866 | 0xE0000,\r | |
867 | 0x20000,\r | |
868 | &Granularity\r | |
869 | );\r | |
870 | \r | |
871 | //\r | |
872 | // Reconstruct the Legacy16 boot memory map\r | |
873 | //\r | |
874 | LegacyBiosBuildE820 (Private, &CopySize);\r | |
875 | if (CopySize > Private->Legacy16Table->E820Length) {\r | |
876 | ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r | |
877 | Regs.X.AX = Legacy16GetTableAddress;\r | |
878 | Regs.X.CX = (UINT16) CopySize;\r | |
879 | Private->LegacyBios.FarCall86 (\r | |
880 | &Private->LegacyBios,\r | |
881 | Private->Legacy16Table->Compatibility16CallSegment,\r | |
882 | Private->Legacy16Table->Compatibility16CallOffset,\r | |
883 | &Regs,\r | |
884 | NULL,\r | |
885 | 0\r | |
886 | );\r | |
887 | \r | |
888 | Private->Legacy16Table->E820Pointer = (UINT32) (Regs.X.DS * 16 + Regs.X.BX);\r | |
889 | Private->Legacy16Table->E820Length = (UINT32) CopySize;\r | |
890 | if (Regs.X.AX != 0) {\r | |
891 | DEBUG ((EFI_D_ERROR, "Legacy16 E820 length insufficient\n"));\r | |
892 | } else {\r | |
893 | CopyMem (\r | |
894 | (VOID *)(UINTN) Private->Legacy16Table->E820Pointer,\r | |
895 | Private->E820Table,\r | |
896 | CopySize\r | |
897 | );\r | |
898 | }\r | |
899 | } else {\r | |
900 | CopyMem (\r | |
901 | (VOID *)(UINTN) Private->Legacy16Table->E820Pointer,\r | |
902 | Private->E820Table,\r | |
903 | CopySize\r | |
904 | );\r | |
905 | Private->Legacy16Table->E820Length = (UINT32) CopySize;\r | |
906 | }\r | |
907 | //\r | |
908 | // Get SMBIOS and ACPI table pointers\r | |
909 | //\r | |
910 | SmbiosTable = NULL;\r | |
911 | EfiGetSystemConfigurationTable (\r | |
912 | &gEfiSmbiosTableGuid,\r | |
913 | &SmbiosTable\r | |
914 | );\r | |
915 | //\r | |
916 | // We do not ASSERT if SmbiosTable not found. It is possbile that a platform does not produce SmbiosTable.\r | |
917 | //\r | |
918 | if (SmbiosTable == NULL) {\r | |
919 | DEBUG ((EFI_D_INFO, "Smbios table is not found!\n"));\r | |
920 | }\r | |
921 | EfiToLegacy16BootTable->SmbiosTable = (UINT32)(UINTN)SmbiosTable;\r | |
922 | \r | |
923 | AcpiTable = NULL;\r | |
924 | Status = EfiGetSystemConfigurationTable (\r | |
925 | &gEfiAcpi20TableGuid,\r | |
926 | &AcpiTable\r | |
927 | );\r | |
928 | if (EFI_ERROR (Status)) {\r | |
929 | Status = EfiGetSystemConfigurationTable (\r | |
930 | &gEfiAcpi10TableGuid,\r | |
931 | &AcpiTable\r | |
932 | );\r | |
933 | }\r | |
934 | //\r | |
935 | // We do not ASSERT if AcpiTable not found. It is possbile that a platform does not produce AcpiTable.\r | |
936 | //\r | |
937 | if (AcpiTable == NULL) {\r | |
938 | DEBUG ((EFI_D_INFO, "ACPI table is not found!\n"));\r | |
939 | }\r | |
940 | EfiToLegacy16BootTable->AcpiTable = (UINT32)(UINTN)AcpiTable;\r | |
941 | \r | |
942 | //\r | |
943 | // Get RSD Ptr table rev at offset 15 decimal\r | |
944 | // Rev = 0 Length is 20 decimal\r | |
945 | // Rev != 0 Length is UINT32 at offset 20 decimal\r | |
946 | //\r | |
947 | if (AcpiTable != NULL) {\r | |
948 | \r | |
949 | AcpiPtr = AcpiTable;\r | |
950 | if (*((UINT8 *) AcpiPtr + 15) == 0) {\r | |
951 | CopySize = 20;\r | |
952 | } else {\r | |
953 | AcpiPtr = ((UINT8 *) AcpiPtr + 20);\r | |
954 | CopySize = (*(UINT32 *) AcpiPtr);\r | |
955 | }\r | |
956 | \r | |
957 | CopyMem (\r | |
958 | (VOID *)(UINTN) Private->Legacy16Table->AcpiRsdPtrPointer,\r | |
959 | AcpiTable,\r | |
960 | CopySize\r | |
961 | );\r | |
962 | }\r | |
963 | //\r | |
964 | // Make sure all PCI Interrupt Line register are programmed to match 8259\r | |
965 | //\r | |
966 | PciProgramAllInterruptLineRegisters (Private);\r | |
967 | \r | |
968 | //\r | |
969 | // Unlock the Legacy BIOS region as PciProgramAllInterruptLineRegisters\r | |
970 | // can lock it.\r | |
971 | //\r | |
972 | Private->LegacyRegion->UnLock (\r | |
973 | Private->LegacyRegion,\r | |
974 | Private->BiosStart,\r | |
975 | Private->LegacyBiosImageSize,\r | |
976 | &Granularity\r | |
977 | );\r | |
978 | \r | |
979 | //\r | |
980 | // Configure Legacy Device Magic\r | |
981 | //\r | |
982 | // Only do this code if booting legacy OS\r | |
983 | //\r | |
984 | if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r | |
985 | UpdateSioData (Private);\r | |
986 | }\r | |
987 | //\r | |
988 | // Setup BDA and EBDA standard areas before Legacy Boot\r | |
989 | //\r | |
990 | LegacyBiosCompleteBdaBeforeBoot (Private);\r | |
991 | LegacyBiosCompleteStandardCmosBeforeBoot (Private);\r | |
992 | \r | |
993 | //\r | |
994 | // We must build IDE data, if it hasn't been done, before PciShadowRoms\r | |
995 | // to insure EFI drivers are connected.\r | |
996 | //\r | |
997 | LegacyBiosBuildIdeData (Private, &HddInfo, 1);\r | |
998 | UpdateAllIdentifyDriveData (Private);\r | |
999 | \r | |
1000 | //\r | |
1001 | // Clear IO BAR, if IDE controller in legacy mode.\r | |
1002 | //\r | |
1003 | InitLegacyIdeController (IdeController);\r | |
1004 | \r | |
1005 | //\r | |
1006 | // Generate number of ticks since midnight for BDA. DOS requires this\r | |
1007 | // for its time. We have to make assumptions as to how long following\r | |
1008 | // code takes since after PciShadowRoms PciIo is gone. Place result in\r | |
1009 | // 40:6C-6F\r | |
1010 | //\r | |
1011 | // Adjust value by 1 second.\r | |
1012 | //\r | |
1013 | gRT->GetTime (&BootTime, NULL);\r | |
1014 | LocalTime = BootTime.Hour * 3600 + BootTime.Minute * 60 + BootTime.Second;\r | |
1015 | LocalTime += 1;\r | |
1016 | \r | |
1017 | //\r | |
1018 | // Multiply result by 18.2 for number of ticks since midnight.\r | |
1019 | // Use 182/10 to avoid floating point math.\r | |
1020 | //\r | |
1021 | LocalTime = (LocalTime * 182) / 10;\r | |
1022 | BdaPtr = (UINT32 *) (UINTN)0x46C;\r | |
1023 | *BdaPtr = LocalTime;\r | |
1024 | \r | |
1025 | //\r | |
1026 | // Shadow PCI ROMs. We must do this near the end since this will kick\r | |
1027 | // of Native EFI drivers that may be needed to collect info for Legacy16\r | |
1028 | //\r | |
1029 | // WARNING: PciIo is gone after this call.\r | |
1030 | //\r | |
1031 | PciShadowRoms (Private);\r | |
1032 | \r | |
1033 | //\r | |
1034 | // Shadow PXE base code, BIS etc.\r | |
1035 | //\r | |
1036 | Private->LegacyRegion->UnLock (Private->LegacyRegion, 0xc0000, 0x40000, &Granularity);\r | |
1037 | ShadowAddress = Private->OptionRom;\r | |
1038 | Private->LegacyBiosPlatform->PlatformHooks (\r | |
1039 | Private->LegacyBiosPlatform,\r | |
1040 | EfiPlatformHookShadowServiceRoms,\r | |
1041 | 0,\r | |
1042 | 0,\r | |
1043 | &ShadowAddress,\r | |
1044 | Legacy16Table,\r | |
1045 | NULL\r | |
1046 | );\r | |
1047 | Private->OptionRom = (UINT32)ShadowAddress;\r | |
1048 | //\r | |
1049 | // Register Legacy SMI Handler\r | |
1050 | //\r | |
1051 | LegacyBiosPlatform->SmmInit (\r | |
1052 | LegacyBiosPlatform,\r | |
1053 | EfiToLegacy16BootTable\r | |
1054 | );\r | |
1055 | \r | |
1056 | //\r | |
1057 | // Let platform code know the boot options\r | |
1058 | //\r | |
1059 | LegacyBiosGetBbsInfo (\r | |
1060 | This,\r | |
1061 | &HddCount,\r | |
1062 | &LocalHddInfo,\r | |
1063 | &BbsCount,\r | |
1064 | &LocalBbsTable\r | |
1065 | );\r | |
1066 | \r | |
7dad86fc RN |
1067 | DEBUG_CODE (\r |
1068 | PrintPciInterruptRegister ();\r | |
1069 | PrintBbsTable (LocalBbsTable);\r | |
1070 | PrintHddInfo (LocalHddInfo);\r | |
1071 | );\r | |
bcecde14 | 1072 | //\r |
1073 | // If drive wasn't spun up then BuildIdeData may have found new drives.\r | |
1074 | // Need to update BBS boot priority.\r | |
1075 | //\r | |
1076 | for (Index = 0; Index < MAX_IDE_CONTROLLER; Index++) {\r | |
1077 | if ((LocalHddInfo[Index].IdentifyDrive[0].Raw[0] != 0) &&\r | |
1078 | (LocalBbsTable[2 * Index + 1].BootPriority == BBS_IGNORE_ENTRY)\r | |
1079 | ) {\r | |
1080 | LocalBbsTable[2 * Index + 1].BootPriority = BBS_UNPRIORITIZED_ENTRY;\r | |
1081 | }\r | |
1082 | \r | |
1083 | if ((LocalHddInfo[Index].IdentifyDrive[1].Raw[0] != 0) &&\r | |
1084 | (LocalBbsTable[2 * Index + 2].BootPriority == BBS_IGNORE_ENTRY)\r | |
1085 | ) {\r | |
1086 | LocalBbsTable[2 * Index + 2].BootPriority = BBS_UNPRIORITIZED_ENTRY;\r | |
1087 | }\r | |
1088 | }\r | |
1089 | \r | |
1090 | Private->LegacyRegion->UnLock (\r | |
1091 | Private->LegacyRegion,\r | |
1092 | 0xc0000,\r | |
1093 | 0x40000,\r | |
1094 | &Granularity\r | |
1095 | );\r | |
1096 | \r | |
1097 | LegacyBiosPlatform->PrepareToBoot (\r | |
1098 | LegacyBiosPlatform,\r | |
1099 | mBbsDevicePathPtr,\r | |
1100 | mBbsTable,\r | |
1101 | mLoadOptionsSize,\r | |
1102 | mLoadOptions,\r | |
1103 | (VOID *) &Private->IntThunk->EfiToLegacy16BootTable\r | |
1104 | );\r | |
1105 | \r | |
1106 | //\r | |
1107 | // If no boot device return to BDS\r | |
1108 | //\r | |
1109 | if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r | |
1110 | for (Index = 0; Index < BbsCount; Index++){\r | |
1111 | if ((LocalBbsTable[Index].BootPriority != BBS_DO_NOT_BOOT_FROM) &&\r | |
1112 | (LocalBbsTable[Index].BootPriority != BBS_UNPRIORITIZED_ENTRY) &&\r | |
1113 | (LocalBbsTable[Index].BootPriority != BBS_IGNORE_ENTRY)) {\r | |
1114 | break;\r | |
1115 | }\r | |
1116 | }\r | |
1117 | if (Index == BbsCount) {\r | |
1118 | return EFI_DEVICE_ERROR;\r | |
1119 | }\r | |
1120 | }\r | |
1121 | //\r | |
1122 | // Let the Legacy16 code know the device path type for legacy boot\r | |
1123 | //\r | |
1124 | EfiToLegacy16BootTable->DevicePathType = mBbsDevicePathPtr->DeviceType;\r | |
1125 | \r | |
1126 | //\r | |
1127 | // Copy MP table, if it exists.\r | |
1128 | //\r | |
1129 | LegacyGetDataOrTable (This, EfiGetPlatformBinaryMpTable);\r | |
1130 | \r | |
1131 | if (!Private->LegacyBootEntered) {\r | |
1132 | //\r | |
1133 | // Copy OEM INT Data, if it exists. Note: This code treats any data\r | |
1134 | // as a bag of bits and knows nothing of the contents nor cares.\r | |
1135 | // Contents are IBV specific.\r | |
1136 | //\r | |
1137 | LegacyGetDataOrTable (This, EfiGetPlatformBinaryOemIntData);\r | |
1138 | \r | |
1139 | //\r | |
1140 | // Copy OEM16 Data, if it exists.Note: This code treats any data\r | |
1141 | // as a bag of bits and knows nothing of the contents nor cares.\r | |
1142 | // Contents are IBV specific.\r | |
1143 | //\r | |
1144 | LegacyGetDataOrTable (This, EfiGetPlatformBinaryOem16Data);\r | |
1145 | \r | |
1146 | //\r | |
1147 | // Copy OEM32 Data, if it exists.Note: This code treats any data\r | |
1148 | // as a bag of bits and knows nothing of the contents nor cares.\r | |
1149 | // Contents are IBV specific.\r | |
1150 | //\r | |
1151 | LegacyGetDataOrTable (This, EfiGetPlatformBinaryOem32Data);\r | |
1152 | }\r | |
1153 | \r | |
1154 | //\r | |
1155 | // Call into Legacy16 code to prepare for INT 19h\r | |
1156 | //\r | |
1157 | ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r | |
1158 | Regs.X.AX = Legacy16PrepareToBoot;\r | |
1159 | \r | |
1160 | //\r | |
1161 | // Pass in handoff data\r | |
1162 | //\r | |
81c0d6e9 | 1163 | Regs.X.ES = NORMALIZE_EFI_SEGMENT ((UINTN)EfiToLegacy16BootTable);\r |
1164 | Regs.X.BX = NORMALIZE_EFI_OFFSET ((UINTN)EfiToLegacy16BootTable);\r | |
bcecde14 | 1165 | \r |
1166 | Private->LegacyBios.FarCall86 (\r | |
1167 | This,\r | |
1168 | Private->Legacy16CallSegment,\r | |
1169 | Private->Legacy16CallOffset,\r | |
1170 | &Regs,\r | |
1171 | NULL,\r | |
1172 | 0\r | |
1173 | );\r | |
1174 | \r | |
1175 | if (Regs.X.AX != 0) {\r | |
1176 | return EFI_DEVICE_ERROR;\r | |
1177 | }\r | |
1178 | //\r | |
1179 | // Lock the Legacy BIOS region\r | |
1180 | //\r | |
1181 | Private->LegacyRegion->Lock (\r | |
1182 | Private->LegacyRegion,\r | |
1183 | 0xc0000,\r | |
1184 | 0x40000,\r | |
1185 | &Granularity\r | |
1186 | );\r | |
1187 | //\r | |
1188 | // Lock attributes of the Legacy Region if chipset supports\r | |
1189 | //\r | |
1190 | Private->LegacyRegion->BootLock (\r | |
1191 | Private->LegacyRegion,\r | |
1192 | 0xc0000,\r | |
1193 | 0x40000,\r | |
1194 | &Granularity\r | |
1195 | );\r | |
1196 | \r | |
1197 | //\r | |
1198 | // Call into Legacy16 code to do the INT 19h\r | |
1199 | //\r | |
1200 | EnableAllControllers (Private);\r | |
1201 | if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r | |
cb38c322 | 1202 | //\r |
1203 | // Report Status Code to indicate legacy boot event will be signalled\r | |
1204 | //\r | |
1205 | REPORT_STATUS_CODE (\r | |
1206 | EFI_PROGRESS_CODE,\r | |
1207 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_LEGACY_BOOT_EVENT)\r | |
1208 | );\r | |
1209 | \r | |
bcecde14 | 1210 | //\r |
1211 | // Signal all the events that are waiting on EVT_SIGNAL_LEGACY_BOOT\r | |
1212 | //\r | |
1213 | EfiSignalEventLegacyBoot ();\r | |
1214 | DEBUG ((EFI_D_INFO, "Legacy INT19 Boot...\n"));\r | |
3512efa9 | 1215 | \r |
1216 | //\r | |
1217 | // Disable DXE Timer while executing in real mode\r | |
bcecde14 | 1218 | //\r |
3512efa9 | 1219 | Private->Timer->SetTimerPeriod (Private->Timer, 0);\r |
1220 | \r | |
bcecde14 | 1221 | //\r |
3512efa9 | 1222 | // Save and disable interrupt of debug timer\r |
1223 | //\r | |
1224 | SaveAndSetDebugTimerInterrupt (FALSE);\r | |
1225 | \r | |
bcecde14 | 1226 | \r |
1227 | //\r | |
1228 | // Put the 8259 into its legacy mode by reprogramming the vector bases\r | |
1229 | //\r | |
1230 | Private->Legacy8259->SetVectorBase (Private->Legacy8259, LEGACY_MODE_BASE_VECTOR_MASTER, LEGACY_MODE_BASE_VECTOR_SLAVE);\r | |
1231 | //\r | |
1232 | // PC History\r | |
1233 | // The original PC used INT8-F for master PIC. Since these mapped over\r | |
1234 | // processor exceptions TIANO moved the master PIC to INT68-6F.\r | |
1235 | // We need to set these back to the Legacy16 unexpected interrupt(saved\r | |
1236 | // in LegacyBios.c) since some OS see that these have values different from\r | |
1237 | // what is expected and invoke them. Since the legacy OS corrupts EFI\r | |
1238 | // memory, there is no handler for these interrupts and OS blows up.\r | |
1239 | //\r | |
1240 | // We need to save the TIANO values for the rare case that the Legacy16\r | |
1241 | // code cannot boot but knows memory hasn't been destroyed.\r | |
1242 | //\r | |
1243 | // To compound the problem, video takes over one of these INTS and must be\r | |
1244 | // be left.\r | |
1245 | // @bug - determine if video hooks INT(in which case we must find new\r | |
1246 | // set of TIANO vectors) or takes it over.\r | |
1247 | //\r | |
1248 | //\r | |
1249 | BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r | |
1250 | for (Index = 0; Index < 8; Index++) {\r | |
1251 | Private->ThunkSavedInt[Index] = BaseVectorMaster[Index];\r | |
1252 | if (Private->ThunkSeg == (UINT16) (BaseVectorMaster[Index] >> 16)) {\r | |
1253 | BaseVectorMaster[Index] = (UINT32) (Private->BiosUnexpectedInt);\r | |
1254 | }\r | |
1255 | }\r | |
1256 | \r | |
1257 | ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r | |
1258 | Regs.X.AX = Legacy16Boot;\r | |
1259 | \r | |
1260 | Private->LegacyBios.FarCall86 (\r | |
1261 | This,\r | |
1262 | Private->Legacy16CallSegment,\r | |
1263 | Private->Legacy16CallOffset,\r | |
1264 | &Regs,\r | |
1265 | NULL,\r | |
1266 | 0\r | |
1267 | );\r | |
1268 | \r | |
1269 | BaseVectorMaster = (UINT32 *) (sizeof (UINT32) * PROTECTED_MODE_BASE_VECTOR_MASTER);\r | |
1270 | for (Index = 0; Index < 8; Index++) {\r | |
1271 | BaseVectorMaster[Index] = Private->ThunkSavedInt[Index];\r | |
1272 | }\r | |
1273 | }\r | |
1274 | Private->LegacyBootEntered = TRUE;\r | |
1275 | if ((mBootMode == BOOT_LEGACY_OS) || (mBootMode == BOOT_UNCONVENTIONAL_DEVICE)) {\r | |
1276 | //\r | |
1277 | // Should never return unless never passed control to 0:7c00(first stage\r | |
1278 | // OS loader) and only then if no bootable device found.\r | |
1279 | //\r | |
1280 | return EFI_DEVICE_ERROR;\r | |
1281 | } else {\r | |
1282 | //\r | |
1283 | // If boot to EFI then expect to return to caller\r | |
1284 | //\r | |
1285 | return EFI_SUCCESS;\r | |
1286 | }\r | |
1287 | }\r | |
1288 | \r | |
1289 | \r | |
1290 | /**\r | |
1291 | Assign drive number to legacy HDD drives prior to booting an EFI\r | |
1292 | aware OS so the OS can access drives without an EFI driver.\r | |
1293 | Note: BBS compliant drives ARE NOT available until this call by\r | |
1294 | either shell or EFI.\r | |
1295 | \r | |
1296 | @param This Protocol instance pointer.\r | |
1297 | @param BbsCount Number of BBS_TABLE structures\r | |
1298 | @param BbsTable List BBS entries\r | |
1299 | \r | |
1300 | @retval EFI_SUCCESS Drive numbers assigned\r | |
1301 | \r | |
1302 | **/\r | |
1303 | EFI_STATUS\r | |
1304 | EFIAPI\r | |
1305 | LegacyBiosPrepareToBootEfi (\r | |
1306 | IN EFI_LEGACY_BIOS_PROTOCOL *This,\r | |
1307 | OUT UINT16 *BbsCount,\r | |
1308 | OUT BBS_TABLE **BbsTable\r | |
1309 | )\r | |
1310 | {\r | |
1311 | EFI_STATUS Status;\r | |
1312 | EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;\r | |
1313 | LEGACY_BIOS_INSTANCE *Private;\r | |
1314 | \r | |
1315 | Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r | |
1316 | EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;\r | |
1317 | mBootMode = BOOT_EFI_OS;\r | |
1318 | mBbsDevicePathPtr = NULL;\r | |
1319 | Status = GenericLegacyBoot (This);\r | |
1320 | *BbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable;\r | |
1321 | *BbsCount = (UINT16) (sizeof (Private->IntThunk->BbsTable) / sizeof (BBS_TABLE));\r | |
1322 | return Status;\r | |
1323 | }\r | |
1324 | \r | |
1325 | /**\r | |
1326 | To boot from an unconventional device like parties and/or execute HDD diagnostics.\r | |
1327 | \r | |
1328 | @param This Protocol instance pointer.\r | |
1329 | @param Attributes How to interpret the other input parameters\r | |
1330 | @param BbsEntry The 0-based index into the BbsTable for the parent\r | |
1331 | device.\r | |
1332 | @param BeerData Pointer to the 128 bytes of ram BEER data.\r | |
1333 | @param ServiceAreaData Pointer to the 64 bytes of raw Service Area data. The\r | |
1334 | caller must provide a pointer to the specific Service\r | |
1335 | Area and not the start all Service Areas.\r | |
1336 | \r | |
1337 | @retval EFI_INVALID_PARAMETER if error. Does NOT return if no error.\r | |
1338 | \r | |
1339 | ***/\r | |
1340 | EFI_STATUS\r | |
1341 | EFIAPI\r | |
1342 | LegacyBiosBootUnconventionalDevice (\r | |
1343 | IN EFI_LEGACY_BIOS_PROTOCOL *This,\r | |
1344 | IN UDC_ATTRIBUTES Attributes,\r | |
1345 | IN UINTN BbsEntry,\r | |
1346 | IN VOID *BeerData,\r | |
1347 | IN VOID *ServiceAreaData\r | |
1348 | )\r | |
1349 | {\r | |
1350 | EFI_STATUS Status;\r | |
1351 | EFI_TO_COMPATIBILITY16_BOOT_TABLE *EfiToLegacy16BootTable;\r | |
1352 | LEGACY_BIOS_INSTANCE *Private;\r | |
1353 | UD_TABLE *UcdTable;\r | |
1354 | UINTN Index;\r | |
1355 | UINT16 BootPriority;\r | |
1356 | BBS_TABLE *BbsTable;\r | |
1357 | \r | |
1358 | BootPriority = 0;\r | |
1359 | Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r | |
1360 | mBootMode = BOOT_UNCONVENTIONAL_DEVICE;\r | |
1361 | mBbsDevicePathPtr = &mBbsDevicePathNode;\r | |
1362 | mAttributes = Attributes;\r | |
1363 | mBbsEntry = BbsEntry;\r | |
1364 | mBeerData = BeerData, mServiceAreaData = ServiceAreaData;\r | |
1365 | \r | |
1366 | EfiToLegacy16BootTable = &Private->IntThunk->EfiToLegacy16BootTable;\r | |
1367 | \r | |
1368 | //\r | |
1369 | // Do input parameter checking\r | |
1370 | //\r | |
1371 | if ((Attributes.DirectoryServiceValidity == 0) &&\r | |
1372 | (Attributes.RabcaUsedFlag == 0) &&\r | |
1373 | (Attributes.ExecuteHddDiagnosticsFlag == 0)\r | |
1374 | ) {\r | |
1375 | return EFI_INVALID_PARAMETER;\r | |
1376 | }\r | |
1377 | \r | |
1378 | if (((Attributes.DirectoryServiceValidity != 0) && (ServiceAreaData == NULL)) ||\r | |
1379 | (((Attributes.DirectoryServiceValidity | Attributes.RabcaUsedFlag) != 0) && (BeerData == NULL))\r | |
1380 | ) {\r | |
1381 | return EFI_INVALID_PARAMETER;\r | |
1382 | }\r | |
1383 | \r | |
1384 | UcdTable = (UD_TABLE *) AllocatePool (\r | |
1385 | sizeof (UD_TABLE)\r | |
1386 | );\r | |
1387 | if (NULL == UcdTable) {\r | |
1388 | return EFI_OUT_OF_RESOURCES;\r | |
1389 | }\r | |
1390 | \r | |
1391 | EfiToLegacy16BootTable->UnconventionalDeviceTable = (UINT32)(UINTN)UcdTable;\r | |
1392 | UcdTable->Attributes = Attributes;\r | |
1393 | UcdTable->BbsTableEntryNumberForParentDevice = (UINT8) BbsEntry;\r | |
1394 | //\r | |
1395 | // Force all existing BBS entries to DoNotBoot. This allows 16-bit CSM\r | |
1396 | // to assign drive numbers but bot boot from. Only newly created entries\r | |
1397 | // will be valid.\r | |
1398 | //\r | |
1399 | BbsTable = (BBS_TABLE*)(UINTN)EfiToLegacy16BootTable->BbsTable;\r | |
1400 | for (Index = 0; Index < EfiToLegacy16BootTable->NumberBbsEntries; Index++) {\r | |
1401 | BbsTable[Index].BootPriority = BBS_DO_NOT_BOOT_FROM;\r | |
1402 | }\r | |
1403 | //\r | |
1404 | // If parent is onboard IDE then assign controller & device number\r | |
1405 | // else they are 0.\r | |
1406 | //\r | |
1407 | if (BbsEntry < MAX_IDE_CONTROLLER * 2) {\r | |
1408 | UcdTable->DeviceNumber = (UINT8) ((BbsEntry - 1) % 2);\r | |
1409 | }\r | |
1410 | \r | |
1411 | if (BeerData != NULL) {\r | |
1412 | CopyMem (\r | |
1413 | (VOID *) UcdTable->BeerData,\r | |
1414 | BeerData,\r | |
1415 | (UINTN) 128\r | |
1416 | );\r | |
1417 | }\r | |
1418 | \r | |
1419 | if (ServiceAreaData != NULL) {\r | |
1420 | CopyMem (\r | |
1421 | (VOID *) UcdTable->ServiceAreaData,\r | |
1422 | ServiceAreaData,\r | |
1423 | (UINTN) 64\r | |
1424 | );\r | |
1425 | }\r | |
1426 | //\r | |
1427 | // For each new entry do the following:\r | |
1428 | // 1. Increment current number of BBS entries\r | |
1429 | // 2. Copy parent entry to new entry.\r | |
1430 | // 3. Zero out BootHandler Offset & segment\r | |
1431 | // 4. Set appropriate device type. BEV(0x80) for HDD diagnostics\r | |
1432 | // and Floppy(0x01) for PARTIES boot.\r | |
1433 | // 5. Assign new priority.\r | |
1434 | //\r | |
1435 | if ((Attributes.ExecuteHddDiagnosticsFlag) != 0) {\r | |
1436 | EfiToLegacy16BootTable->NumberBbsEntries += 1;\r | |
1437 | \r | |
1438 | CopyMem (\r | |
1439 | (VOID *) &BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootPriority,\r | |
1440 | (VOID *) &BbsTable[BbsEntry].BootPriority,\r | |
1441 | sizeof (BBS_TABLE)\r | |
1442 | );\r | |
1443 | \r | |
1444 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootHandlerOffset = 0;\r | |
1445 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootHandlerSegment = 0;\r | |
1446 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].DeviceType = 0x80;\r | |
1447 | \r | |
1448 | UcdTable->BbsTableEntryNumberForHddDiag = (UINT8) (EfiToLegacy16BootTable->NumberBbsEntries - 1);\r | |
1449 | \r | |
1450 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootPriority = BootPriority;\r | |
1451 | BootPriority += 1;\r | |
1452 | \r | |
1453 | //\r | |
1454 | // Set device type as BBS_TYPE_DEV for PARTIES diagnostic\r | |
1455 | //\r | |
1456 | mBbsDevicePathNode.DeviceType = BBS_TYPE_BEV;\r | |
1457 | }\r | |
1458 | \r | |
1459 | if (((Attributes.DirectoryServiceValidity | Attributes.RabcaUsedFlag)) != 0) {\r | |
1460 | EfiToLegacy16BootTable->NumberBbsEntries += 1;\r | |
1461 | CopyMem (\r | |
1462 | (VOID *) &BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootPriority,\r | |
1463 | (VOID *) &BbsTable[BbsEntry].BootPriority,\r | |
1464 | sizeof (BBS_TABLE)\r | |
1465 | );\r | |
1466 | \r | |
1467 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootHandlerOffset = 0;\r | |
1468 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootHandlerSegment = 0;\r | |
1469 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].DeviceType = 0x01;\r | |
1470 | UcdTable->BbsTableEntryNumberForBoot = (UINT8) (EfiToLegacy16BootTable->NumberBbsEntries - 1);\r | |
1471 | BbsTable[EfiToLegacy16BootTable->NumberBbsEntries].BootPriority = BootPriority;\r | |
1472 | \r | |
1473 | //\r | |
1474 | // Set device type as BBS_TYPE_FLOPPY for PARTIES boot as floppy\r | |
1475 | //\r | |
1476 | mBbsDevicePathNode.DeviceType = BBS_TYPE_FLOPPY;\r | |
1477 | }\r | |
1478 | //\r | |
1479 | // Build the BBS Device Path for this boot selection\r | |
1480 | //\r | |
1481 | mBbsDevicePathNode.Header.Type = BBS_DEVICE_PATH;\r | |
1482 | mBbsDevicePathNode.Header.SubType = BBS_BBS_DP;\r | |
1483 | SetDevicePathNodeLength (&mBbsDevicePathNode.Header, sizeof (BBS_BBS_DEVICE_PATH));\r | |
1484 | mBbsDevicePathNode.StatusFlag = 0;\r | |
1485 | mBbsDevicePathNode.String[0] = 0;\r | |
1486 | \r | |
1487 | Status = GenericLegacyBoot (This);\r | |
1488 | return Status;\r | |
1489 | }\r | |
1490 | \r | |
1491 | /**\r | |
1492 | Attempt to legacy boot the BootOption. If the EFI contexted has been\r | |
1493 | compromised this function will not return.\r | |
1494 | \r | |
1495 | @param This Protocol instance pointer.\r | |
1496 | @param BbsDevicePath EFI Device Path from BootXXXX variable.\r | |
1497 | @param LoadOptionsSize Size of LoadOption in size.\r | |
1498 | @param LoadOptions LoadOption from BootXXXX variable\r | |
1499 | \r | |
1500 | @retval EFI_SUCCESS Removable media not present\r | |
1501 | \r | |
1502 | **/\r | |
1503 | EFI_STATUS\r | |
1504 | EFIAPI\r | |
1505 | LegacyBiosLegacyBoot (\r | |
1506 | IN EFI_LEGACY_BIOS_PROTOCOL *This,\r | |
1507 | IN BBS_BBS_DEVICE_PATH *BbsDevicePath,\r | |
1508 | IN UINT32 LoadOptionsSize,\r | |
1509 | IN VOID *LoadOptions\r | |
1510 | )\r | |
1511 | {\r | |
1512 | EFI_STATUS Status;\r | |
1513 | \r | |
1514 | mBbsDevicePathPtr = BbsDevicePath;\r | |
1515 | mLoadOptionsSize = LoadOptionsSize;\r | |
1516 | mLoadOptions = LoadOptions;\r | |
1517 | mBootMode = BOOT_LEGACY_OS;\r | |
1518 | Status = GenericLegacyBoot (This);\r | |
1519 | \r | |
1520 | return Status;\r | |
1521 | }\r | |
1522 | \r | |
1523 | /**\r | |
1524 | Convert EFI Memory Type to E820 Memory Type.\r | |
1525 | \r | |
1526 | @param Type EFI Memory Type\r | |
1527 | \r | |
1528 | @return ACPI Memory Type for EFI Memory Type\r | |
1529 | \r | |
1530 | **/\r | |
1531 | EFI_ACPI_MEMORY_TYPE\r | |
1532 | EfiMemoryTypeToE820Type (\r | |
1533 | IN UINT32 Type\r | |
1534 | )\r | |
1535 | {\r | |
1536 | switch (Type) {\r | |
1537 | case EfiLoaderCode:\r | |
1538 | case EfiLoaderData:\r | |
1539 | case EfiBootServicesCode:\r | |
1540 | case EfiBootServicesData:\r | |
1541 | case EfiConventionalMemory:\r | |
1542 | case EfiRuntimeServicesCode:\r | |
1543 | case EfiRuntimeServicesData:\r | |
1544 | return EfiAcpiAddressRangeMemory;\r | |
1545 | \r | |
1546 | case EfiACPIReclaimMemory:\r | |
1547 | return EfiAcpiAddressRangeACPI;\r | |
1548 | \r | |
1549 | case EfiACPIMemoryNVS:\r | |
1550 | return EfiAcpiAddressRangeNVS;\r | |
1551 | \r | |
1552 | //\r | |
1553 | // All other types map to reserved.\r | |
1554 | // Adding the code just waists FLASH space.\r | |
1555 | //\r | |
1556 | // case EfiReservedMemoryType:\r | |
1557 | // case EfiUnusableMemory:\r | |
1558 | // case EfiMemoryMappedIO:\r | |
1559 | // case EfiMemoryMappedIOPortSpace:\r | |
1560 | // case EfiPalCode:\r | |
1561 | //\r | |
1562 | default:\r | |
1563 | return EfiAcpiAddressRangeReserved;\r | |
1564 | }\r | |
1565 | }\r | |
1566 | \r | |
1567 | /**\r | |
1568 | Build the E820 table.\r | |
1569 | \r | |
1570 | @param Private Legacy BIOS Instance data\r | |
1571 | @param Size Size of E820 Table\r | |
1572 | \r | |
1573 | @retval EFI_SUCCESS It should always work.\r | |
1574 | \r | |
1575 | **/\r | |
1576 | EFI_STATUS\r | |
1577 | LegacyBiosBuildE820 (\r | |
1578 | IN LEGACY_BIOS_INSTANCE *Private,\r | |
1579 | OUT UINTN *Size\r | |
1580 | )\r | |
1581 | {\r | |
1582 | EFI_STATUS Status;\r | |
1583 | EFI_E820_ENTRY64 *E820Table;\r | |
1584 | EFI_MEMORY_DESCRIPTOR *EfiMemoryMap;\r | |
1585 | EFI_MEMORY_DESCRIPTOR *EfiMemoryMapEnd;\r | |
1586 | EFI_MEMORY_DESCRIPTOR *EfiEntry;\r | |
1587 | EFI_MEMORY_DESCRIPTOR *NextEfiEntry;\r | |
1588 | EFI_MEMORY_DESCRIPTOR TempEfiEntry;\r | |
1589 | UINTN EfiMemoryMapSize;\r | |
1590 | UINTN EfiMapKey;\r | |
1591 | UINTN EfiDescriptorSize;\r | |
1592 | UINT32 EfiDescriptorVersion;\r | |
1593 | UINTN Index;\r | |
1594 | EFI_PEI_HOB_POINTERS Hob;\r | |
1595 | EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;\r | |
1596 | UINTN TempIndex;\r | |
1597 | UINTN IndexSort;\r | |
1598 | UINTN TempNextIndex;\r | |
1599 | EFI_E820_ENTRY64 TempE820;\r | |
1600 | EFI_ACPI_MEMORY_TYPE TempType;\r | |
1601 | BOOLEAN ChangedFlag;\r | |
1602 | UINTN Above1MIndex;\r | |
1603 | UINT64 MemoryBlockLength;\r | |
1604 | \r | |
1605 | E820Table = (EFI_E820_ENTRY64 *) Private->E820Table;\r | |
1606 | \r | |
1607 | //\r | |
1608 | // Get the EFI memory map.\r | |
1609 | //\r | |
1610 | EfiMemoryMapSize = 0;\r | |
1611 | EfiMemoryMap = NULL;\r | |
1612 | Status = gBS->GetMemoryMap (\r | |
1613 | &EfiMemoryMapSize,\r | |
1614 | EfiMemoryMap,\r | |
1615 | &EfiMapKey,\r | |
1616 | &EfiDescriptorSize,\r | |
1617 | &EfiDescriptorVersion\r | |
1618 | );\r | |
1619 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r | |
1620 | \r | |
1621 | do {\r | |
1622 | //\r | |
1623 | // Use size returned back plus 1 descriptor for the AllocatePool.\r | |
1624 | // We don't just multiply by 2 since the "for" loop below terminates on\r | |
1625 | // EfiMemoryMapEnd which is dependent upon EfiMemoryMapSize. Otherwize\r | |
1626 | // we process bogus entries and create bogus E820 entries.\r | |
1627 | //\r | |
1628 | EfiMemoryMap = (EFI_MEMORY_DESCRIPTOR *) AllocatePool (EfiMemoryMapSize);\r | |
1629 | ASSERT (EfiMemoryMap != NULL);\r | |
1630 | Status = gBS->GetMemoryMap (\r | |
1631 | &EfiMemoryMapSize,\r | |
1632 | EfiMemoryMap,\r | |
1633 | &EfiMapKey,\r | |
1634 | &EfiDescriptorSize,\r | |
1635 | &EfiDescriptorVersion\r | |
1636 | );\r | |
1637 | if (EFI_ERROR (Status)) {\r | |
1638 | FreePool (EfiMemoryMap);\r | |
1639 | }\r | |
1640 | } while (Status == EFI_BUFFER_TOO_SMALL);\r | |
1641 | \r | |
1642 | ASSERT_EFI_ERROR (Status);\r | |
1643 | \r | |
1644 | //\r | |
1645 | // Punch in the E820 table for memory less than 1 MB.\r | |
1646 | // Assume ZeroMem () has been done on data structure.\r | |
1647 | //\r | |
1648 | //\r | |
1649 | // First entry is 0 to (640k - EBDA)\r | |
1650 | //\r | |
1651 | E820Table[0].BaseAddr = 0;\r | |
1652 | E820Table[0].Length = (UINT64) ((*(UINT16 *) (UINTN)0x40E) << 4);\r | |
1653 | E820Table[0].Type = EfiAcpiAddressRangeMemory;\r | |
1654 | \r | |
1655 | //\r | |
1656 | // Second entry is (640k - EBDA) to 640k\r | |
1657 | //\r | |
1658 | E820Table[1].BaseAddr = E820Table[0].Length;\r | |
1659 | E820Table[1].Length = (UINT64) ((640 * 1024) - E820Table[0].Length);\r | |
1660 | E820Table[1].Type = EfiAcpiAddressRangeReserved;\r | |
1661 | \r | |
1662 | //\r | |
1663 | // Third Entry is legacy BIOS\r | |
1664 | // DO NOT CLAIM region from 0xA0000-0xDFFFF. OS can use free areas\r | |
1665 | // to page in memory under 1MB.\r | |
1666 | // Omit region from 0xE0000 to start of BIOS, if any. This can be\r | |
1667 | // used for a multiple reasons including OPROMS.\r | |
1668 | //\r | |
1669 | \r | |
1670 | //\r | |
1671 | // The CSM binary image size is not the actually size that CSM binary used,\r | |
1672 | // to avoid memory corrupt, we declare the 0E0000 - 0FFFFF is used by CSM binary.\r | |
1673 | //\r | |
1674 | E820Table[2].BaseAddr = 0xE0000;\r | |
1675 | E820Table[2].Length = 0x20000;\r | |
1676 | E820Table[2].Type = EfiAcpiAddressRangeReserved;\r | |
1677 | \r | |
1678 | Above1MIndex = 2;\r | |
1679 | \r | |
1680 | //\r | |
1681 | // Process the EFI map to produce E820 map;\r | |
1682 | //\r | |
1683 | \r | |
1684 | //\r | |
1685 | // Sort memory map from low to high\r | |
1686 | //\r | |
1687 | EfiEntry = EfiMemoryMap;\r | |
1688 | NextEfiEntry = NEXT_MEMORY_DESCRIPTOR (EfiEntry, EfiDescriptorSize);\r | |
1689 | EfiMemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) EfiMemoryMap + EfiMemoryMapSize);\r | |
1690 | while (EfiEntry < EfiMemoryMapEnd) {\r | |
1691 | while (NextEfiEntry < EfiMemoryMapEnd) {\r | |
1692 | if (EfiEntry->PhysicalStart > NextEfiEntry->PhysicalStart) {\r | |
1693 | CopyMem (&TempEfiEntry, EfiEntry, sizeof (EFI_MEMORY_DESCRIPTOR));\r | |
1694 | CopyMem (EfiEntry, NextEfiEntry, sizeof (EFI_MEMORY_DESCRIPTOR));\r | |
1695 | CopyMem (NextEfiEntry, &TempEfiEntry, sizeof (EFI_MEMORY_DESCRIPTOR));\r | |
1696 | }\r | |
1697 | \r | |
1698 | NextEfiEntry = NEXT_MEMORY_DESCRIPTOR (NextEfiEntry, EfiDescriptorSize);\r | |
1699 | }\r | |
1700 | \r | |
1701 | EfiEntry = NEXT_MEMORY_DESCRIPTOR (EfiEntry, EfiDescriptorSize);\r | |
1702 | NextEfiEntry = NEXT_MEMORY_DESCRIPTOR (EfiEntry, EfiDescriptorSize);\r | |
1703 | }\r | |
1704 | \r | |
1705 | EfiEntry = EfiMemoryMap;\r | |
1706 | EfiMemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) EfiMemoryMap + EfiMemoryMapSize);\r | |
1707 | for (Index = Above1MIndex; (EfiEntry < EfiMemoryMapEnd) && (Index < EFI_MAX_E820_ENTRY - 1); ) {\r | |
1708 | MemoryBlockLength = (UINT64) (LShiftU64 (EfiEntry->NumberOfPages, 12));\r | |
1709 | if ((EfiEntry->PhysicalStart + MemoryBlockLength) < 0x100000) {\r | |
1710 | //\r | |
1711 | // Skip the memory block is under 1MB\r | |
1712 | //\r | |
1713 | } else {\r | |
1714 | if (EfiEntry->PhysicalStart < 0x100000) {\r | |
1715 | //\r | |
1716 | // When the memory block spans below 1MB, ensure the memory block start address is at least 1MB\r | |
1717 | //\r | |
1718 | MemoryBlockLength -= 0x100000 - EfiEntry->PhysicalStart;\r | |
1719 | EfiEntry->PhysicalStart = 0x100000;\r | |
1720 | }\r | |
1721 | \r | |
1722 | //\r | |
1723 | // Convert memory type to E820 type\r | |
1724 | //\r | |
1725 | TempType = EfiMemoryTypeToE820Type (EfiEntry->Type);\r | |
1726 | \r | |
1727 | if ((E820Table[Index].Type == TempType) && (EfiEntry->PhysicalStart == (E820Table[Index].BaseAddr + E820Table[Index].Length))) {\r | |
1728 | //\r | |
1729 | // Grow an existing entry\r | |
1730 | //\r | |
1731 | E820Table[Index].Length += MemoryBlockLength;\r | |
1732 | } else {\r | |
1733 | //\r | |
1734 | // Make a new entry\r | |
1735 | //\r | |
1736 | ++Index;\r | |
1737 | E820Table[Index].BaseAddr = EfiEntry->PhysicalStart;\r | |
1738 | E820Table[Index].Length = MemoryBlockLength;\r | |
1739 | E820Table[Index].Type = TempType;\r | |
1740 | }\r | |
1741 | }\r | |
1742 | EfiEntry = NEXT_MEMORY_DESCRIPTOR (EfiEntry, EfiDescriptorSize);\r | |
1743 | }\r | |
1744 | \r | |
1745 | FreePool (EfiMemoryMap);\r | |
1746 | \r | |
1747 | //\r | |
1748 | // Process the reserved memory map to produce E820 map ;\r | |
1749 | //\r | |
1750 | for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r | |
1751 | if (Hob.Raw != NULL && GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {\r | |
1752 | ResourceHob = Hob.ResourceDescriptor;\r | |
1753 | if (((ResourceHob->ResourceType == EFI_RESOURCE_MEMORY_MAPPED_IO) ||\r | |
1754 | (ResourceHob->ResourceType == EFI_RESOURCE_FIRMWARE_DEVICE) ||\r | |
1755 | (ResourceHob->ResourceType == EFI_RESOURCE_MEMORY_RESERVED) ) &&\r | |
1756 | (ResourceHob->PhysicalStart > 0x100000) &&\r | |
1757 | (Index < EFI_MAX_E820_ENTRY - 1)) {\r | |
1758 | ++Index;\r | |
1759 | E820Table[Index].BaseAddr = ResourceHob->PhysicalStart;\r | |
1760 | E820Table[Index].Length = ResourceHob->ResourceLength;\r | |
1761 | E820Table[Index].Type = EfiAcpiAddressRangeReserved;\r | |
1762 | }\r | |
1763 | }\r | |
1764 | }\r | |
1765 | \r | |
1766 | Index ++;\r | |
1767 | Private->IntThunk->EfiToLegacy16InitTable.NumberE820Entries = (UINT32)Index;\r | |
1768 | Private->IntThunk->EfiToLegacy16BootTable.NumberE820Entries = (UINT32)Index;\r | |
1769 | Private->NumberE820Entries = (UINT32)Index;\r | |
1770 | *Size = (UINTN) (Index * sizeof (EFI_E820_ENTRY64));\r | |
1771 | \r | |
1772 | //\r | |
1773 | // Sort E820Table from low to high\r | |
1774 | //\r | |
1775 | for (TempIndex = 0; TempIndex < Index; TempIndex++) {\r | |
1776 | ChangedFlag = FALSE;\r | |
1777 | for (TempNextIndex = 1; TempNextIndex < Index - TempIndex; TempNextIndex++) {\r | |
1778 | if (E820Table[TempNextIndex - 1].BaseAddr > E820Table[TempNextIndex].BaseAddr) {\r | |
1779 | ChangedFlag = TRUE;\r | |
1780 | TempE820.BaseAddr = E820Table[TempNextIndex - 1].BaseAddr;\r | |
1781 | TempE820.Length = E820Table[TempNextIndex - 1].Length;\r | |
1782 | TempE820.Type = E820Table[TempNextIndex - 1].Type;\r | |
1783 | \r | |
1784 | E820Table[TempNextIndex - 1].BaseAddr = E820Table[TempNextIndex].BaseAddr;\r | |
1785 | E820Table[TempNextIndex - 1].Length = E820Table[TempNextIndex].Length;\r | |
1786 | E820Table[TempNextIndex - 1].Type = E820Table[TempNextIndex].Type;\r | |
1787 | \r | |
1788 | E820Table[TempNextIndex].BaseAddr = TempE820.BaseAddr;\r | |
1789 | E820Table[TempNextIndex].Length = TempE820.Length;\r | |
1790 | E820Table[TempNextIndex].Type = TempE820.Type;\r | |
1791 | }\r | |
1792 | }\r | |
1793 | \r | |
1794 | if (!ChangedFlag) {\r | |
1795 | break;\r | |
1796 | }\r | |
1797 | }\r | |
1798 | \r | |
1799 | //\r | |
1800 | // Remove the overlap range\r | |
1801 | //\r | |
1802 | for (TempIndex = 1; TempIndex < Index; TempIndex++) {\r | |
1803 | if (E820Table[TempIndex - 1].BaseAddr <= E820Table[TempIndex].BaseAddr &&\r | |
1804 | ((E820Table[TempIndex - 1].BaseAddr + E820Table[TempIndex - 1].Length) >=\r | |
1805 | (E820Table[TempIndex].BaseAddr +E820Table[TempIndex].Length))) {\r | |
1806 | //\r | |
1807 | //Overlap range is found\r | |
1808 | //\r | |
1809 | ASSERT (E820Table[TempIndex - 1].Type == E820Table[TempIndex].Type);\r | |
1810 | \r | |
1811 | if (TempIndex == Index - 1) {\r | |
1812 | E820Table[TempIndex].BaseAddr = 0;\r | |
1813 | E820Table[TempIndex].Length = 0;\r | |
1814 | E820Table[TempIndex].Type = (EFI_ACPI_MEMORY_TYPE) 0;\r | |
1815 | Index--;\r | |
1816 | break;\r | |
1817 | } else {\r | |
1818 | for (IndexSort = TempIndex; IndexSort < Index - 1; IndexSort ++) {\r | |
1819 | E820Table[IndexSort].BaseAddr = E820Table[IndexSort + 1].BaseAddr;\r | |
1820 | E820Table[IndexSort].Length = E820Table[IndexSort + 1].Length;\r | |
1821 | E820Table[IndexSort].Type = E820Table[IndexSort + 1].Type;\r | |
1822 | }\r | |
1823 | Index--;\r | |
1824 | }\r | |
1825 | }\r | |
1826 | }\r | |
1827 | \r | |
1828 | \r | |
1829 | \r | |
1830 | Private->IntThunk->EfiToLegacy16InitTable.NumberE820Entries = (UINT32)Index;\r | |
1831 | Private->IntThunk->EfiToLegacy16BootTable.NumberE820Entries = (UINT32)Index;\r | |
1832 | Private->NumberE820Entries = (UINT32)Index;\r | |
1833 | *Size = (UINTN) (Index * sizeof (EFI_E820_ENTRY64));\r | |
1834 | \r | |
1835 | //\r | |
1836 | // Determine OS usable memory above 1Mb\r | |
1837 | //\r | |
1838 | Private->IntThunk->EfiToLegacy16BootTable.OsMemoryAbove1Mb = 0x0000;\r | |
1839 | for (TempIndex = Above1MIndex; TempIndex < Index; TempIndex++) {\r | |
1840 | if (E820Table[TempIndex].BaseAddr >= 0x100000 && E820Table[TempIndex].BaseAddr < 0x100000000ULL) { // not include above 4G memory\r | |
1841 | //\r | |
1842 | // ACPIReclaimMemory is also usable memory for ACPI OS, after OS dumps all ACPI tables.\r | |
1843 | //\r | |
1844 | if ((E820Table[TempIndex].Type == EfiAcpiAddressRangeMemory) || (E820Table[TempIndex].Type == EfiAcpiAddressRangeACPI)) {\r | |
1845 | Private->IntThunk->EfiToLegacy16BootTable.OsMemoryAbove1Mb += (UINT32) (E820Table[TempIndex].Length);\r | |
1846 | } else {\r | |
1847 | break; // break at first not normal memory, because SMM may use reserved memory.\r | |
1848 | }\r | |
1849 | }\r | |
1850 | }\r | |
1851 | \r | |
1852 | Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb = Private->IntThunk->EfiToLegacy16BootTable.OsMemoryAbove1Mb;\r | |
1853 | \r | |
1854 | //\r | |
1855 | // Print DEBUG information\r | |
1856 | //\r | |
1857 | for (TempIndex = 0; TempIndex < Index; TempIndex++) {\r | |
1858 | DEBUG((EFI_D_INFO, "E820[%2d]: 0x%16lx ---- 0x%16lx, Type = 0x%x \n",\r | |
1859 | TempIndex,\r | |
1860 | E820Table[TempIndex].BaseAddr,\r | |
1861 | (E820Table[TempIndex].BaseAddr + E820Table[TempIndex].Length),\r | |
1862 | E820Table[TempIndex].Type\r | |
1863 | ));\r | |
1864 | }\r | |
1865 | \r | |
1866 | return EFI_SUCCESS;\r | |
1867 | }\r | |
1868 | \r | |
1869 | \r | |
1870 | /**\r | |
1871 | Fill in the standard BDA and EBDA stuff prior to legacy Boot\r | |
1872 | \r | |
1873 | @param Private Legacy BIOS Instance data\r | |
1874 | \r | |
1875 | @retval EFI_SUCCESS It should always work.\r | |
1876 | \r | |
1877 | **/\r | |
1878 | EFI_STATUS\r | |
1879 | LegacyBiosCompleteBdaBeforeBoot (\r | |
1880 | IN LEGACY_BIOS_INSTANCE *Private\r | |
1881 | )\r | |
1882 | {\r | |
1883 | BDA_STRUC *Bda;\r | |
1884 | UINT16 MachineConfig;\r | |
1885 | DEVICE_PRODUCER_DATA_HEADER *SioPtr;\r | |
1886 | \r | |
1887 | Bda = (BDA_STRUC *) ((UINTN) 0x400);\r | |
1888 | MachineConfig = 0;\r | |
1889 | \r | |
1890 | SioPtr = &(Private->IntThunk->EfiToLegacy16BootTable.SioData);\r | |
1891 | Bda->Com1 = SioPtr->Serial[0].Address;\r | |
1892 | Bda->Com2 = SioPtr->Serial[1].Address;\r | |
1893 | Bda->Com3 = SioPtr->Serial[2].Address;\r | |
1894 | Bda->Com4 = SioPtr->Serial[3].Address;\r | |
1895 | \r | |
1896 | if (SioPtr->Serial[0].Address != 0x00) {\r | |
1897 | MachineConfig += 0x200;\r | |
1898 | }\r | |
1899 | \r | |
1900 | if (SioPtr->Serial[1].Address != 0x00) {\r | |
1901 | MachineConfig += 0x200;\r | |
1902 | }\r | |
1903 | \r | |
1904 | if (SioPtr->Serial[2].Address != 0x00) {\r | |
1905 | MachineConfig += 0x200;\r | |
1906 | }\r | |
1907 | \r | |
1908 | if (SioPtr->Serial[3].Address != 0x00) {\r | |
1909 | MachineConfig += 0x200;\r | |
1910 | }\r | |
1911 | \r | |
1912 | Bda->Lpt1 = SioPtr->Parallel[0].Address;\r | |
1913 | Bda->Lpt2 = SioPtr->Parallel[1].Address;\r | |
1914 | Bda->Lpt3 = SioPtr->Parallel[2].Address;\r | |
1915 | \r | |
1916 | if (SioPtr->Parallel[0].Address != 0x00) {\r | |
1917 | MachineConfig += 0x4000;\r | |
1918 | }\r | |
1919 | \r | |
1920 | if (SioPtr->Parallel[1].Address != 0x00) {\r | |
1921 | MachineConfig += 0x4000;\r | |
1922 | }\r | |
1923 | \r | |
1924 | if (SioPtr->Parallel[2].Address != 0x00) {\r | |
1925 | MachineConfig += 0x4000;\r | |
1926 | }\r | |
1927 | \r | |
1928 | Bda->NumberOfDrives = (UINT8) (Bda->NumberOfDrives + Private->IdeDriveCount);\r | |
1929 | if (SioPtr->Floppy.NumberOfFloppy != 0x00) {\r | |
1930 | MachineConfig = (UINT16) (MachineConfig + 0x01 + (SioPtr->Floppy.NumberOfFloppy - 1) * 0x40);\r | |
1931 | Bda->FloppyXRate = 0x07;\r | |
1932 | }\r | |
1933 | \r | |
1934 | Bda->Lpt1_2Timeout = 0x1414;\r | |
1935 | Bda->Lpt3_4Timeout = 0x1414;\r | |
1936 | Bda->Com1_2Timeout = 0x0101;\r | |
1937 | Bda->Com3_4Timeout = 0x0101;\r | |
1938 | \r | |
1939 | //\r | |
1940 | // Force VGA and Coprocessor, indicate 101/102 keyboard\r | |
1941 | //\r | |
1942 | MachineConfig = (UINT16) (MachineConfig + 0x00 + 0x02 + (SioPtr->MousePresent * 0x04));\r | |
1943 | Bda->MachineConfig = MachineConfig;\r | |
1944 | \r | |
1945 | return EFI_SUCCESS;\r | |
1946 | }\r | |
1947 | \r | |
1948 | /**\r | |
1949 | Fill in the standard BDA for Keyboard LEDs\r | |
1950 | \r | |
1951 | @param This Protocol instance pointer.\r | |
1952 | @param Leds Current LED status\r | |
1953 | \r | |
1954 | @retval EFI_SUCCESS It should always work.\r | |
1955 | \r | |
1956 | **/\r | |
1957 | EFI_STATUS\r | |
1958 | EFIAPI\r | |
1959 | LegacyBiosUpdateKeyboardLedStatus (\r | |
1960 | IN EFI_LEGACY_BIOS_PROTOCOL *This,\r | |
1961 | IN UINT8 Leds\r | |
1962 | )\r | |
1963 | {\r | |
1964 | LEGACY_BIOS_INSTANCE *Private;\r | |
1965 | BDA_STRUC *Bda;\r | |
1966 | UINT8 LocalLeds;\r | |
1967 | EFI_IA32_REGISTER_SET Regs;\r | |
1968 | \r | |
1969 | Bda = (BDA_STRUC *) ((UINTN) 0x400);\r | |
1970 | \r | |
1971 | Private = LEGACY_BIOS_INSTANCE_FROM_THIS (This);\r | |
1972 | LocalLeds = Leds;\r | |
1973 | Bda->LedStatus = (UINT8) ((Bda->LedStatus &~0x07) | LocalLeds);\r | |
1974 | LocalLeds = (UINT8) (LocalLeds << 4);\r | |
1975 | Bda->ShiftStatus = (UINT8) ((Bda->ShiftStatus &~0x70) | LocalLeds);\r | |
1976 | LocalLeds = (UINT8) (Leds & 0x20);\r | |
1977 | Bda->KeyboardStatus = (UINT8) ((Bda->KeyboardStatus &~0x20) | LocalLeds);\r | |
1978 | //\r | |
1979 | // Call into Legacy16 code to allow it to do any processing\r | |
1980 | //\r | |
1981 | ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r | |
1982 | Regs.X.AX = Legacy16SetKeyboardLeds;\r | |
1983 | Regs.H.CL = Leds;\r | |
1984 | \r | |
1985 | Private->LegacyBios.FarCall86 (\r | |
1986 | &Private->LegacyBios,\r | |
1987 | Private->Legacy16Table->Compatibility16CallSegment,\r | |
1988 | Private->Legacy16Table->Compatibility16CallOffset,\r | |
1989 | &Regs,\r | |
1990 | NULL,\r | |
1991 | 0\r | |
1992 | );\r | |
1993 | \r | |
1994 | return EFI_SUCCESS;\r | |
1995 | }\r | |
1996 | \r | |
1997 | \r | |
1998 | /**\r | |
1999 | Fill in the standard CMOS stuff prior to legacy Boot\r | |
2000 | \r | |
2001 | @param Private Legacy BIOS Instance data\r | |
2002 | \r | |
2003 | @retval EFI_SUCCESS It should always work.\r | |
2004 | \r | |
2005 | **/\r | |
2006 | EFI_STATUS\r | |
2007 | LegacyBiosCompleteStandardCmosBeforeBoot (\r | |
2008 | IN LEGACY_BIOS_INSTANCE *Private\r | |
2009 | )\r | |
2010 | {\r | |
2011 | UINT8 Bda;\r | |
2012 | UINT8 Floppy;\r | |
2013 | UINT32 Size;\r | |
2014 | \r | |
2015 | //\r | |
2016 | // Update CMOS locations\r | |
2017 | // 10 floppy\r | |
2018 | // 12,19,1A - ignore as OS don't use them and there is no standard due\r | |
2019 | // to large capacity drives\r | |
2020 | // CMOS 14 = BDA 40:10 plus bit 3(display enabled)\r | |
2021 | //\r | |
2022 | Bda = (UINT8)(*((UINT8 *)((UINTN)0x410)) | BIT3);\r | |
2023 | \r | |
2024 | //\r | |
2025 | // Force display enabled\r | |
2026 | //\r | |
2027 | Floppy = 0x00;\r | |
2028 | if ((Bda & BIT0) != 0) {\r | |
2029 | Floppy = BIT6;\r | |
2030 | }\r | |
2031 | \r | |
2032 | //\r | |
2033 | // Check if 2.88MB floppy set\r | |
2034 | //\r | |
2035 | if ((Bda & (BIT7 | BIT6)) != 0) {\r | |
2036 | Floppy = (UINT8)(Floppy | BIT1);\r | |
2037 | }\r | |
2038 | \r | |
2039 | LegacyWriteStandardCmos (CMOS_10, Floppy);\r | |
2040 | LegacyWriteStandardCmos (CMOS_14, Bda);\r | |
2041 | \r | |
2042 | //\r | |
2043 | // Force Status Register A to set rate selection bits and divider\r | |
2044 | //\r | |
2045 | LegacyWriteStandardCmos (CMOS_0A, 0x26);\r | |
2046 | \r | |
2047 | //\r | |
2048 | // redo memory size since it can change\r | |
2049 | //\r | |
2050 | Size = 15 * SIZE_1MB;\r | |
2051 | if (Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb < (15 * SIZE_1MB)) {\r | |
2052 | Size = Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb >> 10;\r | |
2053 | }\r | |
2054 | \r | |
2055 | LegacyWriteStandardCmos (CMOS_17, (UINT8)(Size & 0xFF));\r | |
2056 | LegacyWriteStandardCmos (CMOS_30, (UINT8)(Size & 0xFF));\r | |
2057 | LegacyWriteStandardCmos (CMOS_18, (UINT8)(Size >> 8));\r | |
2058 | LegacyWriteStandardCmos (CMOS_31, (UINT8)(Size >> 8));\r | |
2059 | \r | |
2060 | LegacyCalculateWriteStandardCmosChecksum ();\r | |
2061 | \r | |
2062 | return EFI_SUCCESS;\r | |
2063 | }\r | |
2064 | \r | |
2065 | /**\r | |
2066 | Relocate this image under 4G memory for IPF.\r | |
2067 | \r | |
2068 | @param ImageHandle Handle of driver image.\r | |
2069 | @param SystemTable Pointer to system table.\r | |
2070 | \r | |
2071 | @retval EFI_SUCCESS Image successfully relocated.\r | |
2072 | @retval EFI_ABORTED Failed to relocate image.\r | |
2073 | \r | |
2074 | **/\r | |
2075 | EFI_STATUS\r | |
2076 | RelocateImageUnder4GIfNeeded (\r | |
2077 | IN EFI_HANDLE ImageHandle,\r | |
2078 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
2079 | )\r | |
2080 | {\r | |
2081 | return EFI_SUCCESS;\r | |
2082 | }\r |