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