]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/Library/DuetBdsLib/BdsPlatform.c
fixed bug for special case.
[mirror_edk2.git] / DuetPkg / Library / DuetBdsLib / BdsPlatform.c
CommitLineData
c69dd9df 1/*++\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 BdsPlatform.c\r
15\r
16Abstract:\r
17\r
18 This file include all platform action which can be customized\r
19 by IBV/OEM.\r
20\r
21--*/\r
22\r
23#include "BdsPlatform.h"\r
24\r
25#define IS_PCI_ISA_PDECODE(_p) IS_CLASS3 (_p, PCI_CLASS_BRIDGE, PCI_CLASS_BRIDGE_ISA_PDECODE, 0)\r
26\r
27CHAR16 mFirmwareVendor[] = L"TianoCore.org";\r
28extern BOOLEAN gConnectAllHappened;\r
29extern USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath;\r
30//\r
31// BDS Platform Functions\r
32//\r
33\r
34VOID\r
35GetSystemTablesFromHob (\r
36 VOID\r
37 )\r
38/*++\r
39\r
40Routine Description:\r
41 Find GUID'ed HOBs that contain EFI_PHYSICAL_ADDRESS of ACPI, SMBIOS, MPs tables\r
42\r
43Arguments:\r
44 None\r
45\r
46Returns:\r
47 None.\r
48\r
49--*/\r
50{\r
51 EFI_STATUS Status;\r
52 EFI_HOB_HANDOFF_INFO_TABLE *HobList;\r
53 EFI_HOB_HANDOFF_INFO_TABLE *HobStart;\r
54 EFI_PHYSICAL_ADDRESS *Table;\r
55 UINTN Index;\r
56 EFI_GUID *TableGuidArray[] = {\r
57 &gEfiAcpi20TableGuid, &gEfiAcpiTableGuid, &gEfiSmbiosTableGuid, &gEfiMpsTableGuid\r
58 };\r
59\r
60 //\r
61 // Get Hob List\r
62 //\r
63 Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, (VOID *) &HobList);\r
64 if (EFI_ERROR (Status)) {\r
65 return;\r
66 }\r
67\r
68 //\r
69 // Iteratively add ACPI Table, SMBIOS Table, MPS Table to EFI System Table\r
70 //\r
71 for (Index = 0; Index < sizeof (TableGuidArray) / sizeof (*TableGuidArray); ++Index) {\r
72 HobStart = HobList;\r
73 Table = NULL;\r
74 Table = GetNextGuidHob (TableGuidArray[Index], &HobStart);\r
75 if (!EFI_ERROR (Status)) {\r
76 if (Table != NULL) {\r
77 //\r
78 // Check if Mps Table/Smbios Table/Acpi Table exists in E/F seg,\r
79 // According to UEFI Spec, we should make sure Smbios table, \r
80 // ACPI table and Mps tables kept in memory of specified type\r
81 //\r
82 ConvertSystemTable(TableGuidArray[Index], &Table);\r
83 gBS->InstallConfigurationTable (TableGuidArray[Index], (VOID *)Table);\r
84 }\r
85 }\r
86 }\r
87\r
88 return ;\r
89}\r
90\r
91#define EFI_LDR_MEMORY_DESCRIPTOR_GUID \\r
92 { 0x7701d7e5, 0x7d1d, 0x4432, 0xa4, 0x68, 0x67, 0x3d, 0xab, 0x8a, 0xde, 0x60 }\r
93\r
94EFI_GUID gEfiLdrMemoryDescriptorGuid = EFI_LDR_MEMORY_DESCRIPTOR_GUID;\r
95\r
96#pragma pack(1)\r
97\r
98typedef struct {\r
99 EFI_HOB_GUID_TYPE Hob;\r
100 UINTN MemDescCount;\r
101 EFI_MEMORY_DESCRIPTOR *MemDesc;\r
102} MEMORY_DESC_HOB;\r
103\r
104#pragma pack()\r
105\r
106#if 0\r
107VOID\r
108PrintMemoryMap (\r
109 VOID\r
110 )\r
111{\r
112 EFI_MEMORY_DESCRIPTOR *MemMap;\r
113 EFI_MEMORY_DESCRIPTOR *MemMapPtr;\r
114 UINTN MemMapSize;\r
115 UINTN MapKey, DescriptorSize;\r
116 UINTN Index;\r
117 UINT32 DescriptorVersion;\r
118 UINT64 Bytes;\r
119 EFI_STATUS Status;\r
120\r
121 MemMapSize = 0;\r
122 MemMap = NULL;\r
123 Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);\r
124 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
125 MemMapSize += EFI_PAGE_SIZE;\r
126 Status = gBS->AllocatePool (EfiBootServicesData, MemMapSize, &MemMap);\r
127 ASSERT (Status == EFI_SUCCESS);\r
128 Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);\r
129 ASSERT (Status == EFI_SUCCESS);\r
130 MemMapPtr = MemMap;\r
131\r
132 ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);\r
133\r
134 for (Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {\r
135 Bytes = LShiftU64 (MemMap->NumberOfPages, 12);\r
136 DEBUG ((EFI_D_ERROR, "%lX-%lX %lX %lX %X\n",\r
137 MemMap->PhysicalStart, \r
138 MemMap->PhysicalStart + Bytes - 1,\r
139 MemMap->NumberOfPages, \r
140 MemMap->Attribute,\r
141 (UINTN)MemMap->Type));\r
142 MemMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMap + DescriptorSize);\r
143 }\r
144\r
145 gBS->FreePool (MemMapPtr);\r
146}\r
147#endif\r
148\r
149VOID\r
150UpdateMemoryMap (\r
151 VOID\r
152 )\r
153{\r
154 EFI_STATUS Status;\r
155 EFI_HOB_HANDOFF_INFO_TABLE *HobList;\r
156 VOID *Table;\r
157 MEMORY_DESC_HOB MemoryDescHob;\r
158 UINTN Index;\r
159 EFI_PHYSICAL_ADDRESS Memory;\r
160\r
161 //\r
162 // Get Hob List\r
163 //\r
164 Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, (VOID *) &HobList);\r
165 if (EFI_ERROR (Status)) {\r
166 return;\r
167 }\r
168\r
169 Table = GetNextGuidHob (&gEfiLdrMemoryDescriptorGuid, &HobList);\r
170 MemoryDescHob.MemDescCount = *(UINTN *)Table;\r
171 MemoryDescHob.MemDesc = *(EFI_MEMORY_DESCRIPTOR **)((UINTN)Table + sizeof(UINTN));\r
172\r
173 //\r
174 // Add ACPINVS, ACPIReclaim, and Reserved memory to MemoryMap\r
175 //\r
176 for (Index = 0; Index < MemoryDescHob.MemDescCount; Index++) {\r
177 if (MemoryDescHob.MemDesc[Index].PhysicalStart < 0x100000) {\r
178 continue;\r
179 }\r
180 if (MemoryDescHob.MemDesc[Index].PhysicalStart >= 0x100000000) {\r
181 continue;\r
182 }\r
183 if ((MemoryDescHob.MemDesc[Index].Type == EfiReservedMemoryType) ||\r
184 (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) ||\r
185 (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode) ||\r
186 (MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||\r
187 (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {\r
188 DEBUG ((EFI_D_ERROR, "PhysicalStart - 0x%x, ", MemoryDescHob.MemDesc[Index].PhysicalStart));\r
189 DEBUG ((EFI_D_ERROR, "PageNumber - 0x%x, ", MemoryDescHob.MemDesc[Index].NumberOfPages));\r
190 DEBUG ((EFI_D_ERROR, "Type - 0x%x\n", MemoryDescHob.MemDesc[Index].Type));\r
191 if ((MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesData) ||\r
192 (MemoryDescHob.MemDesc[Index].Type == EfiRuntimeServicesCode)) {\r
193 //\r
194 // Skip RuntimeSevicesData and RuntimeServicesCode, they are BFV\r
195 //\r
196 continue;\r
197 }\r
198 Status = gDS->AddMemorySpace (\r
199 EfiGcdMemoryTypeSystemMemory,\r
200 MemoryDescHob.MemDesc[Index].PhysicalStart,\r
201 LShiftU64 (MemoryDescHob.MemDesc[Index].NumberOfPages, EFI_PAGE_SHIFT),\r
202 MemoryDescHob.MemDesc[Index].Attribute\r
203 );\r
204 if (EFI_ERROR (Status)) {\r
205 DEBUG ((EFI_D_ERROR, "AddMemorySpace fail!\n"));\r
206 if ((MemoryDescHob.MemDesc[Index].Type == EfiACPIReclaimMemory) ||\r
207 (MemoryDescHob.MemDesc[Index].Type == EfiACPIMemoryNVS)) {\r
208 //\r
209 // For EfiACPIReclaimMemory and EfiACPIMemoryNVS, it must success.\r
210 // For EfiReservedMemoryType, there maybe overlap. So skip check here.\r
211 //\r
212// ASSERT_EFI_ERROR (Status);\r
213 }\r
214 continue;\r
215 }\r
216\r
217 Memory = MemoryDescHob.MemDesc[Index].PhysicalStart;\r
218 Status = gBS->AllocatePages (\r
219 AllocateAddress,\r
220 MemoryDescHob.MemDesc[Index].Type,\r
221 (UINTN)MemoryDescHob.MemDesc[Index].NumberOfPages,\r
222 &Memory\r
223 );\r
224 if (EFI_ERROR (Status)) {\r
225 DEBUG ((EFI_D_ERROR, "AllocatePages fail!\n"));\r
226 //\r
227 // For the page added, it must be allocated.\r
228 //\r
229// ASSERT_EFI_ERROR (Status);\r
230 continue;\r
231 }\r
232 }\r
233 }\r
234 \r
235}\r
236\r
237EFI_STATUS\r
238DisableUsbLegacySupport(\r
239 void\r
240 )\r
241/*++\r
242\r
243Routine Description:\r
244 Disabble the USB legacy Support in all Ehci and Uhci.\r
245 This function assume all PciIo handles have been created in system.\r
246 \r
247Arguments:\r
248 None\r
249 \r
250Returns:\r
251 EFI_SUCCESS\r
252 EFI_NOT_FOUND\r
253--*/\r
254{\r
255 EFI_STATUS Status;\r
256 EFI_HANDLE *HandleArray;\r
257 UINTN HandleArrayCount;\r
258 UINTN Index;\r
259 EFI_PCI_IO_PROTOCOL *PciIo;\r
260 UINT8 Class[3];\r
261 UINT16 Command;\r
262 UINT32 HcCapParams;\r
263 UINT32 ExtendCap;\r
264 UINT32 Value;\r
265 UINT32 TimeOut;\r
266 \r
267 //\r
268 // Find the usb host controller \r
269 // \r
270 Status = gBS->LocateHandleBuffer (\r
271 ByProtocol,\r
272 &gEfiPciIoProtocolGuid,\r
273 NULL,\r
274 &HandleArrayCount,\r
275 &HandleArray\r
276 );\r
277 if (!EFI_ERROR (Status)) {\r
278 for (Index = 0; Index < HandleArrayCount; Index++) {\r
279 Status = gBS->HandleProtocol (\r
280 HandleArray[Index],\r
281 &gEfiPciIoProtocolGuid,\r
282 (VOID **)&PciIo\r
283 );\r
284 if (!EFI_ERROR (Status)) {\r
285 //\r
286 // Find the USB host controller controller\r
287 //\r
288 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);\r
289 if (!EFI_ERROR (Status)) {\r
290 if ((PCI_CLASS_SERIAL == Class[2]) &&\r
291 (PCI_CLASS_SERIAL_USB == Class[1])) {\r
292 if (PCI_CLASSC_PI_UHCI == Class[0]) {\r
293 //\r
294 // Found the UHCI, then disable the legacy support\r
295 //\r
296 Command = 0;\r
297 Status = PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, 0xC0, 1, &Command);\r
298 } else if (PCI_CLASSC_PI_EHCI == Class[0]) {\r
299 //\r
300 // Found the EHCI, then disable the legacy support\r
301 //\r
302 Status = PciIo->Mem.Read (\r
303 PciIo,\r
304 EfiPciIoWidthUint32,\r
305 0, //EHC_BAR_INDEX\r
306 (UINT64) 0x08, //EHC_HCCPARAMS_OFFSET\r
307 1,\r
308 &HcCapParams\r
309 );\r
310 \r
311 ExtendCap = (HcCapParams >> 8) & 0xFF;\r
312 //\r
313 // Disable the SMI in USBLEGCTLSTS firstly\r
314 //\r
315 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap + 0x4, 1, &Value);\r
316 Value &= 0xFFFF0000;\r
317 PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, ExtendCap + 0x4, 1, &Value);\r
318 \r
319 //\r
320 // Get EHCI Ownership from legacy bios\r
321 //\r
322 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap, 1, &Value);\r
323 Value |= (0x1 << 24);\r
324 PciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, ExtendCap, 1, &Value);\r
325\r
326 TimeOut = 40;\r
327 while (TimeOut--) {\r
328 gBS->Stall (500);\r
329\r
330 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ExtendCap, 1, &Value);\r
331\r
332 if ((Value & 0x01010000) == 0x01000000) {\r
333 break;\r
334 }\r
335 }\r
336 }\r
337 } \r
338 }\r
339 }\r
340 }\r
341 } else {\r
342 return Status;\r
343 }\r
344 gBS->FreePool (HandleArray);\r
345 return EFI_SUCCESS;\r
346}\r
347\r
348\r
349VOID\r
350PlatformBdsInit (\r
351 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData\r
352 )\r
353/*++\r
354\r
355Routine Description:\r
356\r
357 Platform Bds init. Incude the platform firmware vendor, revision\r
358 and so crc check.\r
359\r
360Arguments:\r
361\r
362 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
363\r
364Returns:\r
365\r
366 None.\r
367\r
368--*/\r
369{\r
370 //\r
371 // set firmwarevendor, here can be IBV/OEM customize\r
372 //\r
373 gST->FirmwareVendor = AllocateRuntimeCopyPool (\r
374 sizeof (mFirmwareVendor),\r
375 &mFirmwareVendor\r
376 );\r
377 ASSERT (gST->FirmwareVendor != NULL);\r
378\r
379 gST->FirmwareRevision = 0;\r
380\r
381 //\r
382 // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
383 //\r
384 gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
385}\r
386\r
387UINT64\r
388GetPciExpressBaseAddressForRootBridge (\r
389 IN UINTN HostBridgeNumber,\r
390 IN UINTN RootBridgeNumber\r
391 )\r
392/*++\r
393\r
394Routine Description:\r
395 This routine is to get PciExpress Base Address for this RootBridge\r
396\r
397Arguments:\r
398 HostBridgeNumber - The number of HostBridge\r
399 RootBridgeNumber - The number of RootBridge\r
400 \r
401Returns:\r
402 UINT64 - PciExpressBaseAddress for this HostBridge and RootBridge\r
403\r
404--*/\r
405{\r
406 EFI_PCI_EXPRESS_BASE_ADDRESS_INFORMATION *PciExpressBaseAddressInfo;\r
407 UINTN BufferSize;\r
408 UINT32 Index;\r
409 UINT32 Number;\r
410 VOID *HobList;\r
411 EFI_STATUS Status;\r
412\r
413 BufferSize = 0;\r
414 //\r
415 // Get Hob List from configuration table\r
416 //\r
417 Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);\r
418 if (EFI_ERROR (Status)) {\r
419 return 0;\r
420 }\r
421\r
422 //\r
423 // Get PciExpressAddressInfo Hob\r
424 //\r
425 PciExpressBaseAddressInfo = NULL;\r
426 PciExpressBaseAddressInfo = GetNextGuidHob (&gEfiPciExpressBaseAddressGuid, &HobList);\r
427\r
428 //\r
429 // Search the PciExpress Base Address in the Hob for current RootBridge\r
430 //\r
431 Number = (UINT32)(BufferSize / sizeof(EFI_PCI_EXPRESS_BASE_ADDRESS_INFORMATION));\r
432 for (Index = 0; Index < Number; Index++) {\r
433 if ((PciExpressBaseAddressInfo[Index].HostBridgeNumber == HostBridgeNumber) &&\r
434 (PciExpressBaseAddressInfo[Index].RootBridgeNumber == RootBridgeNumber)) {\r
435 return PciExpressBaseAddressInfo[Index].PciExpressBaseAddress;\r
436 }\r
437 }\r
438\r
439 //\r
440 // Do not find the PciExpress Base Address in the Hob\r
441 //\r
442 return 0;\r
443}\r
444\r
445VOID\r
446PatchPciRootBridgeDevicePath (\r
447 IN UINTN HostBridgeNumber,\r
448 IN UINTN RootBridgeNumber,\r
449 IN PLATFORM_ROOT_BRIDGE_DEVICE_PATH *RootBridge\r
450 )\r
451{\r
452 UINT64 PciExpressBase;\r
453\r
454 PciExpressBase = GetPciExpressBaseAddressForRootBridge (HostBridgeNumber, RootBridgeNumber);\r
455\r
456 if (PciExpressBase != 0) {\r
457 RootBridge->PciRootBridge.HID = EISA_PNP_ID(0x0A08);\r
458 }\r
459}\r
460\r
461EFI_STATUS\r
462ConnectRootBridge (\r
463 VOID\r
464 )\r
465/*++\r
466\r
467Routine Description:\r
468\r
469 Connect RootBridge\r
470\r
471Arguments:\r
472\r
473 None.\r
474 \r
475Returns:\r
476\r
477 EFI_SUCCESS - Connect RootBridge successfully.\r
478 EFI_STATUS - Connect RootBridge fail.\r
479\r
480--*/\r
481{\r
482 EFI_STATUS Status;\r
483 EFI_HANDLE RootHandle;\r
484\r
485 //\r
486 // Patch Pci Root Bridge Device Path\r
487 //\r
488 PatchPciRootBridgeDevicePath (0, 0, &gPlatformRootBridge0);\r
489\r
490 //\r
491 // Make all the PCI_IO protocols on PCI Seg 0 show up\r
492 //\r
493 BdsLibConnectDevicePath (gPlatformRootBridges[0]);\r
494\r
495 Status = gBS->LocateDevicePath (\r
496 &gEfiDevicePathProtocolGuid, \r
497 &gPlatformRootBridges[0], \r
498 &RootHandle\r
499 );\r
500 if (EFI_ERROR (Status)) {\r
501 return Status;\r
502 }\r
503\r
504 Status = gBS->ConnectController (RootHandle, NULL, NULL, FALSE);\r
505 if (EFI_ERROR (Status)) {\r
506 return Status;\r
507 }\r
508\r
509 return EFI_SUCCESS;\r
510}\r
511\r
512EFI_STATUS\r
513PrepareLpcBridgeDevicePath (\r
514 IN EFI_HANDLE DeviceHandle\r
515 )\r
516/*++\r
517\r
518Routine Description:\r
519\r
520 Add IsaKeyboard to ConIn,\r
521 add IsaSerial to ConOut, ConIn, ErrOut.\r
522 LPC Bridge: 06 01 00\r
523\r
524Arguments:\r
525\r
526 DeviceHandle - Handle of PCIIO protocol.\r
527 \r
528Returns:\r
529\r
530 EFI_SUCCESS - LPC bridge is added to ConOut, ConIn, and ErrOut.\r
531 EFI_STATUS - No LPC bridge is added.\r
532\r
533--*/\r
534{\r
535 EFI_STATUS Status;\r
536 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
537 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
538\r
539 DevicePath = NULL;\r
540 Status = gBS->HandleProtocol (\r
541 DeviceHandle,\r
542 &gEfiDevicePathProtocolGuid,\r
543 &DevicePath\r
544 );\r
545 if (EFI_ERROR (Status)) {\r
546 return Status;\r
547 }\r
548 TempDevicePath = DevicePath;\r
549\r
550 //\r
551 // Register Keyboard\r
552 //\r
553 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnpPs2KeyboardDeviceNode);\r
554\r
555 BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
556\r
557 //\r
558 // Register COM1\r
559 //\r
560 DevicePath = TempDevicePath;\r
561 gPnp16550ComPortDeviceNode.UID = 0;\r
562\r
563 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);\r
564 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
565 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
566\r
567 BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
568 BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
569 BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
570\r
571 //\r
572 // Register COM2\r
573 //\r
574 DevicePath = TempDevicePath;\r
575 gPnp16550ComPortDeviceNode.UID = 1;\r
576\r
577 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gPnp16550ComPortDeviceNode);\r
578 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
579 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
580\r
581 BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
582 BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
583 BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
584\r
585 return EFI_SUCCESS;\r
586}\r
587\r
588#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
589EFI_STATUS\r
590GetGopDevicePath (\r
591 IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,\r
592 OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath\r
593 )\r
594{\r
595 UINTN Index;\r
596 EFI_STATUS Status;\r
597 EFI_HANDLE PciDeviceHandle;\r
598 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
599 EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath;\r
600 UINTN GopHandleCount;\r
601 EFI_HANDLE *GopHandleBuffer;\r
602\r
603 if (PciDevicePath == NULL || GopDevicePath == NULL) {\r
604 return EFI_INVALID_PARAMETER;\r
605 }\r
606 \r
607 //\r
608 // Initialize the GopDevicePath to be PciDevicePath\r
609 //\r
610 *GopDevicePath = PciDevicePath;\r
611 TempPciDevicePath = PciDevicePath;\r
612\r
613 Status = gBS->LocateDevicePath (\r
614 &gEfiDevicePathProtocolGuid,\r
615 &TempPciDevicePath,\r
616 &PciDeviceHandle\r
617 );\r
618 if (EFI_ERROR (Status)) {\r
619 return Status;\r
620 }\r
621\r
622 //\r
623 // Try to connect this handle, so that GOP dirver could start on this \r
624 // device and create child handles with GraphicsOutput Protocol installed\r
625 // on them, then we get device paths of these child handles and select \r
626 // them as possible console device.\r
627 //\r
628 gBS->ConnectController (PciDeviceHandle, NULL, NULL, FALSE);\r
629\r
630 Status = gBS->LocateHandleBuffer (\r
631 ByProtocol,\r
632 &gEfiGraphicsOutputProtocolGuid,\r
633 NULL,\r
634 &GopHandleCount,\r
635 &GopHandleBuffer\r
636 );\r
637 if (!EFI_ERROR (Status)) {\r
638 //\r
639 // Add all the child handles as possible Console Device\r
640 //\r
641 for (Index = 0; Index < GopHandleCount; Index++) {\r
642 Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, &TempDevicePath);\r
643 if (EFI_ERROR (Status)) {\r
644 continue;\r
645 }\r
646 if (CompareMem (\r
647 PciDevicePath,\r
648 TempDevicePath,\r
649 GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH\r
650 ) == 0) {\r
651 //\r
652 // In current implementation, we only enable one of the child handles\r
653 // as console device, i.e. sotre one of the child handle's device\r
654 // path to variable "ConOut"\r
655 // In futhure, we could select all child handles to be console device\r
656 // \r
657\r
658 *GopDevicePath = TempDevicePath;\r
659\r
660 //\r
661 // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()\r
662 // Add the integrity GOP device path.\r
663 //\r
664 BdsLibUpdateConsoleVariable (VarConsoleOutDev, NULL, PciDevicePath);\r
665 BdsLibUpdateConsoleVariable (VarConsoleOutDev, TempDevicePath, NULL);\r
666 }\r
667 }\r
668 gBS->FreePool (GopHandleBuffer);\r
669 }\r
670\r
671 return EFI_SUCCESS;\r
672}\r
673#endif\r
674\r
675EFI_STATUS\r
676PreparePciVgaDevicePath (\r
677 IN EFI_HANDLE DeviceHandle\r
678 )\r
679/*++\r
680\r
681Routine Description:\r
682\r
683 Add PCI VGA to ConOut.\r
684 PCI VGA: 03 00 00\r
685\r
686Arguments:\r
687\r
688 DeviceHandle - Handle of PCIIO protocol.\r
689 \r
690Returns:\r
691\r
692 EFI_SUCCESS - PCI VGA is added to ConOut.\r
693 EFI_STATUS - No PCI VGA device is added.\r
694\r
695--*/\r
696{\r
697 EFI_STATUS Status;\r
698 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
699#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
700 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;\r
701#endif \r
702\r
703 DevicePath = NULL;\r
704 Status = gBS->HandleProtocol (\r
705 DeviceHandle,\r
706 &gEfiDevicePathProtocolGuid,\r
707 &DevicePath\r
708 );\r
709 if (EFI_ERROR (Status)) {\r
710 return Status;\r
711 }\r
712 \r
713#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
714 GetGopDevicePath (DevicePath, &GopDevicePath);\r
715 DevicePath = GopDevicePath;\r
716#endif\r
717\r
718 BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
719 \r
720 return EFI_SUCCESS;\r
721}\r
722\r
723EFI_STATUS\r
724PreparePciSerialDevicePath (\r
725 IN EFI_HANDLE DeviceHandle\r
726 )\r
727/*++\r
728\r
729Routine Description:\r
730\r
731 Add PCI Serial to ConOut, ConIn, ErrOut.\r
732 PCI Serial: 07 00 02\r
733\r
734Arguments:\r
735\r
736 DeviceHandle - Handle of PCIIO protocol.\r
737 \r
738Returns:\r
739\r
740 EFI_SUCCESS - PCI Serial is added to ConOut, ConIn, and ErrOut.\r
741 EFI_STATUS - No PCI Serial device is added.\r
742\r
743--*/\r
744{\r
745 EFI_STATUS Status;\r
746 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
747\r
748 DevicePath = NULL;\r
749 Status = gBS->HandleProtocol (\r
750 DeviceHandle,\r
751 &gEfiDevicePathProtocolGuid,\r
752 &DevicePath\r
753 );\r
754 if (EFI_ERROR (Status)) {\r
755 return Status;\r
756 }\r
757\r
758 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUartDeviceNode);\r
759 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gTerminalTypeDeviceNode);\r
760\r
761 BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
762 BdsLibUpdateConsoleVariable (VarConsoleInp, DevicePath, NULL);\r
763 BdsLibUpdateConsoleVariable (VarErrorOut, DevicePath, NULL);\r
764 \r
765 return EFI_SUCCESS;\r
766}\r
767\r
768EFI_STATUS\r
769DetectAndPreparePlatformPciDevicePath (\r
770 BOOLEAN DetectVgaOnly\r
771 )\r
772/*++\r
773\r
774Routine Description:\r
775\r
776 Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
777\r
778Arguments:\r
779\r
780 DetectVgaOnly - Only detect VGA device if it's TRUE.\r
781 \r
782Returns:\r
783\r
784 EFI_SUCCESS - PCI Device check and Console variable update successfully.\r
785 EFI_STATUS - PCI Device check or Console variable update fail.\r
786\r
787--*/\r
788{\r
789 EFI_STATUS Status;\r
790 UINTN HandleCount;\r
791 EFI_HANDLE *HandleBuffer;\r
792 UINTN Index;\r
793 EFI_PCI_IO_PROTOCOL *PciIo;\r
794 PCI_TYPE00 Pci;\r
795\r
796 //\r
797 // Start to check all the PciIo to find all possible device\r
798 //\r
799 HandleCount = 0;\r
800 HandleBuffer = NULL;\r
801 Status = gBS->LocateHandleBuffer (\r
802 ByProtocol,\r
803 &gEfiPciIoProtocolGuid,\r
804 NULL,\r
805 &HandleCount,\r
806 &HandleBuffer\r
807 );\r
808 if (EFI_ERROR (Status)) {\r
809 return Status;\r
810 }\r
811\r
812 for (Index = 0; Index < HandleCount; Index++) {\r
813 Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, &PciIo);\r
814 if (EFI_ERROR (Status)) {\r
815 continue;\r
816 }\r
817\r
818 //\r
819 // Check for all PCI device\r
820 //\r
821 Status = PciIo->Pci.Read (\r
822 PciIo,\r
823 EfiPciIoWidthUint32,\r
824 0,\r
825 sizeof (Pci) / sizeof (UINT32),\r
826 &Pci\r
827 );\r
828 if (EFI_ERROR (Status)) {\r
829 continue;\r
830 }\r
831\r
832 if (!DetectVgaOnly) {\r
833 //\r
834 // Here we decide whether it is LPC Bridge\r
835 //\r
836 if ((IS_PCI_LPC (&Pci)) ||\r
837 ((IS_PCI_ISA_PDECODE (&Pci)) && (Pci.Hdr.VendorId == 0x8086) && (Pci.Hdr.DeviceId == 0x7110))) {\r
838 //\r
839 // Add IsaKeyboard to ConIn,\r
840 // add IsaSerial to ConOut, ConIn, ErrOut\r
841 //\r
842 PrepareLpcBridgeDevicePath (HandleBuffer[Index]);\r
843 continue;\r
844 }\r
845 //\r
846 // Here we decide which Serial device to enable in PCI bus \r
847 //\r
848 if (IS_PCI_16550SERIAL (&Pci)) {\r
849 //\r
850 // Add them to ConOut, ConIn, ErrOut.\r
851 //\r
852 PreparePciSerialDevicePath (HandleBuffer[Index]);\r
853 continue;\r
854 }\r
855 }\r
856\r
857 //\r
858 // Here we decide which VGA device to enable in PCI bus \r
859 //\r
860 if (IS_PCI_VGA (&Pci)) {\r
861 //\r
862 // Add them to ConOut.\r
863 //\r
864 PreparePciVgaDevicePath (HandleBuffer[Index]);\r
865 continue;\r
866 }\r
867 }\r
868 \r
869 gBS->FreePool (HandleBuffer);\r
870 \r
871 return EFI_SUCCESS;\r
872}\r
873\r
874EFI_STATUS\r
875PlatformBdsConnectConsole (\r
876 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r
877 )\r
878/*++\r
879\r
880Routine Description:\r
881\r
882 Connect the predefined platform default console device. Always try to find\r
883 and enable the vga device if have.\r
884\r
885Arguments:\r
886\r
887 PlatformConsole - Predfined platform default console device array.\r
888 \r
889Returns:\r
890\r
891 EFI_SUCCESS - Success connect at least one ConIn and ConOut \r
892 device, there must have one ConOut device is \r
893 active vga device.\r
894 \r
895 EFI_STATUS - Return the status of \r
896 BdsLibConnectAllDefaultConsoles ()\r
897\r
898--*/\r
899{\r
900 EFI_STATUS Status;\r
901 UINTN Index;\r
902 EFI_DEVICE_PATH_PROTOCOL *VarConout;\r
903 EFI_DEVICE_PATH_PROTOCOL *VarConin;\r
904 UINTN DevicePathSize;\r
905\r
906 //\r
907 // Connect RootBridge\r
908 //\r
909 ConnectRootBridge ();\r
910\r
911 VarConout = BdsLibGetVariableAndSize (\r
912 VarConsoleOut,\r
913 &gEfiGlobalVariableGuid,\r
914 &DevicePathSize\r
915 );\r
916 VarConin = BdsLibGetVariableAndSize (\r
917 VarConsoleInp,\r
918 &gEfiGlobalVariableGuid,\r
919 &DevicePathSize\r
920 );\r
921 if (VarConout == NULL || VarConin == NULL) {\r
922 //\r
923 // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
924 //\r
925 DetectAndPreparePlatformPciDevicePath (FALSE);\r
926\r
927 //\r
928 // Have chance to connect the platform default console,\r
929 // the platform default console is the minimue device group\r
930 // the platform should support\r
931 //\r
932 for (Index = 0; PlatformConsole[Index].DevicePath != NULL; ++Index) {\r
933 //\r
934 // Update the console variable with the connect type\r
935 //\r
936 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
937 BdsLibUpdateConsoleVariable (VarConsoleInp, PlatformConsole[Index].DevicePath, NULL);\r
938 }\r
939 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
940 BdsLibUpdateConsoleVariable (VarConsoleOut, PlatformConsole[Index].DevicePath, NULL);\r
941 }\r
942 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
943 BdsLibUpdateConsoleVariable (VarErrorOut, PlatformConsole[Index].DevicePath, NULL);\r
944 }\r
945 }\r
946 } else {\r
947 //\r
948 // Only detect VGA device and add them to ConOut\r
949 //\r
950 DetectAndPreparePlatformPciDevicePath (TRUE);\r
951 }\r
952 \r
953 //\r
954 // The ConIn devices connection will start the USB bus, should disable all\r
955 // Usb legacy support firstly.\r
956 // Caution: Must ensure the PCI bus driver has been started. Since the \r
957 // ConnectRootBridge() will create all the PciIo protocol, it's safe here now\r
958 //\r
959 Status = DisableUsbLegacySupport();\r
960 \r
961 //\r
962 // Connect the all the default console with current cosole variable\r
963 //\r
964 Status = BdsLibConnectAllDefaultConsoles ();\r
965 if (EFI_ERROR (Status)) {\r
966 return Status;\r
967 }\r
968\r
969 return EFI_SUCCESS;\r
970}\r
971\r
972VOID\r
973PlatformBdsConnectSequence (\r
974 VOID\r
975 )\r
976/*++\r
977\r
978Routine Description:\r
979\r
980 Connect with predeined platform connect sequence, \r
981 the OEM/IBV can customize with their own connect sequence.\r
982 \r
983Arguments:\r
984\r
985 None.\r
986 \r
987Returns:\r
988\r
989 None.\r
990 \r
991--*/\r
992{\r
993 UINTN Index;\r
994\r
995 Index = 0;\r
996\r
997 //\r
998 // Here we can get the customized platform connect sequence\r
999 // Notes: we can connect with new variable which record the\r
1000 // last time boots connect device path sequence\r
1001 //\r
1002 while (gPlatformConnectSequence[Index] != NULL) {\r
1003 //\r
1004 // Build the platform boot option\r
1005 //\r
1006 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
1007 Index++;\r
1008 }\r
1009\r
1010}\r
1011\r
1012VOID\r
1013PlatformBdsGetDriverOption (\r
1014 IN OUT LIST_ENTRY *BdsDriverLists\r
1015 )\r
1016/*++\r
1017\r
1018Routine Description:\r
1019\r
1020 Load the predefined driver option, OEM/IBV can customize this\r
1021 to load their own drivers\r
1022 \r
1023Arguments:\r
1024\r
1025 BdsDriverLists - The header of the driver option link list.\r
1026 \r
1027Returns:\r
1028\r
1029 None.\r
1030 \r
1031--*/\r
1032{\r
1033 UINTN Index;\r
1034\r
1035 Index = 0;\r
1036\r
1037 //\r
1038 // Here we can get the customized platform driver option\r
1039 //\r
1040 while (gPlatformDriverOption[Index] != NULL) {\r
1041 //\r
1042 // Build the platform boot option\r
1043 //\r
1044 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
1045 Index++;\r
1046 }\r
1047\r
1048}\r
1049\r
1050VOID\r
1051PlatformBdsDiagnostics (\r
1052 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,\r
1053 IN BOOLEAN QuietBoot\r
1054 )\r
1055/*++\r
1056\r
1057Routine Description:\r
1058\r
1059 Perform the platform diagnostic, such like test memory. OEM/IBV also\r
1060 can customize this fuction to support specific platform diagnostic.\r
1061 \r
1062Arguments:\r
1063\r
1064 MemoryTestLevel - The memory test intensive level\r
1065 \r
1066 QuietBoot - Indicate if need to enable the quiet boot\r
1067 \r
1068Returns:\r
1069\r
1070 None.\r
1071 \r
1072--*/\r
1073{\r
1074 EFI_STATUS Status;\r
1075\r
1076 //\r
1077 // Here we can decide if we need to show\r
1078 // the diagnostics screen\r
1079 // Notes: this quiet boot code should be remove\r
1080 // from the graphic lib\r
1081 //\r
1082 if (QuietBoot) {\r
ff514e29 1083 Status = EnableQuietBootEx (&gEfiDefaultBmpLogoGuid, mBdsImageHandle);\r
1084 if (EFI_ERROR (Status)) {\r
1085 DisableQuietBoot ();\r
1086 return;\r
1087 }\r
1088\r
c69dd9df 1089 //\r
1090 // Perform system diagnostic\r
1091 //\r
1092 Status = BdsMemoryTest (MemoryTestLevel);\r
1093 if (EFI_ERROR (Status)) {\r
1094 DisableQuietBoot ();\r
1095 }\r
1096\r
1097 return ;\r
1098 }\r
1099 //\r
1100 // Perform system diagnostic\r
1101 //\r
1102 Status = BdsMemoryTest (MemoryTestLevel);\r
1103}\r
1104\r
1105VOID\r
1106PlatformBdsPolicyBehavior (\r
1107 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,\r
1108 IN OUT LIST_ENTRY *DriverOptionList,\r
1109 IN OUT LIST_ENTRY *BootOptionList\r
1110 )\r
1111/*++\r
1112\r
1113Routine Description:\r
1114\r
1115 The function will excute with as the platform policy, current policy\r
1116 is driven by boot mode. IBV/OEM can customize this code for their specific\r
1117 policy action.\r
1118 \r
1119Arguments:\r
1120\r
1121 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
1122 \r
1123 DriverOptionList - The header of the driver option link list\r
1124 \r
1125 BootOptionList - The header of the boot option link list\r
1126 \r
1127Returns:\r
1128\r
1129 None.\r
1130 \r
1131--*/\r
1132{\r
1133 EFI_STATUS Status;\r
1134 UINT16 Timeout;\r
1135 EFI_EVENT UserInputDurationTime;\r
1136 LIST_ENTRY *Link;\r
1137 BDS_COMMON_OPTION *BootOption;\r
1138 UINTN Index;\r
1139 EFI_INPUT_KEY Key;\r
1140 EFI_TPL OldTpl;\r
1141\r
1142 //\r
1143 // Init the time out value\r
1144 //\r
1145 Timeout = BdsLibGetTimeout ();\r
1146\r
1147 //\r
1148 // Load the driver option as the driver option list\r
1149 //\r
1150 PlatformBdsGetDriverOption (DriverOptionList);\r
1151\r
1152 //\r
1153 // Get current Boot Mode\r
1154 //\r
1155 Status = BdsLibGetBootMode (&PrivateData->BootMode);\r
1156 DEBUG ((EFI_D_ERROR, "Boot Mode:%x\n", PrivateData->BootMode));\r
1157\r
1158 //\r
1159 // Go the different platform policy with different boot mode\r
1160 // Notes: this part code can be change with the table policy\r
1161 //\r
1162 ASSERT (PrivateData->BootMode == BOOT_WITH_FULL_CONFIGURATION);\r
1163 //\r
1164 // Connect platform console\r
1165 //\r
1166 Status = PlatformBdsConnectConsole (gPlatformConsole);\r
1167 if (EFI_ERROR (Status)) {\r
1168 //\r
1169 // Here OEM/IBV can customize with defined action\r
1170 //\r
1171 PlatformBdsNoConsoleAction ();\r
1172 }\r
1173 //\r
1174 // Create a 300ms duration event to ensure user has enough input time to enter Setup\r
1175 //\r
1176 Status = gBS->CreateEvent (\r
1177 EFI_EVENT_TIMER,\r
1178 0,\r
1179 NULL,\r
1180 NULL,\r
1181 &UserInputDurationTime\r
1182 );\r
1183 ASSERT (Status == EFI_SUCCESS);\r
1184 Status = gBS->SetTimer (UserInputDurationTime, TimerRelative, 3000000);\r
1185 ASSERT (Status == EFI_SUCCESS);\r
1186 //\r
1187 // Memory test and Logo show\r
1188 //\r
1189 PlatformBdsDiagnostics (IGNORE, TRUE);\r
1190\r
1191 //\r
1192 // Perform some platform specific connect sequence\r
1193 //\r
1194 PlatformBdsConnectSequence ();\r
1195\r
1196 //\r
1197 // Give one chance to enter the setup if we\r
1198 // have the time out\r
1199 //\r
1200 if (Timeout != 0) {\r
1201 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
1202 }\r
1203\r
1204 //\r
1205 //BdsLibConnectAll ();\r
1206 //BdsLibEnumerateAllBootOption (BootOptionList); \r
1207 \r
1208 //\r
1209 // Please uncomment above ConnectAll and EnumerateAll code and remove following first boot\r
1210 // checking code in real production tip.\r
1211 // \r
1212 // In BOOT_WITH_FULL_CONFIGURATION boot mode, should always connect every device \r
1213 // and do enumerate all the default boot options. But in development system board, the boot mode \r
1214 // cannot be BOOT_ASSUMING_NO_CONFIGURATION_CHANGES because the machine box\r
1215 // is always open. So the following code only do the ConnectAll and EnumerateAll at first boot.\r
1216 //\r
1217 Status = BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
1218 if (EFI_ERROR(Status)) {\r
1219 //\r
1220 // If cannot find "BootOrder" variable, it may be first boot. \r
1221 // Try to connect all devices and enumerate all boot options here.\r
1222 //\r
1223 BdsLibConnectAll ();\r
1224 BdsLibEnumerateAllBootOption (BootOptionList);\r
1225 } \r
1226\r
1227 //\r
1228 // To give the User a chance to enter Setup here, if user set TimeOut is 0.\r
1229 // BDS should still give user a chance to enter Setup\r
1230 //\r
1231 // Connect first boot option, and then check user input before exit \r
1232 //\r
1233 for (Link = BootOptionList->ForwardLink; Link != BootOptionList;Link = Link->ForwardLink) {\r
1234 BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
1235 if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {\r
1236 //\r
1237 // skip the header of the link list, becuase it has no boot option\r
1238 //\r
1239 continue;\r
1240 } else {\r
1241 //\r
1242 // Make sure the boot option device path connected, but ignore the BBS device path\r
1243 //\r
1244 if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {\r
1245 BdsLibConnectDevicePath (BootOption->DevicePath);\r
1246 } \r
1247 break; \r
1248 }\r
1249 } \r
1250\r
1251 //\r
1252 // Check whether the user input after the duration time has expired \r
1253 //\r
d55eb54d 1254 OldTpl = EfiGetCurrentTpl();\r
c69dd9df 1255 gBS->RestoreTPL (TPL_APPLICATION); \r
1256 gBS->WaitForEvent (1, &UserInputDurationTime, &Index);\r
1257 gBS->CloseEvent (UserInputDurationTime);\r
1258 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
1259 gBS->RaiseTPL (OldTpl); \r
1260 \r
1261 if (!EFI_ERROR (Status)) {\r
1262 //\r
1263 // Enter Setup if user input \r
1264 //\r
1265 Timeout = 0xffff;\r
1266 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
1267 }\r
1268 \r
1269 return ;\r
1270\r
1271}\r
1272\r
1273VOID\r
1274PlatformBdsBootSuccess (\r
1275 IN BDS_COMMON_OPTION *Option\r
1276 )\r
1277/*++\r
1278\r
1279Routine Description:\r
1280 \r
1281 Hook point after a boot attempt succeeds. We don't expect a boot option to\r
1282 return, so the EFI 1.0 specification defines that you will default to an\r
1283 interactive mode and stop processing the BootOrder list in this case. This\r
1284 is alos a platform implementation and can be customized by IBV/OEM.\r
1285\r
1286Arguments:\r
1287\r
1288 Option - Pointer to Boot Option that succeeded to boot.\r
1289\r
1290Returns:\r
1291 \r
1292 None.\r
1293\r
1294--*/\r
1295{\r
1296 CHAR16 *TmpStr;\r
1297\r
1298 //\r
1299 // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
1300 // select loop then we need to pop up a UI and wait for user input.\r
1301 //\r
1302 TmpStr = Option->StatusString;\r
1303 if (TmpStr != NULL) {\r
1304 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
1305 gBS->FreePool (TmpStr);\r
1306 }\r
1307}\r
1308\r
1309VOID\r
1310PlatformBdsBootFail (\r
1311 IN BDS_COMMON_OPTION *Option,\r
1312 IN EFI_STATUS Status,\r
1313 IN CHAR16 *ExitData,\r
1314 IN UINTN ExitDataSize\r
1315 )\r
1316/*++\r
1317\r
1318Routine Description:\r
1319 \r
1320 Hook point after a boot attempt fails.\r
1321\r
1322Arguments:\r
1323 \r
1324 Option - Pointer to Boot Option that failed to boot.\r
1325\r
1326 Status - Status returned from failed boot.\r
1327\r
1328 ExitData - Exit data returned from failed boot.\r
1329\r
1330 ExitDataSize - Exit data size returned from failed boot.\r
1331\r
1332Returns:\r
1333 \r
1334 None.\r
1335\r
1336--*/\r
1337{\r
1338 CHAR16 *TmpStr;\r
1339\r
1340 //\r
1341 // If Boot returned with failed status then we need to pop up a UI and wait\r
1342 // for user input.\r
1343 //\r
1344 TmpStr = Option->StatusString;\r
1345 if (TmpStr != NULL) {\r
1346 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
1347 gBS->FreePool (TmpStr);\r
1348 }\r
1349\r
1350}\r
1351\r
1352EFI_STATUS\r
1353PlatformBdsNoConsoleAction (\r
1354 VOID\r
1355 )\r
1356/*++\r
1357\r
1358Routine Description:\r
1359 \r
1360 This function is remained for IBV/OEM to do some platform action,\r
1361 if there no console device can be connected.\r
1362\r
1363Arguments:\r
1364 \r
1365 None.\r
1366 \r
1367Returns:\r
1368 \r
1369 EFI_SUCCESS - Direct return success now.\r
1370\r
1371--*/\r
1372{\r
1373 return EFI_SUCCESS;\r
1374}\r
1375\r
1376EFI_STATUS\r
1377ConvertSystemTable (\r
1378 IN EFI_GUID *TableGuid,\r
1379 IN OUT VOID **Table\r
1380 )\r
1381/*++\r
1382\r
1383Routine Description:\r
1384 Convert ACPI Table /Smbios Table /MP Table if its location is lower than Address:0x100000\r
1385 Assumption here:\r
1386 As in legacy Bios, ACPI/Smbios/MP table is required to place in E/F Seg, \r
1387 So here we just check if the range is E/F seg, \r
1388 and if Not, assume the Memory type is EfiACPIReclaimMemory/EfiACPIMemoryNVS\r
1389\r
1390Arguments:\r
1391 TableGuid - Guid of the table\r
1392 Table - pointer to the table \r
1393\r
1394Returns:\r
1395 EFI_SUCEESS - Convert Table successfully\r
1396 Other - Failed\r
1397\r
1398--*/\r
1399{\r
1400 EFI_STATUS Status;\r
1401 VOID *AcpiHeader;\r
1402 UINTN AcpiTableLen;\r
1403 \r
1404 //\r
1405 // If match acpi guid (1.0, 2.0, or later), Convert ACPI table according to version. \r
1406 //\r
1407 AcpiHeader = (VOID*)(UINTN)(*(UINT64 *)(*Table));\r
1408 \r
1409 if (CompareGuid(TableGuid, &gEfiAcpiTableGuid) || CompareGuid(TableGuid, &gEfiAcpi20TableGuid)){\r
1410 if (((EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiHeader)->Reserved == 0x00){\r
1411 //\r
1412 // If Acpi 1.0 Table, then RSDP structure doesn't contain Length field, use structure size\r
1413 //\r
1414 AcpiTableLen = sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);\r
1415 } else if (((EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiHeader)->Reserved >= 0x02){\r
1416 //\r
1417 // If Acpi 2.0 or later, use RSDP Length fied.\r
1418 //\r
1419 AcpiTableLen = ((EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)AcpiHeader)->Length;\r
1420 } else {\r
1421 //\r
1422 // Invalid Acpi Version, return\r
1423 //\r
1424 return EFI_UNSUPPORTED;\r
1425 }\r
1426 Status = ConvertAcpiTable (AcpiTableLen, Table);\r
1427 return Status; \r
1428 }\r
1429 \r
1430 //\r
1431 // If matches smbios guid, convert Smbios table.\r
1432 //\r
1433 if (CompareGuid(TableGuid, &gEfiSmbiosTableGuid)){\r
1434 Status = ConvertSmbiosTable (Table);\r
1435 return Status;\r
1436 }\r
1437 \r
1438 //\r
1439 // If the table is MP table?\r
1440 //\r
1441 if (CompareGuid(TableGuid, &gEfiMpsTableGuid)){\r
1442 Status = ConvertMpsTable (Table);\r
1443 return Status;\r
1444 }\r
1445 \r
1446 return EFI_UNSUPPORTED;\r
1447} \r
1448\r
1449UINT8\r
1450GetBufferCheckSum (\r
1451 IN VOID * Buffer,\r
1452 IN UINTN Length\r
1453 )\r
1454/*++\r
1455\r
1456Routine Description:\r
1457 Caculate buffer checksum (8-bit)\r
1458\r
1459Arguments:\r
1460 Buffer - Pointer to Buffer that to be caculated\r
1461 Length - How many bytes are to be caculated \r
1462\r
1463Returns:\r
1464 Checksum of the buffer\r
1465\r
1466--*/\r
1467{\r
1468 UINT8 CheckSum;\r
1469 UINT8 *Ptr8;\r
1470 \r
1471 CheckSum = 0;\r
1472 Ptr8 = (UINT8 *) Buffer;\r
1473 \r
1474 while (Length > 0) {\r
1475 CheckSum = (UINT8) (CheckSum + *Ptr8++);\r
1476 Length--;\r
1477 }\r
1478 \r
1479 return ((0xFF - CheckSum) + 1);\r
1480} \r
1481\r
1482EFI_STATUS\r
1483ConvertAcpiTable (\r
1484 IN UINTN TableLen,\r
1485 IN OUT VOID **Table\r
1486 )\r
1487/*++\r
1488\r
1489Routine Description:\r
1490 Convert RSDP of ACPI Table if its location is lower than Address:0x100000\r
1491 Assumption here:\r
1492 As in legacy Bios, ACPI table is required to place in E/F Seg, \r
1493 So here we just check if the range is E/F seg, \r
1494 and if Not, assume the Memory type is EfiACPIReclaimMemory/EfiACPIMemoryNVS\r
1495\r
1496Arguments:\r
1497 TableLen - Acpi RSDP length\r
1498 Table - pointer to the table \r
1499\r
1500Returns:\r
1501 EFI_SUCEESS - Convert Table successfully\r
1502 Other - Failed\r
1503\r
1504--*/\r
1505{\r
1506 VOID *AcpiTableOri;\r
1507 VOID *AcpiTableNew;\r
1508 EFI_STATUS Status;\r
1509 EFI_PHYSICAL_ADDRESS BufferPtr;\r
1510\r
1511 \r
1512 AcpiTableOri = (VOID *)(UINTN)(*(UINT64*)(*Table));\r
1513 if (((UINTN)AcpiTableOri < 0x100000) && ((UINTN)AcpiTableOri > 0xE0000)) {\r
1514 BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;\r
1515 Status = gBS->AllocatePages (\r
1516 AllocateMaxAddress,\r
1517 EfiACPIMemoryNVS,\r
1518 EFI_SIZE_TO_PAGES(TableLen),\r
1519 &BufferPtr\r
1520 );\r
1521 ASSERT_EFI_ERROR (Status);\r
1522 AcpiTableNew = (VOID *)(UINTN)BufferPtr;\r
1523 CopyMem (AcpiTableNew, AcpiTableOri, TableLen);\r
1524 } else {\r
1525 AcpiTableNew = AcpiTableOri;\r
1526 }\r
1527 //\r
1528 // Change configuration table Pointer\r
1529 //\r
1530 *Table = AcpiTableNew;\r
1531 \r
1532 return EFI_SUCCESS;\r
1533}\r
1534\r
1535EFI_STATUS\r
1536ConvertSmbiosTable (\r
1537 IN OUT VOID **Table\r
1538 )\r
1539/*++\r
1540\r
1541Routine Description:\r
1542\r
1543 Convert Smbios Table if the Location of the SMBios Table is lower than Addres 0x100000\r
1544 Assumption here:\r
1545 As in legacy Bios, Smbios table is required to place in E/F Seg, \r
1546 So here we just check if the range is F seg, \r
1547 and if Not, assume the Memory type is EfiACPIMemoryNVS/EfiRuntimeServicesData\r
1548Arguments:\r
1549 Table - pointer to the table\r
1550\r
1551Returns:\r
1552 EFI_SUCEESS - Convert Table successfully\r
1553 Other - Failed\r
1554\r
1555--*/\r
1556{\r
1557 SMBIOS_TABLE_ENTRY_POINT *SmbiosTableNew;\r
1558 SMBIOS_TABLE_ENTRY_POINT *SmbiosTableOri;\r
1559 EFI_STATUS Status;\r
1560 UINT32 SmbiosEntryLen;\r
1561 UINT32 BufferLen;\r
1562 EFI_PHYSICAL_ADDRESS BufferPtr;\r
1563 \r
1564 SmbiosTableNew = NULL;\r
1565 SmbiosTableOri = NULL;\r
1566 \r
1567 //\r
1568 // Get Smibos configuration Table \r
1569 //\r
1570 SmbiosTableOri = (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)(*(UINT64*)(*Table));\r
1571 \r
1572 if ((SmbiosTableOri == NULL) ||\r
1573 ((UINTN)SmbiosTableOri > 0x100000) ||\r
1574 ((UINTN)SmbiosTableOri < 0xF0000)){\r
1575 return EFI_SUCCESS;\r
1576 }\r
1577 //\r
1578 // Relocate the Smibos memory\r
1579 //\r
1580 BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;\r
1581 if (SmbiosTableOri->SmbiosBcdRevision != 0x21) {\r
1582 SmbiosEntryLen = SmbiosTableOri->EntryPointLength;\r
1583 } else {\r
1584 //\r
1585 // According to Smbios Spec 2.4, we should set entry point length as 0x1F if version is 2.1\r
1586 //\r
1587 SmbiosEntryLen = 0x1F;\r
1588 }\r
1589 BufferLen = SmbiosEntryLen + SYS_TABLE_PAD(SmbiosEntryLen) + SmbiosTableOri->TableLength;\r
1590 Status = gBS->AllocatePages (\r
1591 AllocateMaxAddress,\r
1592 EfiACPIMemoryNVS,\r
1593 EFI_SIZE_TO_PAGES(BufferLen),\r
1594 &BufferPtr\r
1595 );\r
1596 ASSERT_EFI_ERROR (Status);\r
1597 SmbiosTableNew = (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)BufferPtr;\r
1598 CopyMem (\r
1599 SmbiosTableNew, \r
1600 SmbiosTableOri,\r
1601 SmbiosEntryLen\r
1602 );\r
1603 // \r
1604 // Get Smbios Structure table address, and make sure the start address is 32-bit align\r
1605 //\r
1606 BufferPtr += SmbiosEntryLen + SYS_TABLE_PAD(SmbiosEntryLen);\r
1607 CopyMem (\r
1608 (VOID *)(UINTN)BufferPtr, \r
1609 (VOID *)(UINTN)(SmbiosTableOri->TableAddress),\r
1610 SmbiosTableOri->TableLength\r
1611 );\r
1612 SmbiosTableNew->TableAddress = (UINT32)BufferPtr;\r
1613 SmbiosTableNew->IntermediateChecksum = 0;\r
1614 SmbiosTableNew->IntermediateChecksum = \r
1615 GetBufferCheckSum ((UINT8*)SmbiosTableNew + 0x10, SmbiosEntryLen -0x10);\r
1616 //\r
1617 // Change the SMBIOS pointer\r
1618 //\r
1619 *Table = SmbiosTableNew;\r
1620 \r
1621 return EFI_SUCCESS; \r
1622} \r
1623\r
1624EFI_STATUS\r
1625ConvertMpsTable (\r
1626 IN OUT VOID **Table\r
1627 )\r
1628/*++\r
1629\r
1630Routine Description:\r
1631\r
1632 Convert MP Table if the Location of the SMBios Table is lower than Addres 0x100000\r
1633 Assumption here:\r
1634 As in legacy Bios, MP table is required to place in E/F Seg, \r
1635 So here we just check if the range is E/F seg, \r
1636 and if Not, assume the Memory type is EfiACPIMemoryNVS/EfiRuntimeServicesData\r
1637Arguments:\r
1638 Table - pointer to the table\r
1639\r
1640Returns:\r
1641 EFI_SUCEESS - Convert Table successfully\r
1642 Other - Failed\r
1643\r
1644--*/\r
1645{\r
1646 UINT32 Data32;\r
1647 UINT32 FPLength;\r
1648 EFI_LEGACY_MP_TABLE_FLOATING_POINTER *MpsFloatingPointerOri;\r
1649 EFI_LEGACY_MP_TABLE_FLOATING_POINTER *MpsFloatingPointerNew;\r
1650 EFI_LEGACY_MP_TABLE_HEADER *MpsTableOri;\r
1651 EFI_LEGACY_MP_TABLE_HEADER *MpsTableNew;\r
1652 VOID *OemTableOri;\r
1653 VOID *OemTableNew;\r
1654 EFI_STATUS Status;\r
1655 EFI_PHYSICAL_ADDRESS BufferPtr;\r
1656 \r
1657 //\r
1658 // Get MP configuration Table \r
1659 //\r
1660 MpsFloatingPointerOri = (EFI_LEGACY_MP_TABLE_FLOATING_POINTER *)(UINTN)(*(UINT64*)(*Table));\r
1661 if (!(((UINTN)MpsFloatingPointerOri <= 0x100000) && \r
1662 ((UINTN)MpsFloatingPointerOri >= 0xF0000))){\r
1663 return EFI_SUCCESS;\r
1664 }\r
1665 //\r
1666 // Get Floating pointer structure length\r
1667 //\r
1668 FPLength = MpsFloatingPointerOri->Length * 16;\r
1669 Data32 = FPLength + SYS_TABLE_PAD (FPLength);\r
1670 MpsTableOri = (EFI_LEGACY_MP_TABLE_HEADER *)(UINTN)(MpsFloatingPointerOri->PhysicalAddress);\r
1671 if (MpsTableOri != NULL) {\r
1672 Data32 += MpsTableOri->BaseTableLength;\r
1673 Data32 += MpsTableOri->ExtendedTableLength;\r
1674 if (MpsTableOri->OemTablePointer != 0x00) {\r
1675 Data32 += SYS_TABLE_PAD (Data32);\r
1676 Data32 += MpsTableOri->OemTableSize;\r
1677 }\r
1678 } else {\r
1679 return EFI_SUCCESS;\r
1680 }\r
1681 //\r
1682 // Relocate memory\r
1683 //\r
1684 BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS;\r
1685 Status = gBS->AllocatePages (\r
1686 AllocateMaxAddress,\r
1687 EfiACPIMemoryNVS,\r
1688 EFI_SIZE_TO_PAGES(Data32),\r
1689 &BufferPtr\r
1690 );\r
1691 ASSERT_EFI_ERROR (Status); \r
1692 MpsFloatingPointerNew = (EFI_LEGACY_MP_TABLE_FLOATING_POINTER *)(UINTN)BufferPtr;\r
1693 CopyMem (MpsFloatingPointerNew, MpsFloatingPointerOri, FPLength);\r
1694 //\r
1695 // If Mp Table exists\r
1696 //\r
1697 if (MpsTableOri != NULL) {\r
1698 //\r
1699 // Get Mps table length, including Ext table\r
1700 //\r
1701 BufferPtr = BufferPtr + FPLength + SYS_TABLE_PAD (FPLength);\r
1702 MpsTableNew = (EFI_LEGACY_MP_TABLE_HEADER *)(UINTN)BufferPtr;\r
1703 CopyMem (MpsTableNew, MpsTableOri, MpsTableOri->BaseTableLength + MpsTableOri->ExtendedTableLength);\r
1704 \r
1705 if ((MpsTableOri->OemTableSize != 0x0000) && (MpsTableOri->OemTablePointer != 0x0000)){\r
1706 BufferPtr += MpsTableOri->BaseTableLength + MpsTableOri->ExtendedTableLength;\r
1707 BufferPtr += SYS_TABLE_PAD (BufferPtr);\r
1708 OemTableNew = (VOID *)(UINTN)BufferPtr;\r
1709 OemTableOri = (VOID *)(UINTN)MpsTableOri->OemTablePointer;\r
1710 CopyMem (OemTableNew, OemTableOri, MpsTableOri->OemTableSize);\r
1711 MpsTableNew->OemTablePointer = (UINT32)(UINTN)OemTableNew;\r
1712 }\r
1713 MpsTableNew->Checksum = 0;\r
1714 MpsTableNew->Checksum = GetBufferCheckSum (MpsTableNew, MpsTableOri->BaseTableLength);\r
1715 MpsFloatingPointerNew->PhysicalAddress = (UINT32)(UINTN)MpsTableNew;\r
1716 MpsFloatingPointerNew->Checksum = 0;\r
1717 MpsFloatingPointerNew->Checksum = GetBufferCheckSum (MpsFloatingPointerNew, FPLength);\r
1718 }\r
1719 //\r
1720 // Change the pointer\r
1721 //\r
1722 *Table = MpsFloatingPointerNew;\r
1723 \r
1724 return EFI_SUCCESS; \r
1725} \r