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