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