]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
Vlv2TbltDevicePkg/SmBiosMiscDxe: Fix GCC build issue
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / PlatformBdsLib / BdsPlatform.c
CommitLineData
3cbfba02
DW
1/** @file\r
2\r
af7bc37a 3 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
04d8d883 4 \r
9dc8036d 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
04d8d883 6 \r
3cbfba02
DW
7\r
8\r
9Module Name:\r
10\r
11 BdsPlatform.c\r
12\r
13Abstract:\r
14\r
15 This file include all platform action which can be customized\r
16 by IBV/OEM.\r
17\r
18--*/\r
19\r
20#include "BdsPlatform.h"\r
21#include "SetupMode.h"\r
22#include <Guid/SetupVariable.h>\r
23#include <Library/TcgPhysicalPresenceLib.h>\r
33aaf8d7 24#include <Library/Tcg2PhysicalPresenceLib.h>\r
3cbfba02
DW
25#include <Protocol/I2cMasterMcg.h>\r
26#include <TianoApi.h>\r
27#include <PlatformBaseAddresses.h>\r
28#include <Protocol/GlobalNvsArea.h>\r
29#include <Library/DxeServicesTableLib.h>\r
30#include <Protocol/BlockIo.h>\r
31#include <PchRegs/PchRegsPcu.h>\r
32#include <Library/S3BootScriptLib.h>\r
33#include "PchAccess.h"\r
34#include "PchRegs/PchRegsSata.h"\r
35#include <Library/SerialPortLib.h>\r
36#include <Library/DebugLib.h>\r
37\r
69a99d0b
MG
38#include <Library/GenericBdsLib/InternalBdsLib.h>\r
39#include <Library/GenericBdsLib/String.h>\r
40#include <Library/NetLib.h>\r
3cbfba02 41\r
04d8d883
JY
42#include <Library/CapsuleLib.h>\r
43#include <Protocol/EsrtManagement.h>\r
44\r
3cbfba02
DW
45EFI_GUID *ConnectDriverTable[] = {\r
46 &gEfiMmioDeviceProtocolGuid,\r
47 &gEfiI2cMasterProtocolGuid,\r
48 &gEfiI2cHostProtocolGuid\r
49};\r
50\r
51#define SHELL_ENVIRONMENT_INTERFACE_PROTOCOL \\r
52 { \\r
53 0x47c7b221, 0xc42a, 0x11d2, 0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \\r
54 }\r
55VOID *mShellImageCallbackReg = NULL;\r
56\r
57\r
58\r
59EFI_USER_PROFILE_HANDLE mCurrentUser = NULL;\r
60EFI_EVENT mHotKeyTimerEvent = NULL;\r
61EFI_EVENT mHitHotkeyEvent = NULL;\r
62EFI_EVENT mUsbKeyboardConnectEvent = NULL;\r
63BOOLEAN mHotKeyPressed = FALSE;\r
64VOID *mHitHotkeyRegistration;\r
65#define KEYBOARD_TIMER_INTERVAL 20000 // 0.02s\r
66\r
67VOID\r
68ConnectUSBController (\r
69 VOID\r
70 );\r
71\r
72EFI_STATUS\r
73PlatformBdsConnectSimpleConsole (\r
74 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r
75);\r
76\r
77VOID \r
78BootIntoFirmwareInterface(\r
79 VOID\r
80 );\r
81 \r
82VOID\r
83EFIAPI\r
84PlatformBdsInitHotKeyEvent (\r
85 VOID\r
86 );\r
87\r
88VOID\r
89EFIAPI\r
90DisableAhciCtlr (\r
91 IN EFI_EVENT Event,\r
92 IN VOID *Context\r
93 )\r
94{\r
95 UINT32 PmcDisableAddress;\r
96 UINT8 SataStorageAmount;\r
97 UINT32 SataBase;\r
98 UINT16 SataPortStatus;\r
99\r
100\r
101 DEBUG ((EFI_D_INFO, "Disable AHCI event is signalled\n"));\r
102 SataStorageAmount = 0;\r
103 SataBase = *(UINT32*) Context;\r
104\r
105 //\r
106 // BayTrail-M EDS chapter 16 ---- PCI IO Register Offset 92 (SATA Port Control and Status)\r
107 //\r
108 SataPortStatus = MmioRead16 (SataBase + R_PCH_SATA_PCS);\r
109\r
110 //\r
111 // Bit 8 EN: Port 0 Present\r
112 //\r
113 if ((SataPortStatus & 0x100) == 0x100) {\r
114 SataStorageAmount++;\r
115 }\r
116\r
117 //\r
118 // Bit 9 EN: Port 1 Present\r
119 //\r
120 if ((SataPortStatus & 0x200) == 0x200) {\r
121 SataStorageAmount++;\r
122 }\r
123\r
124 //\r
125 // Disable SATA controller when it sets to AHCI mode without carrying any devices\r
126 // in order to prevent AHCI yellow bang under Win device manager.\r
127 //\r
128 if (SataStorageAmount == 0) {\r
129 PmcDisableAddress = (MmioRead32 ((PCH_PCI_EXPRESS_BASE_ADDRESS + (UINT32) (31 << 15)) + R_PCH_LPC_PMC_BASE) & B_PCH_LPC_PMC_BASE_BAR) + R_PCH_PMC_FUNC_DIS;\r
130 MmioOr32 (PmcDisableAddress, B_PCH_PMC_FUNC_DIS_SATA);\r
131 S3BootScriptSaveMemWrite (\r
132 EfiBootScriptWidthUint32,\r
133 (UINTN) PmcDisableAddress,\r
134 1,\r
135 (VOID *) (UINTN) PmcDisableAddress\r
136 );\r
137 }\r
138}\r
139\r
140VOID\r
141InstallReadyToLock (\r
142 VOID\r
143 )\r
144{\r
145 EFI_STATUS Status;\r
146 EFI_HANDLE Handle;\r
147 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
148 EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;\r
149\r
150 //\r
151 // Install DxeSmmReadyToLock protocol prior to the processing of boot options\r
152 //\r
153 Status = gBS->LocateProtocol (\r
154 &gEfiSmmAccess2ProtocolGuid,\r
155 NULL,\r
156 (VOID **) &SmmAccess\r
157 );\r
158 if (!EFI_ERROR (Status)) {\r
159\r
160 //\r
161 // Prepare S3 information, this MUST be done before DxeSmmReadyToLock\r
162 //\r
163 Status = gBS->LocateProtocol (\r
164 &gEfiAcpiS3SaveProtocolGuid,\r
165 NULL,\r
166 (VOID **)&AcpiS3Save\r
167 );\r
168 if (!EFI_ERROR (Status)) {\r
169 AcpiS3Save->S3Save (AcpiS3Save, NULL);\r
170 }\r
171\r
172 Handle = NULL;\r
173 Status = gBS->InstallProtocolInterface (\r
174 &Handle,\r
175 &gExitPmAuthProtocolGuid,\r
176 EFI_NATIVE_INTERFACE,\r
177 NULL\r
178 );\r
179 ASSERT_EFI_ERROR (Status);\r
180\r
18b00c8c 181 //\r
182 // Signal EndOfDxe PI Event\r
183 //\r
184 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
185\r
3cbfba02
DW
186 Handle = NULL;\r
187 Status = gBS->InstallProtocolInterface (\r
188 &Handle,\r
189 &gEfiDxeSmmReadyToLockProtocolGuid,\r
190 EFI_NATIVE_INTERFACE,\r
191 NULL\r
192 );\r
193 ASSERT_EFI_ERROR (Status);\r
194 }\r
195\r
196 return ;\r
197}\r
198\r
199VOID\r
200EFIAPI\r
201ShellImageCallback (\r
202 IN EFI_EVENT Event,\r
203 IN VOID *Context\r
204 )\r
205{\r
206 BdsSetConsoleMode (TRUE);\r
207 DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n"));\r
208}\r
209\r
210//\r
211// BDS Platform Functions\r
212//\r
213/**\r
2e182e30 214 Platform Bds init. Include the platform firmware vendor, revision\r
3cbfba02
DW
215 and so crc check.\r
216\r
217 @param VOID\r
218\r
219 @retval None.\r
220\r
221**/\r
222VOID\r
223EFIAPI\r
224PlatformBdsInit (\r
225 VOID\r
226 )\r
227{\r
228 EFI_STATUS Status;\r
229 EFI_EVENT ShellImageEvent;\r
230 EFI_GUID ShellEnvProtocol = SHELL_ENVIRONMENT_INTERFACE_PROTOCOL;\r
231\r
232 #ifdef __GNUC__\r
233 SerialPortWrite((UINT8 *)">>>>BdsEntry[GCC]\r\n", 19);\r
234 #else\r
235 SerialPortWrite((UINT8 *)">>>>BdsEntry\r\n", 14);\r
236 #endif\r
237 BdsLibSaveMemoryTypeInformation ();\r
238\r
239 //\r
240 // Before user authentication, the user identification devices need be connected\r
241 // from the platform customized device paths\r
242 //\r
243 PlatformBdsConnectAuthDevice ();\r
244\r
245 //\r
246 // As console is not ready, the auto logon user will be identified.\r
247 //\r
248 BdsLibUserIdentify (&mCurrentUser);\r
249\r
250 //\r
251 // Change Gop mode when boot into Shell\r
252 //\r
253 if (mShellImageCallbackReg == NULL) {\r
254 Status = gBS->CreateEvent (\r
255 EFI_EVENT_NOTIFY_SIGNAL,\r
256 EFI_TPL_CALLBACK,\r
257 ShellImageCallback,\r
258 NULL,\r
259 &ShellImageEvent\r
260 );\r
261 if (!EFI_ERROR (Status)) {\r
262 Status = gBS->RegisterProtocolNotify (\r
263 &ShellEnvProtocol,\r
264 ShellImageEvent,\r
265 &mShellImageCallbackReg\r
266 );\r
267\r
268 DEBUG ((EFI_D_INFO, "BdsEntry ShellImageCallback \n"));\r
269 }\r
270 }\r
271}\r
272\r
273EFI_STATUS\r
274GetGopDevicePath (\r
275 IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,\r
276 OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath\r
277 )\r
278{\r
279 UINTN Index;\r
280 EFI_STATUS Status;\r
281 EFI_HANDLE PciDeviceHandle;\r
282 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
283 EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath;\r
284 UINTN GopHandleCount;\r
285 EFI_HANDLE *GopHandleBuffer;\r
286\r
287 UINTN VarSize;\r
288 SYSTEM_CONFIGURATION mSystemConfiguration;\r
289\r
290 if (PciDevicePath == NULL || GopDevicePath == NULL) {\r
291 return EFI_INVALID_PARAMETER;\r
292 }\r
293\r
294 //\r
295 // Initialize the GopDevicePath to be PciDevicePath\r
296 //\r
297 *GopDevicePath = PciDevicePath;\r
298 TempPciDevicePath = PciDevicePath;\r
299\r
300 Status = gBS->LocateDevicePath (\r
301 &gEfiDevicePathProtocolGuid,\r
302 &TempPciDevicePath,\r
303 &PciDeviceHandle\r
304 );\r
305 if (EFI_ERROR (Status)) {\r
306 return Status;\r
307 }\r
308\r
309 //\r
2e182e30 310 // Try to connect this handle, so that GOP driver could start on this\r
3cbfba02
DW
311 // device and create child handles with GraphicsOutput Protocol installed\r
312 // on them, then we get device paths of these child handles and select\r
313 // them as possible console device.\r
314 //\r
315\r
316 //\r
317 // Select display devices\r
318 //\r
319 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
320 Status = gRT->GetVariable(\r
321 L"Setup",\r
322 &gEfiNormalSetupGuid,\r
323 NULL,\r
324 &VarSize,\r
325 &mSystemConfiguration\r
326 );\r
620f2891
TH
327 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {\r
328 //The setup variable is corrupted\r
329 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
330 Status = gRT->GetVariable(\r
331 L"SetupRecovery",\r
332 &gEfiNormalSetupGuid,\r
333 NULL,\r
334 &VarSize,\r
335 &mSystemConfiguration\r
336 );\r
337 ASSERT_EFI_ERROR (Status);\r
338 } \r
3cbfba02
DW
339\r
340 if(mSystemConfiguration.BootDisplayDevice != 0x0)\r
341 {\r
342 ACPI_ADR_DEVICE_PATH AcpiAdr;\r
343 EFI_DEVICE_PATH_PROTOCOL *MyDevicePath = NULL;\r
344\r
345 AcpiAdr.Header.Type = ACPI_DEVICE_PATH;\r
346 AcpiAdr.Header.SubType = ACPI_ADR_DP;\r
347\r
348 switch (mSystemConfiguration.BootDisplayDevice) {\r
349 case 1:\r
350 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, PORT_CRT, 0); //CRT Device\r
351 break;\r
352 case 2:\r
353 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_B_HDMI, 0); //HDMI Device Port B\r
354 break;\r
355 case 3:\r
356 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_B_DP, 0); //DP PortB\r
357 break;\r
358 case 4:\r
359 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_EXTERNAL_DIGITAL, PORT_C_DP, 0); //DP PortC\r
360 break;\r
361 case 5:\r
362 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_C_DP, 0); //eDP Port C\r
363 break;\r
364 case 6:\r
365 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_MIPI_A, 0); //DSI Port A\r
366 break;\r
367 case 7:\r
368 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_INTERNAL_DIGITAL, PORT_MIPI_C, 0); //DSI Port C\r
369 break;\r
370 default:\r
371 AcpiAdr.ADR= ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, PORT_CRT, 0);\r
372 break;\r
373 }\r
374\r
375 SetDevicePathNodeLength (&AcpiAdr.Header, sizeof (ACPI_ADR_DEVICE_PATH));\r
376\r
377 MyDevicePath = AppendDevicePathNode(MyDevicePath, (EFI_DEVICE_PATH_PROTOCOL*)&AcpiAdr);\r
378\r
379 gBS->ConnectController (\r
380 PciDeviceHandle,\r
381 NULL,\r
382 MyDevicePath,\r
383 FALSE\r
384 );\r
385\r
386 FreePool(MyDevicePath);\r
387 }\r
388 else\r
389 {\r
390 gBS->ConnectController (\r
391 PciDeviceHandle,\r
392 NULL,\r
393 NULL,\r
394 FALSE\r
395 );\r
396 }\r
397\r
398 Status = gBS->LocateHandleBuffer (\r
399 ByProtocol,\r
400 &gEfiGraphicsOutputProtocolGuid,\r
401 NULL,\r
402 &GopHandleCount,\r
403 &GopHandleBuffer\r
404 );\r
405 if (!EFI_ERROR (Status)) {\r
406 //\r
407 // Add all the child handles as possible Console Device\r
408 //\r
409 for (Index = 0; Index < GopHandleCount; Index++) {\r
410 Status = gBS->HandleProtocol (\r
411 GopHandleBuffer[Index],\r
412 &gEfiDevicePathProtocolGuid,\r
413 (VOID**)&TempDevicePath\r
414 );\r
415 if (EFI_ERROR (Status)) {\r
416 continue;\r
417 }\r
418 if (CompareMem (\r
419 PciDevicePath,\r
420 TempDevicePath,\r
421 GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH\r
422 ) == 0) {\r
423 //\r
424 // In current implementation, we only enable one of the child handles\r
425 // as console device, i.e. sotre one of the child handle's device\r
426 // path to variable "ConOut"\r
2e182e30 427 // In future, we could select all child handles to be console device\r
3cbfba02
DW
428 //\r
429 *GopDevicePath = TempDevicePath;\r
430 }\r
431 }\r
432 gBS->FreePool (GopHandleBuffer);\r
433 }\r
434\r
435 return EFI_SUCCESS;\r
436}\r
437\r
438/**\r
439\r
440 Search out all the platform pci or agp video device. The function may will\r
441 find multiple video device, and return all enabled device path.\r
442\r
443 @param PlugInPciVgaDevicePath Return the platform plug in pci video device\r
444 path if the system have plug in pci video device.\r
445 @param OnboardPciVgaDevicePath Return the platform active agp video device path\r
446 if the system have plug in agp video device or on\r
447 chip agp device.\r
448\r
449 @retval EFI_SUCCSS Get all platform active video device path.\r
450 @retval EFI_STATUS Return the status of gBS->LocateDevicePath (),\r
451 gBS->ConnectController (),\r
452 and gBS->LocateHandleBuffer ().\r
453\r
454**/\r
455EFI_STATUS\r
456GetPlugInPciVgaDevicePath (\r
457 IN OUT EFI_DEVICE_PATH_PROTOCOL **PlugInPciVgaDevicePath,\r
458 IN OUT EFI_DEVICE_PATH_PROTOCOL **OnboardPciVgaDevicePath\r
459 )\r
460{\r
461 EFI_STATUS Status;\r
462 EFI_HANDLE RootHandle;\r
463 UINTN HandleCount;\r
464 EFI_HANDLE *HandleBuffer;\r
465 UINTN Index;\r
466 UINTN Index1;\r
467 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
468 BOOLEAN PlugInPciVga;\r
469 EFI_PCI_IO_PROTOCOL *PciIo;\r
470 PCI_TYPE00 Pci;\r
471\r
472 DevicePath = NULL;\r
473 PlugInPciVga = TRUE;\r
474 HandleCount = 0;\r
475 HandleBuffer = NULL;\r
476\r
477 //\r
478 // Make all the PCI_IO protocols on PCI Seg 0 show up\r
479 //\r
480 BdsLibConnectDevicePath (gPlatformRootBridges[0]);\r
481\r
482 Status = gBS->LocateDevicePath (\r
483 &gEfiDevicePathProtocolGuid,\r
484 &gPlatformRootBridges[0],\r
485 &RootHandle\r
486 );\r
487 if (EFI_ERROR (Status)) {\r
488 return Status;\r
489 }\r
490\r
491 Status = gBS->ConnectController (\r
492 RootHandle,\r
493 NULL,\r
494 NULL,\r
495 FALSE\r
496 );\r
497 if (EFI_ERROR (Status)) {\r
498 return Status;\r
499 }\r
500\r
501 //\r
502 // Start to check all the pci io to find all possible VGA device\r
503 //\r
504 HandleCount = 0;\r
505 HandleBuffer = NULL;\r
506 Status = gBS->LocateHandleBuffer (\r
507 ByProtocol,\r
508 &gEfiPciIoProtocolGuid,\r
509 NULL,\r
510 &HandleCount,\r
511 &HandleBuffer\r
512 );\r
513 if (EFI_ERROR (Status)) {\r
514 return Status;\r
515 }\r
516\r
517 for (Index = 0; Index < HandleCount; Index++) {\r
518 Status = gBS->HandleProtocol (\r
519 HandleBuffer[Index],\r
520 &gEfiPciIoProtocolGuid,\r
521 (VOID**)&PciIo\r
522 );\r
523 if (!EFI_ERROR (Status)) {\r
524\r
525 //\r
526 // Check for all VGA device\r
527 //\r
528 Status = PciIo->Pci.Read (\r
529 PciIo,\r
530 EfiPciIoWidthUint32,\r
531 0,\r
532 sizeof (Pci) / sizeof (UINT32),\r
533 &Pci\r
534 );\r
535 if (EFI_ERROR (Status)) {\r
536 continue;\r
537 }\r
538\r
539 //\r
540 // Here we decide which VGA device to enable in PCI bus\r
541 //\r
542 // The first plugin PCI VGA card device will be present as PCI VGA\r
543 // The onchip AGP or AGP card will be present as AGP VGA\r
544 //\r
545 if (!IS_PCI_VGA (&Pci)) {\r
546 continue;\r
547 }\r
548\r
549 //\r
550 // Set the device as the possible console out device,\r
551 //\r
552 // Below code will make every VGA device to be one\r
553 // of the possibe console out device\r
554 //\r
555 PlugInPciVga = TRUE;\r
556 gBS->HandleProtocol (\r
557 HandleBuffer[Index],\r
558 &gEfiDevicePathProtocolGuid,\r
559 (VOID**)&DevicePath\r
560 );\r
561\r
562 Index1 = 0;\r
563\r
564 while (gPlatformAllPossiblePciVgaConsole[Index1] != NULL) {\r
565 if (CompareMem (\r
566 DevicePath,\r
567 gPlatformAllPossiblePciVgaConsole[Index1],\r
568 GetDevicePathSize (gPlatformAllPossiblePciVgaConsole[Index1])\r
569 ) == 0) {\r
570\r
571 //\r
572 // This device is an AGP device\r
573 //\r
574 *OnboardPciVgaDevicePath = DevicePath;\r
575 PlugInPciVga = FALSE;\r
576 break;\r
577 }\r
578\r
579 Index1 ++;\r
580 }\r
581\r
582 if (PlugInPciVga) {\r
583 *PlugInPciVgaDevicePath = DevicePath;\r
584 }\r
585 }\r
586 }\r
587\r
588 FreePool (HandleBuffer);\r
589\r
590 return EFI_SUCCESS;\r
591}\r
592\r
593/**\r
594\r
595 Find the platform active vga, and base on the policy to enable the vga as\r
596 the console out device. The policy is driven by one setup variable "VBIOS".\r
597\r
598 None.\r
599\r
600 @param EFI_UNSUPPORTED There is no active vga device\r
601\r
602 @retval EFI_STATUS Return the status of BdsLibGetVariableAndSize ()\r
603\r
604**/\r
605EFI_STATUS\r
606PlatformBdsForceActiveVga (\r
607 VOID\r
608 )\r
609{\r
610 EFI_STATUS Status;\r
611 EFI_DEVICE_PATH_PROTOCOL *PlugInPciVgaDevicePath;\r
612 EFI_DEVICE_PATH_PROTOCOL *OnboardPciVgaDevicePath;\r
613 EFI_DEVICE_PATH_PROTOCOL *DevicePathFirst;\r
614 EFI_DEVICE_PATH_PROTOCOL *DevicePathSecond;\r
615 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;\r
616 UINTN VarSize;\r
617 SYSTEM_CONFIGURATION mSystemConfiguration;\r
618\r
619 Status = EFI_SUCCESS;\r
620 PlugInPciVgaDevicePath = NULL;\r
621 OnboardPciVgaDevicePath = NULL;\r
622\r
623 //\r
624 // Check the policy which is the first enabled VGA\r
625 //\r
626 GetPlugInPciVgaDevicePath (&PlugInPciVgaDevicePath, &OnboardPciVgaDevicePath);\r
627\r
628 if (PlugInPciVgaDevicePath == NULL && OnboardPciVgaDevicePath == NULL) {\r
629 return EFI_UNSUPPORTED;\r
630 }\r
631\r
632 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
633 Status = gRT->GetVariable(\r
634 L"Setup",\r
635 &gEfiNormalSetupGuid,\r
636 NULL,\r
637 &VarSize,\r
638 &mSystemConfiguration\r
639 );\r
620f2891
TH
640 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {\r
641 //The setup variable is corrupted\r
642 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
643 Status = gRT->GetVariable(\r
644 L"SetupRecovery",\r
645 &gEfiNormalSetupGuid,\r
646 NULL,\r
647 &VarSize,\r
648 &mSystemConfiguration\r
649 );\r
650 ASSERT_EFI_ERROR (Status);\r
651 } \r
3cbfba02
DW
652\r
653\r
654 if ((PlugInPciVgaDevicePath == NULL && OnboardPciVgaDevicePath != NULL) ) {\r
655 DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA ...\n"));\r
656 DevicePathFirst = OnboardPciVgaDevicePath;\r
657 DevicePathSecond = PlugInPciVgaDevicePath;\r
658 goto UpdateConOut;\r
659 }\r
660 if(OnboardPciVgaDevicePath != NULL && mSystemConfiguration.PrimaryVideoAdaptor == 0) {\r
661 DEBUG ((EFI_D_ERROR,"Update onboard PCI VGA When set primary!!!...\n"));\r
662 DevicePathFirst = OnboardPciVgaDevicePath;\r
663 DevicePathSecond = PlugInPciVgaDevicePath;\r
664 goto UpdateConOut;\r
665 }\r
666\r
667 DEBUG ((EFI_D_ERROR,"Update plug in PCI VGA ...\n"));\r
668 DevicePathFirst = PlugInPciVgaDevicePath;\r
669 DevicePathSecond = OnboardPciVgaDevicePath;\r
670\r
671UpdateConOut:\r
672 GetGopDevicePath (DevicePathFirst, &GopDevicePath);\r
673 DevicePathFirst = GopDevicePath;\r
674\r
675 Status = BdsLibUpdateConsoleVariable (\r
676 L"ConOut",\r
677 DevicePathFirst,\r
678 DevicePathSecond\r
679 );\r
680\r
681 return Status;\r
682}\r
683\r
684VOID\r
685UpdateConsoleResolution(\r
686 VOID\r
687 )\r
688{\r
689 UINT32 HorizontalResolution;\r
690 UINT32 VerticalResolution;\r
691 SYSTEM_CONFIGURATION SystemConfiguration;\r
692 UINTN VarSize;\r
693 EFI_STATUS Status;\r
694\r
695\r
696 HorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);\r
697 VerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);\r
698\r
699 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
700 Status = gRT->GetVariable(\r
701 L"Setup",\r
702 &gEfiNormalSetupGuid,\r
703 NULL,\r
704 &VarSize,\r
705 &SystemConfiguration\r
706 );\r
620f2891
TH
707 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {\r
708 //The setup variable is corrupted\r
709 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
710 Status = gRT->GetVariable(\r
711 L"SetupRecovery",\r
712 &gEfiNormalSetupGuid,\r
713 NULL,\r
714 &VarSize,\r
715 &SystemConfiguration\r
716 );\r
717 ASSERT_EFI_ERROR (Status);\r
718 } \r
3cbfba02
DW
719\r
720 switch (SystemConfiguration.IgdFlatPanel) {\r
721\r
722 case 0:\r
723 //\r
724 // Use the detault PCD values.\r
725 //\r
726 break;\r
727\r
728 case 1:\r
729 HorizontalResolution = 640;\r
730 VerticalResolution = 480;\r
731 break;\r
732\r
733 case 2:\r
734 HorizontalResolution = 800;\r
735 VerticalResolution = 600;\r
736 break;\r
737\r
738 case 3:\r
739 HorizontalResolution = 1024;\r
740 VerticalResolution = 768;\r
741 break;\r
742\r
743 case 4:\r
744 HorizontalResolution = 1280;\r
745 VerticalResolution = 1024;\r
746 break;\r
747\r
748 case 5:\r
749 HorizontalResolution = 1366;\r
750 VerticalResolution = 768;\r
751 break;\r
752\r
753 case 6:\r
754 HorizontalResolution = 1680;\r
755 VerticalResolution = 1050;\r
756 break;\r
757\r
758 case 7:\r
759 HorizontalResolution = 1920;\r
760 VerticalResolution = 1200;\r
761 break;\r
762\r
763 case 8:\r
764 HorizontalResolution = 1280;\r
765 VerticalResolution = 800;\r
766 break;\r
767 }\r
768\r
769 PcdSet32 (PcdSetupVideoHorizontalResolution, HorizontalResolution);\r
770 PcdSet32 (PcdSetupVideoVerticalResolution, VerticalResolution);\r
771 DEBUG ((EFI_D_ERROR, "HorizontalResolution = %x; VerticalResolution = %x", HorizontalResolution, VerticalResolution));\r
772\r
773 return;\r
774}\r
775\r
776/**\r
777 Connect the predefined platform default console device. Always try to find\r
778 and enable the vga device if have.\r
779\r
2e182e30 780 @param PlatformConsole Predefined platform default console device array.\r
3cbfba02
DW
781\r
782 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut\r
783 device, there must have one ConOut device is\r
784 active vga device.\r
785\r
786 @retval EFI_STATUS Return the status of\r
787 BdsLibConnectAllDefaultConsoles ()\r
788\r
789**/\r
790EFI_STATUS\r
791PlatformBdsConnectConsole (\r
792 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r
793)\r
794{\r
795 EFI_STATUS Status;\r
796 UINTN Index;\r
797 EFI_DEVICE_PATH_PROTOCOL *VarConout;\r
798 EFI_DEVICE_PATH_PROTOCOL *VarConin;\r
799 UINTN DevicePathSize;\r
800\r
801 UpdateConsoleResolution();\r
802\r
803 Index = 0;\r
804 Status = EFI_SUCCESS;\r
805 DevicePathSize = 0;\r
806 VarConout = BdsLibGetVariableAndSize (\r
807 L"ConOut",\r
808 &gEfiGlobalVariableGuid,\r
809 &DevicePathSize\r
810 );\r
811 VarConin = BdsLibGetVariableAndSize (\r
812 L"ConIn",\r
813 &gEfiGlobalVariableGuid,\r
814 &DevicePathSize\r
815 );\r
816 if (VarConout == NULL || VarConin == NULL) {\r
817 //\r
818 // Have chance to connect the platform default console,\r
2e182e30 819 // the platform default console is the minimum device group\r
3cbfba02
DW
820 // the platform should support\r
821 //\r
822 while (PlatformConsole[Index].DevicePath != NULL) {\r
823\r
824 //\r
825 // Update the console variable with the connect type\r
826 //\r
827 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
828 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
829 }\r
830\r
831 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
832 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
833 }\r
834\r
835 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
836 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
837 }\r
838\r
839 Index ++;\r
840 }\r
841 }\r
842\r
843 //\r
844 // Make sure we have at least one active VGA, and have the right\r
845 // active VGA in console variable\r
846 //\r
847 Status = PlatformBdsForceActiveVga ();\r
848 if (EFI_ERROR (Status)) {\r
849 return Status;\r
850 }\r
851\r
852 DEBUG ((EFI_D_INFO, "DISPLAY INIT DONE\n"));\r
853\r
854 //\r
855 // Connect the all the default console with current console variable\r
856 //\r
857 Status = BdsLibConnectAllDefaultConsoles ();\r
858 if (EFI_ERROR (Status)) {\r
859 return Status;\r
860 }\r
861\r
862 return EFI_SUCCESS;\r
863}\r
864\r
865/**\r
2e182e30 866 Connect with predefined platform connect sequence,\r
3cbfba02
DW
867 the OEM/IBV can customize with their own connect sequence.\r
868\r
869 @param None.\r
870\r
871 @retval None.\r
872\r
873**/\r
874VOID\r
875PlatformBdsConnectSequence (\r
876 VOID\r
877 )\r
878{\r
879 UINTN Index;\r
880\r
881 Index = 0;\r
882\r
883 //\r
884 // Here we can get the customized platform connect sequence\r
885 // Notes: we can connect with new variable which record the\r
886 // last time boots connect device path sequence\r
887 //\r
888 while (gPlatformConnectSequence[Index] != NULL) {\r
889\r
890 //\r
891 // Build the platform boot option\r
892 //\r
893 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
894 Index ++;\r
895 }\r
896\r
897 //\r
898 // Just use the simple policy to connect all devices\r
899 // There should be no difference between debug tip and release tip, or it will be extremely hard to debug.\r
900 //\r
901 // There is case that IdeController driver will write boot script in driver model Start() function. It will be rejected by boot script save.\r
902 // It is only found when DEBUG disabled, because we are using BdsLibConnectAll() when DEBUG enabled.\r
903 //\r
904 // So we use BdsLibConnectAll() here to make sure IdeController.Start() is invoked before InstallReadyToLock().\r
905 // We may also consider to connect SataController only later if needed.\r
906 //\r
907 BdsLibConnectAll ();\r
908}\r
909\r
910/**\r
911\r
912 Load the predefined driver option, OEM/IBV can customize this\r
913 to load their own drivers\r
914\r
915 @param BdsDriverLists The header of the driver option link list.\r
916\r
917 @retval None.\r
918\r
919**/\r
920VOID\r
921PlatformBdsGetDriverOption (\r
922 IN OUT LIST_ENTRY *BdsDriverLists\r
923 )\r
924{\r
925 UINTN Index;\r
926\r
927 Index = 0;\r
928\r
929 //\r
930 // Here we can get the customized platform driver option\r
931 //\r
932 while (gPlatformDriverOption[Index] != NULL) {\r
933\r
934 //\r
935 // Build the platform boot option\r
936 //\r
937 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
938 Index ++;\r
939 }\r
940\r
941}\r
942\r
943/**\r
944 This function is used for some critical time if the the system\r
945 have no any boot option, and there is no time out for user to add\r
946 the new boot option. This can also treat as the platform default\r
947 boot option.\r
948\r
949 @param BdsBootOptionList The header of the boot option link list.\r
950\r
951 @retval None.\r
952\r
953**/\r
954VOID\r
955PlatformBdsPredictBootOption (\r
956 IN OUT LIST_ENTRY *BdsBootOptionList\r
957 )\r
958{\r
959 UINTN Index;\r
960\r
961 Index = 0;\r
962\r
963 //\r
964 // Here give chance to get platform boot option data\r
965 //\r
966 while (gPlatformBootOption[Index] != NULL) {\r
967\r
968 //\r
969 // Build the platform boot option\r
970 //\r
971 BdsLibRegisterNewOption (BdsBootOptionList, gPlatformBootOption[Index], NULL, L"BootOrder");\r
972 Index ++;\r
973 }\r
974}\r
975\r
976/**\r
977 Perform the platform diagnostic, such like test memory. OEM/IBV also\r
978 can customize this fuction to support specific platform diagnostic.\r
979\r
980 @param MemoryTestLevel The memory test intensive level\r
981 @param QuietBoot Indicate if need to enable the quiet boot\r
982 @param BaseMemoryTest A pointer to BdsMemoryTest()\r
983\r
984 @retval None.\r
985\r
986**/\r
987VOID\r
988PlatformBdsDiagnostics (\r
989 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,\r
990 IN BOOLEAN QuietBoot,\r
991 IN BASEM_MEMORY_TEST BaseMemoryTest\r
992 )\r
993{\r
994 EFI_STATUS Status;\r
995\r
996 //\r
997 // Here we can decide if we need to show\r
998 // the diagnostics screen\r
999 // Notes: this quiet boot code should be remove\r
1000 // from the graphic lib\r
1001 //\r
1002 if (QuietBoot) {\r
1003 EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
1004\r
1005 //\r
1006 // Perform system diagnostic\r
1007 //\r
1008 Status = BaseMemoryTest (MemoryTestLevel);\r
1009 if (EFI_ERROR (Status)) {\r
1010 DisableQuietBoot ();\r
1011 }\r
1012\r
1013 return;\r
1014 }\r
1015\r
1016 //\r
1017 // Perform system diagnostic\r
1018 //\r
1019 Status = BaseMemoryTest (MemoryTestLevel);\r
1020}\r
1021\r
1022\r
69a99d0b
MG
1023/**\r
1024 For EFI boot option, BDS separate them as six types:\r
1025 1. Network - The boot option points to the SimpleNetworkProtocol device.\r
1026 Bds will try to automatically create this type boot option when enumerate.\r
1027 2. Shell - The boot option points to internal flash shell.\r
1028 Bds will try to automatically create this type boot option when enumerate.\r
1029 3. Removable BlockIo - The boot option only points to the removable media\r
1030 device, like USB flash disk, DVD, Floppy etc.\r
1031 These device should contain a *removable* blockIo\r
1032 protocol in their device handle.\r
1033 Bds will try to automatically create this type boot option\r
1034 when enumerate.\r
1035 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,\r
1036 like HardDisk.\r
1037 These device should contain a *fixed* blockIo\r
1038 protocol in their device handle.\r
1039 BDS will skip fixed blockIo devices, and NOT\r
1040 automatically create boot option for them. But BDS\r
1041 will help to delete those fixed blockIo boot option,\r
1042 whose description rule conflict with other auto-created\r
1043 boot options.\r
1044 5. Non-BlockIo Simplefile - The boot option points to a device whose handle\r
1045 has SimpleFileSystem Protocol, but has no blockio\r
1046 protocol. These devices do not offer blockIo\r
1047 protocol, but BDS still can get the\r
1048 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem\r
1049 Protocol.\r
1050 6. File - The boot option points to a file. These boot options are usually\r
1051 created by user manually or OS loader. BDS will not delete or modify\r
1052 these boot options.\r
1053\r
1054 This function will enumerate all possible boot device in the system, and\r
1055 automatically create boot options for Network, Shell, Removable BlockIo,\r
1056 and Non-BlockIo Simplefile devices.\r
1057 It will only execute once of every boot.\r
1058\r
1059 @param BdsBootOptionList The header of the link list which indexed all\r
1060 current boot options\r
1061\r
1062 @retval EFI_SUCCESS Finished all the boot device enumerate and create\r
1063 the boot option base on that boot device\r
1064\r
1065 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list\r
1066**/\r
1067EFI_STATUS\r
1068EFIAPI\r
1069PlatformBdsLibEnumerateAllBootOption (\r
1070 IN OUT LIST_ENTRY *BdsBootOptionList\r
1071 )\r
1072{\r
1073 EFI_STATUS Status;\r
1074 UINT16 FloppyNumber;\r
1075 UINT16 HarddriveNumber;\r
1076 UINT16 CdromNumber;\r
1077 UINT16 UsbNumber;\r
1078 UINT16 MiscNumber;\r
1079 UINT16 ScsiNumber;\r
1080 UINT16 NonBlockNumber;\r
1081 UINTN NumberBlockIoHandles;\r
1082 EFI_HANDLE *BlockIoHandles;\r
1083 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
1084 BOOLEAN Removable[2];\r
1085 UINTN RemovableIndex;\r
1086 UINTN Index;\r
1087 UINTN NumOfLoadFileHandles;\r
1088 EFI_HANDLE *LoadFileHandles;\r
1089 UINTN FvHandleCount;\r
1090 EFI_HANDLE *FvHandleBuffer;\r
1091 EFI_FV_FILETYPE Type;\r
1092 UINTN Size;\r
1093 EFI_FV_FILE_ATTRIBUTES Attributes;\r
1094 UINT32 AuthenticationStatus;\r
1095 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
1096 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1097 UINTN DevicePathType;\r
1098 CHAR16 Buffer[40];\r
1099 EFI_HANDLE *FileSystemHandles;\r
1100 UINTN NumberFileSystemHandles;\r
1101 BOOLEAN NeedDelete;\r
1102 EFI_IMAGE_DOS_HEADER DosHeader;\r
1103 CHAR8 *PlatLang;\r
1104 CHAR8 *LastLang;\r
1105 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;\r
1106 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
1107 CHAR16 *MacStr;\r
1108 CHAR16 *IPverStr;\r
1109 EFI_HANDLE *NetworkHandles;\r
1110 UINTN BufferSize;\r
1111\r
1112 FloppyNumber = 0;\r
1113 HarddriveNumber = 0;\r
1114 CdromNumber = 0;\r
1115 UsbNumber = 0;\r
1116 MiscNumber = 0;\r
1117 ScsiNumber = 0;\r
1118 PlatLang = NULL;\r
1119 LastLang = NULL;\r
1120 ZeroMem (Buffer, sizeof (Buffer));\r
1121\r
1122 //\r
1123 // If the boot device enumerate happened, just get the boot\r
1124 // device from the boot order variable\r
1125 //\r
1126 if (mEnumBootDevice) {\r
1127 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (VOID**)&LastLang, NULL);\r
1128 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL);\r
1129 ASSERT (PlatLang != NULL);\r
1130 if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {\r
1131 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
1132 FreePool (LastLang);\r
1133 FreePool (PlatLang);\r
1134 return Status;\r
1135 } else {\r
1136 Status = gRT->SetVariable (\r
1137 LAST_ENUM_LANGUAGE_VARIABLE_NAME,\r
1138 &gLastEnumLangGuid,\r
1139 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1140 AsciiStrSize (PlatLang),\r
1141 PlatLang\r
1142 );\r
1143 //\r
1144 // Failure to set the variable only impacts the performance next time enumerating the boot options.\r
1145 //\r
1146\r
1147 if (LastLang != NULL) {\r
1148 FreePool (LastLang);\r
1149 }\r
1150 FreePool (PlatLang);\r
1151 }\r
1152 }\r
1153\r
1154 //\r
1155 // Notes: this dirty code is to get the legacy boot option from the\r
1156 // BBS table and create to variable as the EFI boot option, it should\r
1157 // be removed after the CSM can provide legacy boot option directly\r
1158 //\r
1159 REFRESH_LEGACY_BOOT_OPTIONS;\r
1160\r
1161 //\r
1162 // Delete invalid boot option\r
1163 //\r
1164 BdsDeleteAllInvalidEfiBootOption ();\r
1165\r
1166 //\r
1167 // Parse removable media followed by fixed media.\r
1168 // The Removable[] array is used by the for-loop below to create removable media boot options \r
1169 // at first, and then to create fixed media boot options.\r
1170 //\r
1171 Removable[0] = FALSE;\r
1172 Removable[1] = TRUE;\r
1173\r
1174 gBS->LocateHandleBuffer (\r
1175 ByProtocol,\r
1176 &gEfiBlockIoProtocolGuid,\r
1177 NULL,\r
1178 &NumberBlockIoHandles,\r
1179 &BlockIoHandles\r
1180 );\r
1181\r
1182 for (RemovableIndex = 0; RemovableIndex < 2; RemovableIndex++) {\r
1183 for (Index = 0; Index < NumberBlockIoHandles; Index++) {\r
1184 Status = gBS->HandleProtocol (\r
1185 BlockIoHandles[Index],\r
1186 &gEfiBlockIoProtocolGuid,\r
1187 (VOID **) &BlkIo\r
1188 );\r
1189 //\r
1190 // skip the logical partition\r
1191 //\r
1192 if (EFI_ERROR (Status) || BlkIo->Media->LogicalPartition) {\r
1193 continue;\r
1194 }\r
1195\r
1196 //\r
1197 // firstly fixed block io then the removable block io\r
1198 //\r
1199 if (BlkIo->Media->RemovableMedia == Removable[RemovableIndex]) {\r
1200 continue;\r
1201 }\r
1202 DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);\r
1203 DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);\r
1204\r
1205 switch (DevicePathType) {\r
1206 case BDS_EFI_ACPI_FLOPPY_BOOT:\r
1207 if (FloppyNumber != 0) {\r
1208 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);\r
1209 } else {\r
1210 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));\r
1211 }\r
1212 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1213 FloppyNumber++;\r
1214 break;\r
1215\r
1216 //\r
1217 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.\r
1218 //\r
1219 case BDS_EFI_MESSAGE_ATAPI_BOOT:\r
1220 case BDS_EFI_MESSAGE_SATA_BOOT:\r
1221 if (BlkIo->Media->RemovableMedia) {\r
1222 if (CdromNumber != 0) {\r
1223 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);\r
1224 } else {\r
1225 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));\r
1226 }\r
1227 CdromNumber++;\r
1228 } else {\r
1229 if (HarddriveNumber != 0) {\r
1230 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber);\r
1231 } else {\r
1232 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)));\r
1233 }\r
1234 HarddriveNumber++;\r
1235 }\r
1236 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));\r
1237 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1238 break;\r
1239\r
1240 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:\r
1241 if (UsbNumber != 0) {\r
1242 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);\r
1243 } else {\r
1244 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));\r
1245 }\r
1246 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1247 UsbNumber++;\r
1248 break;\r
1249\r
1250 case BDS_EFI_MESSAGE_SCSI_BOOT:\r
1251 if (ScsiNumber != 0) {\r
1252 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);\r
1253 } else {\r
1254 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));\r
1255 }\r
1256 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1257 ScsiNumber++;\r
1258 break;\r
1259\r
1260 case BDS_EFI_MESSAGE_MISC_BOOT:\r
1261 default:\r
1262 if (MiscNumber != 0) {\r
1263 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);\r
1264 } else {\r
1265 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));\r
1266 }\r
1267 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1268 MiscNumber++;\r
1269 break;\r
1270 }\r
1271 }\r
1272 }\r
1273\r
1274 if (NumberBlockIoHandles != 0) {\r
1275 FreePool (BlockIoHandles);\r
1276 }\r
1277\r
1278 //\r
1279 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.\r
1280 //\r
1281 NonBlockNumber = 0;\r
1282 gBS->LocateHandleBuffer (\r
1283 ByProtocol,\r
1284 &gEfiSimpleFileSystemProtocolGuid,\r
1285 NULL,\r
1286 &NumberFileSystemHandles,\r
1287 &FileSystemHandles\r
1288 );\r
1289 for (Index = 0; Index < NumberFileSystemHandles; Index++) {\r
1290 Status = gBS->HandleProtocol (\r
1291 FileSystemHandles[Index],\r
1292 &gEfiBlockIoProtocolGuid,\r
1293 (VOID **) &BlkIo\r
1294 );\r
1295 if (!EFI_ERROR (Status)) {\r
1296 //\r
1297 // Skip if the file system handle supports a BlkIo protocol,\r
1298 //\r
1299 continue;\r
1300 }\r
1301\r
1302 //\r
1303 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI\r
1304 // machinename is ia32, ia64, x64, ...\r
1305 //\r
1306 Hdr.Union = &HdrData;\r
1307 NeedDelete = TRUE;\r
1308 Status = BdsLibGetImageHeader (\r
1309 FileSystemHandles[Index],\r
1310 EFI_REMOVABLE_MEDIA_FILE_NAME,\r
1311 &DosHeader,\r
1312 Hdr\r
1313 );\r
1314 if (!EFI_ERROR (Status) &&\r
1315 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&\r
1316 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {\r
1317 NeedDelete = FALSE;\r
1318 }\r
1319\r
1320 if (NeedDelete) {\r
1321 //\r
1322 // No such file or the file is not a EFI application, delete this boot option\r
1323 //\r
1324 BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);\r
1325 } else {\r
1326 if (NonBlockNumber != 0) {\r
1327 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);\r
1328 } else {\r
1329 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));\r
1330 }\r
1331 BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);\r
1332 NonBlockNumber++;\r
1333 }\r
1334 }\r
1335\r
1336 if (NumberFileSystemHandles != 0) {\r
1337 FreePool (FileSystemHandles);\r
1338 }\r
1339\r
1340 //\r
1341 // Check if we have on flash shell\r
1342 //\r
1343 gBS->LocateHandleBuffer (\r
1344 ByProtocol,\r
1345 &gEfiFirmwareVolume2ProtocolGuid,\r
1346 NULL,\r
1347 &FvHandleCount,\r
1348 &FvHandleBuffer\r
1349 );\r
1350 for (Index = 0; Index < FvHandleCount; Index++) {\r
1351 gBS->HandleProtocol (\r
1352 FvHandleBuffer[Index],\r
1353 &gEfiFirmwareVolume2ProtocolGuid,\r
1354 (VOID **) &Fv\r
1355 );\r
1356\r
1357 Status = Fv->ReadFile (\r
1358 Fv,\r
1359 PcdGetPtr(PcdShellFile),\r
1360 NULL,\r
1361 &Size,\r
1362 &Type,\r
1363 &Attributes,\r
1364 &AuthenticationStatus\r
1365 );\r
1366 if (EFI_ERROR (Status)) {\r
1367 //\r
1368 // Skip if no shell file in the FV\r
1369 //\r
1370 continue;\r
1371 }\r
1372 //\r
1373 // Build the shell boot option\r
1374 //\r
1375 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);\r
1376 }\r
1377\r
1378 if (FvHandleCount != 0) {\r
1379 FreePool (FvHandleBuffer);\r
1380 }\r
1381\r
1382 //\r
1383 // Parse Network Boot Device\r
1384 //\r
1385 NumOfLoadFileHandles = 0;\r
1386 //\r
1387 // Search Load File protocol for PXE boot option.\r
1388 //\r
1389 gBS->LocateHandleBuffer (\r
1390 ByProtocol,\r
1391 &gEfiLoadFileProtocolGuid,\r
1392 NULL,\r
1393 &NumOfLoadFileHandles,\r
1394 &LoadFileHandles\r
1395 );\r
1396\r
1397 for (Index = 0; Index < NumOfLoadFileHandles; Index++) {\r
1398\r
1399//\r
1400//Locate EFI_DEVICE_PATH_PROTOCOL to dynamically get IPv4/IPv6 protocol information.\r
1401//\r
1402\r
1403 Status = gBS->HandleProtocol (\r
1404 LoadFileHandles[Index],\r
1405 &gEfiDevicePathProtocolGuid,\r
1406 (VOID **) &DevicePath\r
1407 );\r
1408 \r
1409 ASSERT_EFI_ERROR (Status);\r
1410\r
1411 while (!IsDevicePathEnd (DevicePath)) {\r
1412 if ((DevicePath->Type == MESSAGING_DEVICE_PATH) &&\r
1413 (DevicePath->SubType == MSG_IPv4_DP)) {\r
1414\r
1415 //\r
1416 //Get handle infomation\r
1417 //\r
1418 BufferSize = 0;\r
1419 NetworkHandles = NULL;\r
1420 Status = gBS->LocateHandle (\r
1421 ByProtocol, \r
1422 &gEfiSimpleNetworkProtocolGuid,\r
1423 NULL,\r
1424 &BufferSize,\r
1425 NetworkHandles\r
1426 );\r
1427\r
1428 if (Status == EFI_BUFFER_TOO_SMALL) {\r
1429 NetworkHandles = AllocateZeroPool(BufferSize);\r
1430 if (NetworkHandles == NULL) {\r
1431 return (EFI_OUT_OF_RESOURCES);\r
1432 }\r
1433 Status = gBS->LocateHandle(\r
1434 ByProtocol,\r
1435 &gEfiSimpleNetworkProtocolGuid,\r
1436 NULL,\r
1437 &BufferSize,\r
1438 NetworkHandles\r
1439 );\r
1440 }\r
1441 \r
1442 //\r
1443 //Get the MAC string\r
1444 //\r
1445 Status = NetLibGetMacString (\r
1446 *NetworkHandles,\r
1447 NULL,\r
1448 &MacStr\r
1449 );\r
1450 if (EFI_ERROR (Status)) { \r
1451 return Status;\r
1452 }\r
1453 IPverStr = L" IPv4";\r
1454 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);\r
1455 break;\r
1456 }\r
1457 if((DevicePath->Type == MESSAGING_DEVICE_PATH) &&\r
1458 (DevicePath->SubType == MSG_IPv6_DP)) {\r
1459\r
1460 //\r
1461 //Get handle infomation\r
1462 //\r
1463 BufferSize = 0;\r
1464 NetworkHandles = NULL;\r
1465 Status = gBS->LocateHandle (\r
1466 ByProtocol, \r
1467 &gEfiSimpleNetworkProtocolGuid,\r
1468 NULL,\r
1469 &BufferSize,\r
1470 NetworkHandles\r
1471 );\r
1472\r
1473 if (Status == EFI_BUFFER_TOO_SMALL) {\r
1474 NetworkHandles = AllocateZeroPool(BufferSize);\r
1475 if (NetworkHandles == NULL) {\r
1476 return (EFI_OUT_OF_RESOURCES);\r
1477 }\r
1478 Status = gBS->LocateHandle(\r
1479 ByProtocol,\r
1480 &gEfiSimpleNetworkProtocolGuid,\r
1481 NULL,\r
1482 &BufferSize,\r
1483 NetworkHandles\r
1484 );\r
1485 }\r
1486 \r
1487 //\r
1488 //Get the MAC string\r
1489 //\r
1490 Status = NetLibGetMacString (\r
1491 *NetworkHandles,\r
1492 NULL,\r
1493 &MacStr\r
1494 );\r
1495 if (EFI_ERROR (Status)) { \r
1496 return Status;\r
1497 }\r
1498 IPverStr = L" IPv6";\r
1499 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s%s%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)),MacStr,IPverStr);\r
1500 break;\r
1501 }\r
1502 DevicePath = NextDevicePathNode (DevicePath);\r
1503 }\r
1504 \r
1505 BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);\r
1506 }\r
1507\r
1508 if (NumOfLoadFileHandles != 0) {\r
1509 FreePool (LoadFileHandles);\r
1510 }\r
1511\r
1512 //\r
1513 // Check if we have on flash shell\r
1514 //\r
1515 /* gBS->LocateHandleBuffer (\r
1516 ByProtocol,\r
1517 &gEfiFirmwareVolume2ProtocolGuid,\r
1518 NULL,\r
1519 &FvHandleCount,\r
1520 &FvHandleBuffer\r
1521 );\r
1522 for (Index = 0; Index < FvHandleCount; Index++) {\r
1523 gBS->HandleProtocol (\r
1524 FvHandleBuffer[Index],\r
1525 &gEfiFirmwareVolume2ProtocolGuid,\r
1526 (VOID **) &Fv\r
1527 );\r
1528\r
1529 Status = Fv->ReadFile (\r
1530 Fv,\r
1531 PcdGetPtr(PcdShellFile),\r
1532 NULL,\r
1533 &Size,\r
1534 &Type,\r
1535 &Attributes,\r
1536 &AuthenticationStatus\r
1537 );\r
1538 if (EFI_ERROR (Status)) {\r
1539 //\r
1540 // Skip if no shell file in the FV\r
1541 //\r
1542 continue;\r
1543 }\r
1544 //\r
1545 // Build the shell boot option\r
1546 //\r
1547 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);\r
1548 }\r
1549\r
1550 if (FvHandleCount != 0) {\r
1551 FreePool (FvHandleBuffer);\r
1552 } */\r
1553 \r
1554 //\r
1555 // Make sure every boot only have one time\r
1556 // boot device enumerate\r
1557 //\r
1558 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
1559 mEnumBootDevice = TRUE;\r
1560\r
1561 return Status;\r
1562} \r
1563\r
1564\r
1565\r
3cbfba02
DW
1566/**\r
1567\r
2e182e30 1568 The function will execute with as the platform policy, current policy\r
3cbfba02
DW
1569 is driven by boot mode. IBV/OEM can customize this code for their specific\r
1570 policy action.\r
1571\r
1572 @param DriverOptionList - The header of the driver option link list\r
1573 @param BootOptionList - The header of the boot option link list\r
1574 @param ProcessCapsules - A pointer to ProcessCapsules()\r
1575 @param BaseMemoryTest - A pointer to BaseMemoryTest()\r
1576\r
1577 @retval None.\r
1578\r
1579**/\r
1580VOID\r
1581EFIAPI\r
1582PlatformBdsPolicyBehavior (\r
1583 IN OUT LIST_ENTRY *DriverOptionList,\r
1584 IN OUT LIST_ENTRY *BootOptionList,\r
04d8d883 1585 IN PROCESS_CAPSULES BdsProcessCapsules,\r
3cbfba02
DW
1586 IN BASEM_MEMORY_TEST BaseMemoryTest\r
1587 )\r
1588{\r
1589 EFI_STATUS Status;\r
1590 UINT16 Timeout;\r
1591 EFI_BOOT_MODE BootMode;\r
1592 BOOLEAN DeferredImageExist;\r
1593 UINTN Index;\r
3cbfba02
DW
1594 SYSTEM_CONFIGURATION SystemConfiguration;\r
1595 UINTN VarSize;\r
3cbfba02
DW
1596 PLATFORM_PCI_DEVICE_PATH *EmmcBootDevPath;\r
1597 EFI_GLOBAL_NVS_AREA_PROTOCOL *GlobalNvsArea;\r
1598 EFI_HANDLE FvProtocolHandle;\r
1599 UINTN HandleCount;\r
1600 EFI_HANDLE *HandleBuffer;\r
1601 UINTN Index1;\r
1602 UINTN SataPciRegBase = 0;\r
1603 UINT16 SataModeSelect = 0;\r
1604 VOID *RegistrationExitPmAuth = NULL;\r
1605 EFI_EVENT Event;\r
1606 BOOLEAN IsFirstBoot;\r
1607 UINT16 *BootOrder;\r
1608 UINTN BootOrderSize;\r
04d8d883 1609 ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;\r
3cbfba02
DW
1610\r
1611 Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
620f2891
TH
1612 if (Timeout > 10 ) {\r
1613 //we think the Timeout variable is corrupted\r
1614 Timeout = 10;\r
1615 }\r
04d8d883 1616\r
3cbfba02
DW
1617 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
1618 Status = gRT->GetVariable(\r
1619 NORMAL_SETUP_NAME,\r
1620 &gEfiNormalSetupGuid,\r
1621 NULL,\r
1622 &VarSize,\r
1623 &SystemConfiguration\r
1624 );\r
620f2891
TH
1625\r
1626 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {\r
1627 //The setup variable is corrupted\r
1628 VarSize = sizeof(SYSTEM_CONFIGURATION);\r
1629 Status = gRT->GetVariable(\r
1630 L"SetupRecovery",\r
1631 &gEfiNormalSetupGuid,\r
1632 NULL,\r
1633 &VarSize,\r
1634 &SystemConfiguration\r
1635 );\r
1636 ASSERT_EFI_ERROR (Status);\r
04d8d883 1637 }\r
3cbfba02
DW
1638\r
1639 //\r
1640 // Load the driver option as the driver option list\r
1641 //\r
1642 PlatformBdsGetDriverOption (DriverOptionList);\r
1643\r
1644 //\r
1645 // Get current Boot Mode\r
1646 //\r
1647 BootMode = GetBootModeHob();\r
1648\r
3cbfba02
DW
1649 //\r
1650 // No deferred images exist by default\r
1651 //\r
1652 DeferredImageExist = FALSE;\r
1653 if ((BootMode != BOOT_WITH_MINIMAL_CONFIGURATION) && (PcdGet32(PcdFlashFvShellSize) > 0)){\r
1654 gDS->ProcessFirmwareVolume (\r
1655 (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),\r
1656 PcdGet32(PcdFlashFvShellSize),\r
1657 &FvProtocolHandle\r
1658 );\r
1659 }\r
1660\r
1661 if (SystemConfiguration.FastBoot == 1) {\r
1662 BootOrder = BdsLibGetVariableAndSize (\r
1663 L"BootOrder",\r
1664 &gEfiGlobalVariableGuid,\r
1665 &BootOrderSize\r
1666 );\r
1667 if ((BootOrder != NULL) && (BootMode != BOOT_ON_FLASH_UPDATE)) {\r
1668 //\r
1669 // BootOrder exist, it means system has boot before. We can do fast boot.\r
1670 //\r
1671 BootMode = BOOT_WITH_MINIMAL_CONFIGURATION;\r
1672 }\r
1673 }\r
1674\r
1675\r
1676 //\r
1677 // Use eMMC to boot OS and turn on AHCI, when SATA HDD is diconnected,\r
1678 // SATA AHCI CTLR device will show yellow bang, implement this solution to solve it.\r
1679 //\r
1680 SataPciRegBase = MmPciAddress (0, 0, PCI_DEVICE_NUMBER_PCH_SATA, 0, 0);\r
1681 SataModeSelect = MmioRead16 (SataPciRegBase + R_PCH_SATA_MAP) & B_PCH_SATA_MAP_SMS_MASK;\r
1682 Status = EFI_SUCCESS;\r
1683 if (SataModeSelect != V_PCH_SATA_MAP_SMS_IDE) {\r
1684 Status = gBS->CreateEvent (\r
1685 EVT_NOTIFY_SIGNAL,\r
1686 TPL_CALLBACK,\r
1687 DisableAhciCtlr,\r
1688 &SataPciRegBase,\r
1689 &Event\r
1690 );\r
1691 if (!EFI_ERROR (Status)) {\r
1692 Status = gBS->RegisterProtocolNotify (\r
1693 &gExitPmAuthProtocolGuid,\r
1694 Event,\r
1695 &RegistrationExitPmAuth\r
1696 );\r
1697 }\r
1698 }\r
1699\r
04d8d883
JY
1700 Status = gBS->LocateProtocol(&gEsrtManagementProtocolGuid, NULL, (VOID **)&EsrtManagement);\r
1701 if (EFI_ERROR(Status)) {\r
1702 EsrtManagement = NULL;\r
1703 }\r
1704\r
3cbfba02
DW
1705 switch (BootMode) {\r
1706\r
1707 case BOOT_WITH_MINIMAL_CONFIGURATION:\r
1708 PlatformBdsInitHotKeyEvent ();\r
1709 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole);\r
1710\r
1711\r
1712 //\r
1713 // Check to see if it's needed to dispatch more DXE drivers.\r
1714 //\r
1715 for (Index = 0; Index < sizeof(ConnectDriverTable)/sizeof(EFI_GUID *); Index++) {\r
1716 Status = gBS->LocateHandleBuffer (\r
1717 ByProtocol,\r
1718 ConnectDriverTable[Index],\r
1719 NULL,\r
1720 &HandleCount,\r
1721 &HandleBuffer\r
1722 );\r
1723 if (!EFI_ERROR (Status)) {\r
1724 for (Index1 = 0; Index1 < HandleCount; Index1++) {\r
1725 gBS->ConnectController (\r
1726 HandleBuffer[Index1],\r
1727 NULL,\r
1728 NULL,\r
1729 TRUE\r
1730 );\r
1731 }\r
1732 }\r
1733\r
1734 if (HandleBuffer != NULL) {\r
1735 FreePool (HandleBuffer);\r
1736 }\r
1737\r
1738 gDS->Dispatch ();\r
1739 }\r
1740\r
1741 //\r
1742 // Locate the Global NVS Protocol.\r
1743 //\r
1744 Status = gBS->LocateProtocol (\r
1745 &gEfiGlobalNvsAreaProtocolGuid,\r
1746 NULL,\r
1747 (void **)&GlobalNvsArea\r
1748 );\r
1749 if (GlobalNvsArea->Area->emmcVersion == 0){\r
1750 EmmcBootDevPath = (PLATFORM_PCI_DEVICE_PATH *)gPlatformSimpleBootOption[0];\r
1751 EmmcBootDevPath->PciDevice.Device = 0x10;\r
1752 }\r
1753\r
1754 //\r
1755 // Connect boot device here to give time to read keyboard.\r
1756 //\r
1757 BdsLibConnectDevicePath (gPlatformSimpleBootOption[0]);\r
1758\r
1759 //\r
1760 // This is a workround for dectecting hotkey from USB keyboard.\r
1761 //\r
1762 gBS->Stall(KEYBOARD_TIMER_INTERVAL);\r
1763\r
1764 if (mHotKeyTimerEvent != NULL) {\r
1765 gBS->SetTimer (\r
1766 mHotKeyTimerEvent,\r
1767 TimerCancel,\r
1768 0\r
1769 );\r
1770 gBS->CloseEvent (mHotKeyTimerEvent);\r
1771 mHotKeyTimerEvent = NULL;\r
1772 }\r
1773 if (mHotKeyPressed) {\r
1774 //\r
1775 // Skip show progress count down\r
1776 //\r
1777 Timeout = 0xFFFF;\r
1778 goto FULL_CONFIGURATION;\r
1779 }\r
1780\r
1781 if (SystemConfiguration.QuietBoot) {\r
1782 EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
1783 } else {\r
1784 PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);\r
1785 }\r
1786\r
1787\r
f4e7aa05
TH
1788 #ifdef TPM_ENABLED\r
1789 TcgPhysicalPresenceLibProcessRequest();\r
1790 #endif\r
1791 #ifdef FTPM_ENABLE\r
33aaf8d7 1792 Tcg2PhysicalPresenceLibProcessRequest(NULL);\r
f4e7aa05 1793 #endif\r
04d8d883
JY
1794\r
1795 if (EsrtManagement != NULL) {\r
1796 EsrtManagement->LockEsrtRepository();\r
1797 }\r
1798\r
3cbfba02
DW
1799 //\r
1800 // Close boot script and install ready to lock\r
1801 //\r
1802 InstallReadyToLock ();\r
1803\r
1804 //\r
04d8d883 1805 // Give one chance to enter the setup if we\r
3cbfba02
DW
1806 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.\r
1807 //\r
1808 BootIntoFirmwareInterface();\r
1809 break;\r
1810\r
1811 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
1812\r
1813 //\r
1814 // In no-configuration boot mode, we can connect the\r
1815 // console directly.\r
1816 //\r
1817 BdsLibConnectAllDefaultConsoles ();\r
1818 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);\r
1819\r
1820 //\r
1821 // Perform some platform specific connect sequence\r
1822 //\r
1823 PlatformBdsConnectSequence ();\r
1824\r
1825 //\r
1826 // As console is ready, perform user identification again.\r
1827 //\r
1828 if (mCurrentUser == NULL) {\r
1829 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);\r
1830 if (DeferredImageExist) {\r
1831 //\r
1832 // After user authentication, the deferred drivers was loaded again.\r
1833 // Here, need to ensure the deferred images are connected.\r
1834 //\r
1835 BdsLibConnectAllDefaultConsoles ();\r
1836 PlatformBdsConnectSequence ();\r
1837 }\r
1838 }\r
1839\r
04d8d883
JY
1840 if (EsrtManagement != NULL) {\r
1841 EsrtManagement->LockEsrtRepository();\r
1842 }\r
1843\r
3cbfba02
DW
1844 //\r
1845 // Close boot script and install ready to lock\r
1846 //\r
1847 InstallReadyToLock ();\r
1848\r
1849 //\r
1850 // Notes: current time out = 0 can not enter the\r
1851 // front page\r
1852 //\r
1853 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);\r
1854\r
1855 //\r
1856 // Check the boot option with the boot option list\r
1857 //\r
1858 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
1859 break;\r
1860\r
1861 case BOOT_ON_FLASH_UPDATE:\r
1862\r
1863 //\r
1864 // Boot with the specific configuration\r
1865 //\r
1866 PlatformBdsConnectConsole (gPlatformConsole);\r
1867 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);\r
af7bc37a 1868 EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
04d8d883 1869\r
1ed0b254 1870 DEBUG((DEBUG_INFO, "ProcessCapsules Before EndOfDxe......\n"));\r
04d8d883 1871 ProcessCapsules ();\r
1ed0b254 1872 DEBUG((DEBUG_INFO, "ProcessCapsules Done\n"));\r
04d8d883
JY
1873\r
1874 //\r
1875 // Close boot script and install ready to lock\r
1876 //\r
1877 InstallReadyToLock ();\r
1878\r
3cbfba02
DW
1879 BdsLibConnectAll ();\r
1880\r
1881 //\r
1882 // Perform user identification\r
1883 //\r
1884 if (mCurrentUser == NULL) {\r
1885 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);\r
1886 if (DeferredImageExist) {\r
1887 //\r
1888 // After user authentication, the deferred drivers was loaded again.\r
1889 // Here, need to ensure the deferred images are connected.\r
1890 //\r
1891 BdsLibConnectAll ();\r
1892 }\r
1893 }\r
1894\r
04d8d883
JY
1895 if (EsrtManagement != NULL) {\r
1896 EsrtManagement->SyncEsrtFmp();\r
1897 }\r
3cbfba02 1898\r
1ed0b254 1899 DEBUG((DEBUG_INFO, "ProcessCapsules After ConnectAll......\n"));\r
04d8d883 1900 ProcessCapsules();\r
1ed0b254 1901 DEBUG((DEBUG_INFO, "ProcessCapsules Done\n"));\r
3cbfba02
DW
1902 break;\r
1903\r
1904 case BOOT_IN_RECOVERY_MODE:\r
1905\r
1906 //\r
1907 // In recovery mode, just connect platform console\r
1908 // and show up the front page\r
1909 //\r
1910 PlatformBdsConnectConsole (gPlatformConsole);\r
1911 PlatformBdsDiagnostics (EXTENSIVE, FALSE, BaseMemoryTest);\r
1912 BdsLibConnectAll ();\r
1913\r
1914 //\r
1915 // Perform user identification\r
1916 //\r
1917 if (mCurrentUser == NULL) {\r
1918 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);\r
1919 if (DeferredImageExist) {\r
1920 //\r
1921 // After user authentication, the deferred drivers was loaded again.\r
1922 // Here, need to ensure the deferred drivers are connected.\r
1923 //\r
1924 BdsLibConnectAll ();\r
1925 }\r
1926 }\r
1927\r
1928 //\r
1929 // Close boot script and install ready to lock\r
1930 //\r
1931 InstallReadyToLock ();\r
1932\r
1933 //\r
1934 // In recovery boot mode, we still enter to the\r
1935 // frong page now\r
1936 //\r
1937 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);\r
1938 break;\r
1939\r
1940FULL_CONFIGURATION:\r
1941 case BOOT_WITH_FULL_CONFIGURATION:\r
1942 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:\r
1943 case BOOT_WITH_DEFAULT_SETTINGS:\r
1944 default:\r
1945\r
1946 //\r
1947 // Connect platform console\r
1948 //\r
1949 Status = PlatformBdsConnectConsole (gPlatformConsole);\r
1950 if (EFI_ERROR (Status)) {\r
1951\r
1952 //\r
1953 // Here OEM/IBV can customize with defined action\r
1954 //\r
1955 PlatformBdsNoConsoleAction ();\r
1956 }\r
1957\r
1958 //\r
1959 // Chenyunh[TODO]: This is Workgroud to show the fs for uSDcard,\r
1960 // Need to root cause this issue.\r
1961 //\r
1962 DEBUG ((DEBUG_ERROR, "Start to reconnect all driver.\n"));\r
1963 BdsLibDisconnectAllEfi();\r
1964 BdsLibConnectAll ();\r
1965 DEBUG ((DEBUG_ERROR, "End to reconnect all driver.\n"));\r
1966\r
1967 //\r
1968 // Perform some platform specific connect sequence\r
1969 //\r
1970 PlatformBdsConnectSequence ();\r
1971 if (SystemConfiguration.QuietBoot) {\r
1972 EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
1973 } else {\r
1974 PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);\r
1975 }\r
1976\r
1977 //\r
1978 // Do a pre-delay so Hard Disk can spin up and see more logo.\r
1979 //\r
1980 gBS->Stall(SystemConfiguration.HddPredelay * 1000000);\r
1981\r
1982 //\r
1983 // Perform user identification\r
1984 //\r
1985 if (mCurrentUser == NULL) {\r
1986 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);\r
1987 if (DeferredImageExist) {\r
1988 //\r
1989 // After user authentication, the deferred drivers was loaded again.\r
1990 // Here, need to ensure the deferred drivers are connected.\r
1991 //\r
1992 Status = PlatformBdsConnectConsole (gPlatformConsole);\r
1993 if (EFI_ERROR (Status)) {\r
1994 PlatformBdsNoConsoleAction ();\r
1995 }\r
1996 PlatformBdsConnectSequence ();\r
1997 }\r
1998 }\r
f4e7aa05 1999 #ifdef TPM_ENABLED\r
3cbfba02 2000 TcgPhysicalPresenceLibProcessRequest();\r
f4e7aa05
TH
2001 #endif\r
2002 #ifdef FTPM_ENABLE\r
33aaf8d7 2003 Tcg2PhysicalPresenceLibProcessRequest(NULL);\r
f4e7aa05 2004 #endif\r
04d8d883
JY
2005\r
2006 if (EsrtManagement != NULL) {\r
2007 EsrtManagement->SyncEsrtFmp();\r
2008 }\r
3cbfba02
DW
2009 //\r
2010 // Close boot script and install ready to lock\r
2011 //\r
2012 InstallReadyToLock ();\r
2013\r
69a99d0b
MG
2014 //\r
2015 // Here we have enough time to do the enumeration of boot device\r
2016 //\r
2017 PlatformBdsLibEnumerateAllBootOption (BootOptionList);\r
2018\r
3cbfba02
DW
2019 //\r
2020 // Give one chance to enter the setup if we\r
2021 // have the time out\r
2022 //\r
2023 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);\r
2024\r
2025 //\r
04d8d883 2026 // Give one chance to enter the setup if we\r
3cbfba02
DW
2027 // select Gummiboot "Reboot Into Firmware Interface"\r
2028 //\r
2029 BootIntoFirmwareInterface();\r
2030\r
2031 //\r
2032 // In default boot mode, always find all boot\r
2033 // option and do enumerate all the default boot option\r
2034 //\r
2035 if (Timeout == 0) {\r
2036 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
2037 if (IsListEmpty(BootOptionList)) {\r
2038 PlatformBdsPredictBootOption (BootOptionList);\r
2039 }\r
2040\r
2041 return;\r
2042 }\r
2043\r
04d8d883 2044\r
3cbfba02
DW
2045 break;\r
2046 }\r
2047\r
2048\r
2049 IsFirstBoot = PcdGetBool(PcdBootState);\r
2050 if (IsFirstBoot) {\r
2051 PcdSetBool(PcdBootState, FALSE);\r
2052 }\r
2053 return;\r
2054\r
2055}\r
2056\r
2057/**\r
2058 Hook point after a boot attempt succeeds. We don't expect a boot option to\r
2059 return, so the UEFI 2.0 specification defines that you will default to an\r
2060 interactive mode and stop processing the BootOrder list in this case. This\r
2061 is alos a platform implementation and can be customized by IBV/OEM.\r
2062\r
2063 @param Option Pointer to Boot Option that succeeded to boot.\r
2064\r
2065 @retval None.\r
2066\r
2067**/\r
2068VOID\r
2069EFIAPI\r
2070PlatformBdsBootSuccess (\r
2071 IN BDS_COMMON_OPTION *Option\r
2072 )\r
2073{\r
2074 CHAR16 *TmpStr;\r
2075\r
2076 //\r
2077 // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
2078 // select loop then we need to pop up a UI and wait for user input.\r
2079 //\r
2080 TmpStr = Option->StatusString;\r
2081 if (TmpStr != NULL) {\r
2082 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
2083 FreePool(TmpStr);\r
2084 }\r
2085}\r
2086\r
2087/**\r
2088 Hook point after a boot attempt fails.\r
2089\r
2090 @param Option - Pointer to Boot Option that failed to boot.\r
2091 @param Status - Status returned from failed boot.\r
2092 @param ExitData - Exit data returned from failed boot.\r
2093 @param ExitDataSize - Exit data size returned from failed boot.\r
2094\r
2095 @retval None.\r
2096\r
2097**/\r
2098VOID\r
2099EFIAPI\r
2100PlatformBdsBootFail (\r
2101 IN BDS_COMMON_OPTION *Option,\r
2102 IN EFI_STATUS Status,\r
2103 IN CHAR16 *ExitData,\r
2104 IN UINTN ExitDataSize\r
2105 )\r
2106{\r
2107 CHAR16 *TmpStr;\r
2108 EFI_HANDLE FvProtocolHandle;\r
2109\r
2110 //\r
2111 // If Boot returned with failed status then we need to pop up a UI and wait\r
2112 // for user input.\r
2113 //\r
2114 TmpStr = Option->StatusString;\r
2115 if (TmpStr != NULL) {\r
2116 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
2117 FreePool(TmpStr);\r
2118 }\r
2119 if (PcdGet32(PcdFlashFvShellSize) > 0){\r
2120 gDS->ProcessFirmwareVolume (\r
2121 (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),\r
2122 PcdGet32(PcdFlashFvShellSize),\r
2123 &FvProtocolHandle\r
2124 );\r
2125 }\r
2126 PlatformBdsConnectSequence ();\r
2127}\r
2128\r
2129/**\r
2130 This function is remained for IBV/OEM to do some platform action,\r
2131 if there no console device can be connected.\r
2132\r
2133 @param None.\r
2134\r
2135 @retval EFI_SUCCESS Direct return success now.\r
2136\r
2137**/\r
2138EFI_STATUS\r
2139PlatformBdsNoConsoleAction (\r
2140 VOID\r
2141 )\r
2142{\r
2143 return EFI_SUCCESS;\r
2144}\r
2145\r
2146/**\r
2147 This function locks the block\r
2148\r
2149 @param Base The base address flash region to be locked.\r
2150\r
2151**/\r
2152VOID\r
2153BdsLockFv (\r
2154 IN EFI_PHYSICAL_ADDRESS Base\r
2155 )\r
2156{\r
2157 EFI_FV_BLOCK_MAP_ENTRY *BlockMap;\r
2158 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
2159 EFI_PHYSICAL_ADDRESS BaseAddress;\r
3cbfba02
DW
2160 UINT32 BlockLength;\r
2161 UINTN Index;\r
2162\r
2163 BaseAddress = Base - 0x400000 + 2;\r
2164 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (Base));\r
2165 BlockMap = &(FvHeader->BlockMap[0]);\r
2166\r
2167 while ((BlockMap->NumBlocks != 0) && (BlockMap->Length != 0)) {\r
2168 BlockLength = BlockMap->Length;\r
2169 for (Index = 0; Index < BlockMap->NumBlocks; Index++) {\r
5fc1373d 2170 MmioOr8 ((UINTN) BaseAddress, 0x03);\r
3cbfba02
DW
2171 BaseAddress += BlockLength;\r
2172 }\r
2173 BlockMap++;\r
2174 }\r
2175}\r
2176\r
2177VOID\r
2178EFIAPI\r
2179PlatformBdsLockNonUpdatableFlash (\r
2180 VOID\r
2181 )\r
2182{\r
2183 EFI_PHYSICAL_ADDRESS Base;\r
2184\r
2185 Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvMainBase);\r
2186 if (Base > 0) {\r
2187 BdsLockFv (Base);\r
2188 }\r
2189\r
2190 Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvRecoveryBase);\r
2191 if (Base > 0) {\r
2192 BdsLockFv (Base);\r
2193 }\r
2194}\r
2195\r
2196/**\r
2197 Lock the ConsoleIn device in system table. All key\r
2198 presses will be ignored until the Password is typed in. The only way to\r
2199 disable the password is to type it in to a ConIn device.\r
2200\r
2201 @param Password Password used to lock ConIn device.\r
2202\r
2203 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.\r
2204 @retval EFI_UNSUPPORTED Password not found\r
2205\r
2206**/\r
2207EFI_STATUS\r
2208EFIAPI\r
2209LockKeyboards (\r
2210 IN CHAR16 *Password\r
2211 )\r
2212{\r
2213 return EFI_UNSUPPORTED;\r
2214}\r
2215\r
2216/**\r
2217 Connect the predefined platform default authentication devices.\r
2218\r
2219 This function connects the predefined device path for authentication device,\r
2220 and if the predefined device path has child device path, the child handle will\r
2221 be connected too. But the child handle of the child will not be connected.\r
2222\r
2223**/\r
2224VOID\r
2225EFIAPI\r
2226PlatformBdsConnectAuthDevice (\r
2227 VOID\r
2228 )\r
2229{\r
2230 EFI_STATUS Status;\r
2231 UINTN Index;\r
2232 UINTN HandleIndex;\r
2233 UINTN HandleCount;\r
2234 EFI_HANDLE *HandleBuffer;\r
2235 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
2236 EFI_USER_MANAGER_PROTOCOL *Manager;\r
2237\r
2238 Status = gBS->LocateProtocol (\r
2239 &gEfiUserManagerProtocolGuid,\r
2240 NULL,\r
2241 (VOID **) &Manager\r
2242 );\r
2243 if (EFI_ERROR (Status)) {\r
2244 //\r
2245 // As user manager protocol is not installed, the authentication devices\r
2246 // should not be connected.\r
2247 //\r
2248 return ;\r
2249 }\r
2250\r
2251 Index = 0;\r
2252 while (gUserAuthenticationDevice[Index] != NULL) {\r
2253 //\r
2254 // Connect the platform customized device paths\r
2255 //\r
2256 BdsLibConnectDevicePath (gUserAuthenticationDevice[Index]);\r
2257 Index++;\r
2258 }\r
2259\r
2260 //\r
2261 // Find and connect the child device paths of the platform customized device paths\r
2262 //\r
2263 HandleBuffer = NULL;\r
2264 for (Index = 0; gUserAuthenticationDevice[Index] != NULL; Index++) {\r
2265 HandleCount = 0;\r
2266 Status = gBS->LocateHandleBuffer (\r
2267 AllHandles,\r
2268 NULL,\r
2269 NULL,\r
2270 &HandleCount,\r
2271 &HandleBuffer\r
2272 );\r
2273 ASSERT (!EFI_ERROR (Status));\r
2274\r
2275 //\r
2276 // Find and connect the child device paths of gUserIdentificationDevice[Index]\r
2277 //\r
2278 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
2279 ChildDevicePath = NULL;\r
2280 Status = gBS->HandleProtocol (\r
2281 HandleBuffer[HandleIndex],\r
2282 &gEfiDevicePathProtocolGuid,\r
2283 (VOID **) &ChildDevicePath\r
2284 );\r
2285 if (EFI_ERROR (Status) || ChildDevicePath == NULL) {\r
2286 continue;\r
2287 }\r
2288\r
2289 if (CompareMem (\r
2290 ChildDevicePath,\r
2291 gUserAuthenticationDevice[Index],\r
2292 (GetDevicePathSize (gUserAuthenticationDevice[Index]) - sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
2293 ) != 0) {\r
2294 continue;\r
2295 }\r
2296 gBS->ConnectController (\r
2297 HandleBuffer[HandleIndex],\r
2298 NULL,\r
2299 NULL,\r
2300 TRUE\r
2301 );\r
2302 }\r
2303 }\r
2304\r
2305 if (HandleBuffer != NULL) {\r
2306 FreePool (HandleBuffer);\r
2307 }\r
2308}\r
2309\r
2310/**\r
2311 This function is to identify a user, and return whether deferred images exist.\r
2312\r
2313 @param[out] User Point to user profile handle.\r
2314 @param[out] DeferredImageExist On return, points to TRUE if the deferred image\r
2315 exist or FALSE if it did not exist.\r
2316\r
2317**/\r
2318VOID\r
2319EFIAPI\r
2320PlatformBdsUserIdentify (\r
2321 OUT EFI_USER_PROFILE_HANDLE *User,\r
2322 OUT BOOLEAN *DeferredImageExist\r
2323 )\r
2324{\r
2325 EFI_STATUS Status;\r
2326 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage;\r
2327 UINTN HandleCount;\r
2328 EFI_HANDLE *HandleBuf;\r
2329 UINTN Index;\r
2330 UINTN DriverIndex;\r
2331 EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r
2332 VOID *DriverImage;\r
2333 UINTN ImageSize;\r
2334 BOOLEAN BootOption;\r
2335\r
2336 //\r
2337 // Perform user identification\r
2338 //\r
2339 do {\r
2340 Status = BdsLibUserIdentify (User);\r
2341 } while (EFI_ERROR (Status));\r
2342\r
2343 //\r
2344 // After user authentication now, try to find whether deferred image exists\r
2345 //\r
2346 HandleCount = 0;\r
2347 HandleBuf = NULL;\r
2348 *DeferredImageExist = FALSE;\r
2349 Status = gBS->LocateHandleBuffer (\r
2350 ByProtocol,\r
2351 &gEfiDeferredImageLoadProtocolGuid,\r
2352 NULL,\r
2353 &HandleCount,\r
2354 &HandleBuf\r
2355 );\r
2356 if (EFI_ERROR (Status)) {\r
2357 return ;\r
2358 }\r
2359\r
2360 for (Index = 0; Index < HandleCount; Index++) {\r
2361 Status = gBS->HandleProtocol (\r
2362 HandleBuf[Index],\r
2363 &gEfiDeferredImageLoadProtocolGuid,\r
2364 (VOID **) &DeferredImage\r
2365 );\r
2366 if (!EFI_ERROR (Status)) {\r
2367 //\r
2368 // Find whether deferred image exists in this instance.\r
2369 //\r
2370 DriverIndex = 0;\r
2371 Status = DeferredImage->GetImageInfo(\r
2372 DeferredImage,\r
2373 DriverIndex,\r
2374 &ImageDevicePath,\r
2375 (VOID **) &DriverImage,\r
2376 &ImageSize,\r
2377 &BootOption\r
2378 );\r
2379 if (!EFI_ERROR (Status)) {\r
2380 //\r
2381 // The deferred image is found.\r
2382 //\r
2383 FreePool (HandleBuf);\r
2384 *DeferredImageExist = TRUE;\r
2385 return ;\r
2386 }\r
2387 }\r
2388 }\r
2389\r
2390 FreePool (HandleBuf);\r
2391}\r
2392\r
2393UINTN gHotKey = 0;\r
2394\r
2395\r
2396EFI_STATUS\r
2397ShowProgressHotKey (\r
2398 IN UINT16 TimeoutDefault\r
2399 )\r
2400{\r
2401 CHAR16 *TmpStr;\r
2402 UINT16 TimeoutRemain;\r
2403 EFI_STATUS Status;\r
2404 EFI_INPUT_KEY Key;\r
2405 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
2406 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
2407 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r
2408 UINT32 GpioValue;\r
1ed0b254
JY
2409 CHAR16 *TmpStr1;\r
2410 CHAR16 *TmpStr2;\r
2411 CHAR16 *TmpStr3;\r
2412 UINTN TmpStrSize;\r
2413 VOID *Buffer;\r
2414 UINTN Size;\r
3cbfba02
DW
2415\r
2416 if (TimeoutDefault == 0) {\r
2417 return EFI_TIMEOUT;\r
2418 }\r
2419\r
c7d161de
DW
2420 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
2421 \r
3cbfba02
DW
2422 if (DebugAssertEnabled())\r
2423 {\r
2424 DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it, or press <F2> or <DEL> to enter setup page! ...Zzz....\n"));\r
2425 }\r
2426 else\r
2427 { \r
2428 #ifdef __GNUC__\r
2429 SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);\r
2430 #else\r
2431 SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);\r
2432 #endif\r
2433 } \r
2434 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
2435 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
2436 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
2437\r
1ed0b254
JY
2438 TmpStr2 = NULL;\r
2439 TmpStr3 = NULL;\r
2440\r
2441 //\r
2442 // Check if the platform is using test key.\r
2443 //\r
2444 Status = GetSectionFromAnyFv(\r
2445 PcdGetPtr(PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid),\r
2446 EFI_SECTION_RAW,\r
2447 0,\r
2448 &Buffer,\r
2449 &Size\r
2450 );\r
2451 if (!EFI_ERROR(Status)) {\r
2452 if ((Size == PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer)) &&\r
2453 (CompareMem(Buffer, PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer), Size) == 0)) {\r
2454 TmpStr2 = L"WARNING: Recovery Test Key is used.\r\n";\r
2455 if (DebugAssertEnabled()) {\r
2456 DEBUG ((DEBUG_INFO, "\n\nWARNING: Recovery Test Key is used.\n"));\r
2457 } else {\r
2458 SerialPortWrite((UINT8 *)"\n\nWARNING: Recovery Test Key is used.", sizeof("\n\nWARNING: Recovery Test Key is used."));\r
2459 }\r
2460 PcdSetBoolS(PcdTestKeyUsed, TRUE);\r
2461 }\r
2462 FreePool(Buffer);\r
2463 }\r
2464 Status = GetSectionFromAnyFv(\r
2465 PcdGetPtr(PcdEdkiiPkcs7TestPublicKeyFileGuid),\r
2466 EFI_SECTION_RAW,\r
2467 0,\r
2468 &Buffer,\r
2469 &Size\r
2470 );\r
2471 if (!EFI_ERROR(Status)) {\r
2472 if ((Size == PcdGetSize(PcdPkcs7CertBuffer)) &&\r
2473 (CompareMem(Buffer, PcdGetPtr(PcdPkcs7CertBuffer), Size) == 0)) {\r
2474 TmpStr3 = L"WARNING: Capsule Test Key is used.\r\n";\r
2475 if (DebugAssertEnabled()) {\r
2476 DEBUG ((DEBUG_INFO, "\n\nWARNING: Capsule Test Key is used.\r\n"));\r
2477 } else {\r
2478 SerialPortWrite((UINT8 *)"\n\nWARNING: Capsule Test Key is used.", sizeof("\n\nWARNING: Capsule Test Key is used."));\r
2479 }\r
2480 PcdSetBoolS(PcdTestKeyUsed, TRUE);\r
2481 }\r
2482 FreePool(Buffer);\r
2483 }\r
2484\r
3cbfba02
DW
2485 //\r
2486 // Clear the progress status bar first\r
2487 //\r
1ed0b254
JY
2488 TmpStr1 = L"Start boot option, Press <F2> or <DEL> to enter setup page.\r\n";\r
2489 TmpStrSize = StrSize(TmpStr1);\r
2490 if (TmpStr2 != NULL) {\r
2491 TmpStrSize += StrSize(TmpStr2);\r
2492 }\r
2493 if (TmpStr3 != NULL) {\r
2494 TmpStrSize += StrSize(TmpStr3);\r
2495 }\r
2496 TmpStr = AllocatePool (TmpStrSize);\r
2497 if (TmpStr == NULL) {\r
2498 TmpStr = TmpStr1;\r
2499 } else {\r
2500 StrCpyS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr1);\r
2501 if (TmpStr2 != NULL) {\r
2502 StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr2);\r
2503 }\r
2504 if (TmpStr3 != NULL) {\r
2505 StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr3);\r
2506 }\r
2507 }\r
3cbfba02
DW
2508 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);\r
2509\r
2510 TimeoutRemain = TimeoutDefault;\r
2511 while (TimeoutRemain != 0) {\r
2512 if (DebugAssertEnabled())\r
2513 {\r
2514 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));\r
2515 }\r
2516 else\r
2517 { \r
2518 SerialPortWrite ((UINT8 *)".", 1);\r
2519 }\r
2520 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);\r
2521 if (Status != EFI_TIMEOUT) {\r
2522 break;\r
2523 }\r
2524 TimeoutRemain--;\r
2525\r
2526 //\r
2527 // Show progress\r
2528 //\r
2529 if (TmpStr != NULL) {\r
2530 PlatformBdsShowProgress (\r
2531 Foreground,\r
2532 Background,\r
2533 TmpStr,\r
2534 Color,\r
2535 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),\r
2536 0\r
2537 );\r
2538 }\r
2539 }\r
2540\r
2541 //\r
2542 // Timeout expired\r
2543 //\r
2544 if (TimeoutRemain == 0) {\r
2545 if (DebugAssertEnabled())\r
2546 {\r
2547 }\r
2548 else\r
2549 { \r
2550 SerialPortWrite ((UINT8 *)"\r\n", 2);\r
2551 }\r
2552 return EFI_TIMEOUT;\r
2553 }\r
2554\r
2555 //\r
2556 // User pressed some key\r
2557 //\r
2558 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
2559 if (EFI_ERROR (Status)) {\r
2560 return Status;\r
2561 }\r
2562\r
2563 //\r
2564 // Check Volume Up Key to enter Setup\r
2565 //\r
2566 GpioValue = MmioRead32 (IO_BASE_ADDRESS + 0x0668); // The value of GPIOC_5\r
2567 if (((GpioValue & BIT0) == 0) && (Key.ScanCode == SCAN_UP)) {\r
2568 gHotKey = 0;\r
2569 return EFI_SUCCESS;\r
2570 }\r
2571\r
2572 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
2573 //\r
2574 // User pressed enter, equivalent to select "continue"\r
2575 //\r
2576 return EFI_TIMEOUT;\r
2577 }\r
2578\r
2579 //\r
2580 //F2 -- Front Page\r
2581 //F5 -- Device Manager\r
2582 //F7 -- Boot Manager\r
2583 // do not use F8. generally people assume it is windows safe mode key.\r
2584 //F9 -- Boot order\r
2585 //\r
2586 DEBUG ((EFI_D_INFO, "[Key Pressed]: ScanCode 0x%x\n", Key.ScanCode));\r
2587 switch(Key.ScanCode) {\r
2588 case SCAN_F2:\r
2589 gHotKey = 0;\r
2590 break;\r
2591\r
2592 case SCAN_DELETE:\r
2593 gHotKey = 0;\r
2594 break;\r
2595\r
2596 case SCAN_F5:\r
2597 gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
2598 break;\r
2599\r
2600 case SCAN_F7:\r
2601 gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;\r
2602 break;\r
2603\r
2604 case SCAN_F9:\r
2605 gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;\r
2606 break;\r
2607\r
2608 default:\r
2609 //set gHotKey to continue so that flow will not go into CallFrontPage\r
2610 gHotKey = FRONT_PAGE_KEY_CONTINUE;\r
2611 return EFI_TIMEOUT;\r
2612 break;\r
2613 }\r
2614\r
2615 return EFI_SUCCESS;\r
2616}\r
2617\r
2618\r
2619\r
2620/**\r
2621 This function is the main entry of the platform setup entry.\r
2622 The function will present the main menu of the system setup,\r
2623 this is the platform reference part and can be customize.\r
2624\r
2625\r
2626 @param TimeoutDefault The fault time out value before the system\r
2627 continue to boot.\r
2628 @param ConnectAllHappened The indicater to check if the connect all have\r
2629 already happened.\r
2630\r
2631**/\r
2632VOID\r
2633PlatformBdsEnterFrontPageWithHotKey (\r
2634 IN UINT16 TimeoutDefault,\r
2635 IN BOOLEAN ConnectAllHappened\r
2636 )\r
2637{\r
2638 EFI_STATUS Status;\r
2639\r
af7bc37a
KM
2640 EFI_STATUS LogoStatus;\r
2641 EFI_BOOT_LOGO_PROTOCOL *BootLogo;\r
3cbfba02
DW
2642 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
2643 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
2644 UINTN BootTextColumn;\r
2645 UINTN BootTextRow;\r
2646\r
2647 GraphicsOutput = NULL;\r
2648 SimpleTextOut = NULL;\r
2649\r
2650 PERF_START (NULL, "BdsTimeOut", "BDS", 0);\r
2651\r
2652 //\r
2653 // Indicate if we need connect all in the platform setup\r
2654 //\r
2655 if (ConnectAllHappened) {\r
2656 gConnectAllHappened = TRUE;\r
2657 }\r
2658\r
2659 if (!mModeInitialized) {\r
2660 //\r
2661 // After the console is ready, get current video resolution\r
2662 // and text mode before launching setup at first time.\r
2663 //\r
2664 Status = gBS->HandleProtocol (\r
2665 gST->ConsoleOutHandle,\r
2666 &gEfiGraphicsOutputProtocolGuid,\r
2667 (VOID**)&GraphicsOutput\r
2668 );\r
2669 if (EFI_ERROR (Status)) {\r
2670 GraphicsOutput = NULL;\r
2671 }\r
2672\r
2673 Status = gBS->HandleProtocol (\r
2674 gST->ConsoleOutHandle,\r
2675 &gEfiSimpleTextOutProtocolGuid,\r
2676 (VOID**)&SimpleTextOut\r
2677 );\r
2678 if (EFI_ERROR (Status)) {\r
2679 SimpleTextOut = NULL;\r
2680 }\r
2681\r
2682 if (GraphicsOutput != NULL) {\r
2683 //\r
2684 // Get current video resolution and text mode.\r
2685 //\r
2686 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
2687 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r
2688 }\r
2689\r
2690 if (SimpleTextOut != NULL) {\r
2691 Status = SimpleTextOut->QueryMode (\r
2692 SimpleTextOut,\r
2693 SimpleTextOut->Mode->Mode,\r
2694 &BootTextColumn,\r
2695 &BootTextRow\r
2696 );\r
2697 mBootTextModeColumn = (UINT32)BootTextColumn;\r
2698 mBootTextModeRow = (UINT32)BootTextRow;\r
2699 }\r
2700\r
2701 //\r
2702 // Get user defined text mode for setup.\r
2703 //\r
2704 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);\r
2705 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);\r
2706 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);\r
2707 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);\r
2708\r
2709 mModeInitialized = TRUE;\r
2710 }\r
2711\r
2712 if (TimeoutDefault != 0xffff) {\r
2713 Status = ShowProgressHotKey (TimeoutDefault);\r
2714\r
2715 //\r
2716 // Ensure screen is clear when switch Console from Graphics mode to Text mode\r
2717 //\r
2718 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
2719 gST->ConOut->ClearScreen (gST->ConOut);\r
2720\r
af7bc37a
KM
2721 //\r
2722 // Boot Logo is corrupted, report it using Boot Logo protocol.\r
2723 //\r
2724 LogoStatus = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
2725 if (!EFI_ERROR (LogoStatus) && (BootLogo != NULL)) {\r
2726 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);\r
2727 }\r
2728\r
3cbfba02
DW
2729 if (EFI_ERROR (Status)) {\r
2730 //\r
2731 // Timeout or user press enter to continue\r
2732 //\r
2733 goto Exit;\r
2734 }\r
2735 }\r
af7bc37a 2736\r
4139580d
SL
2737 //\r
2738 // Install BM HiiPackages. \r
2739 // Keep BootMaint HiiPackage, so that it can be covered by global setting. \r
2740 //\r
2741 InitBMPackage ();\r
3cbfba02
DW
2742 do {\r
2743\r
2744 BdsSetConsoleMode (TRUE);\r
2745\r
2746 InitializeFrontPage (FALSE);\r
2747\r
2748 //\r
2749 // Update Front Page strings\r
2750 //\r
2751 UpdateFrontPageStrings ();\r
2752\r
2753 Status = EFI_SUCCESS;\r
2754 gCallbackKey = 0;\r
2755 if (gHotKey == 0) {\r
2756 Status = CallFrontPage ();\r
2757 } else {\r
2758 gCallbackKey = gHotKey;\r
2759 gHotKey = 0;\r
2760 }\r
2761\r
2762 //\r
2763 // If gCallbackKey is greater than 1 and less or equal to 5,\r
2764 // it will launch configuration utilities.\r
2765 // 2 = set language\r
2766 // 3 = boot manager\r
2767 // 4 = device manager\r
2768 // 5 = boot maintenance manager\r
2769 //\r
2770 if (gCallbackKey != 0) {\r
2771 REPORT_STATUS_CODE (\r
2772 EFI_PROGRESS_CODE,\r
2773 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)\r
2774 );\r
2775 }\r
2776\r
2777 //\r
2778 // Based on the key that was set, we can determine what to do\r
2779 //\r
2780 switch (gCallbackKey) {\r
2781 //\r
2782 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can\r
2783 // describe to their customers in documentation how to find their setup information (namely\r
2784 // under the device manager and specific buckets)\r
2785 //\r
2786 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager\r
2787 //\r
2788 case FRONT_PAGE_KEY_CONTINUE:\r
2789\r
2790 //\r
2791 // User hit continue\r
2792 //\r
2793 break;\r
2794\r
2795 case FRONT_PAGE_KEY_LANGUAGE:\r
2796\r
2797 //\r
2798 // User made a language setting change - display front page again\r
2799 //\r
2800 break;\r
2801\r
2802 case FRONT_PAGE_KEY_BOOT_MANAGER:\r
4139580d
SL
2803 //\r
2804 // Remove the installed BootMaint HiiPackages when exit.\r
2805 //\r
2806 FreeBMPackage ();\r
3cbfba02
DW
2807\r
2808 //\r
2809 // User chose to run the Boot Manager\r
2810 //\r
2811 CallBootManager ();\r
4139580d
SL
2812 \r
2813 //\r
2814 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.\r
2815 //\r
2816 InitBMPackage ();\r
3cbfba02
DW
2817 break;\r
2818\r
2819 case FRONT_PAGE_KEY_DEVICE_MANAGER:\r
2820\r
2821 //\r
2822 // Display the Device Manager\r
2823 //\r
2824 do {\r
2825 CallDeviceManager ();\r
2826 } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);\r
2827 break;\r
2828\r
2829 case FRONT_PAGE_KEY_BOOT_MAINTAIN:\r
2830\r
2831 //\r
2832 // Display the Boot Maintenance Manager\r
2833 //\r
2834 BdsStartBootMaint ();\r
2835 break;\r
2836 }\r
2837\r
2838 } while (((UINTN)gCallbackKey) != FRONT_PAGE_KEY_CONTINUE);\r
2839\r
2840 //\r
2841 //Will leave browser, check any reset required change is applied? if yes, reset system\r
2842 //\r
2843 SetupResetReminder ();\r
4139580d
SL
2844 //\r
2845 // Remove the installed BootMaint HiiPackages when exit.\r
2846 //\r
2847 FreeBMPackage ();\r
3cbfba02
DW
2848\r
2849Exit:\r
2850 //\r
2851 // Automatically load current entry\r
2852 // Note: The following lines of code only execute when Auto boot\r
2853 // takes affect\r
2854 //\r
2855 PERF_END (NULL, "BdsTimeOut", "BDS", 0);\r
2856}\r
2857\r
2858\r
2859VOID \r
2860BootIntoFirmwareInterface(\r
2861VOID\r
2862)\r
2863{\r
2864 EFI_STATUS Status;\r
2865 UINTN DataSize;\r
2866 UINT16 Timeout; \r
2867 UINT64 OsIndication;\r
2868\r
2869 \r
2870 OsIndication = 0;\r
2871 DataSize = sizeof(UINT64);\r
2872 Status = gRT->GetVariable (\r
2873 L"OsIndications",\r
2874 &gEfiGlobalVariableGuid,\r
2875 NULL,\r
2876 &DataSize,\r
2877 &OsIndication\r
2878 );\r
2879 \r
2880 DEBUG ((EFI_D_INFO, "OSIndication Variable Value %d\n", OsIndication));\r
2881 //\r
2882 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.\r
2883 // \r
2884 if (!EFI_ERROR(Status) && (OsIndication != 0)) { \r
2885 Timeout = 0xffff;\r
2886 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
2887 }\r
2888}\r
2889\r
2890\r
2891EFI_STATUS\r
2892PlatformBdsConnectSimpleConsole (\r
2893 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r
2894)\r
2895{\r
2896 EFI_STATUS Status;\r
2897 UINTN Index;\r
2898 EFI_DEVICE_PATH_PROTOCOL *VarConout;\r
2899 EFI_DEVICE_PATH_PROTOCOL *VarConin;\r
2900 UINTN DevicePathSize;\r
2901\r
2902\r
2903 Index = 0;\r
2904 Status = EFI_SUCCESS;\r
2905 DevicePathSize = 0;\r
2906 VarConout = BdsLibGetVariableAndSize (\r
2907 L"ConOut",\r
2908 &gEfiGlobalVariableGuid,\r
2909 &DevicePathSize\r
2910 );\r
2911 VarConin = BdsLibGetVariableAndSize (\r
2912 L"ConIn",\r
2913 &gEfiGlobalVariableGuid,\r
2914 &DevicePathSize\r
2915 );\r
2916 if (VarConout == NULL || VarConin == NULL) {\r
2917 //\r
2918 // Have chance to connect the platform default console,\r
2e182e30 2919 // the platform default console is the minimum device group\r
3cbfba02
DW
2920 // the platform should support\r
2921 //\r
2922 while (PlatformConsole[Index].DevicePath != NULL) {\r
2923\r
2924 //\r
2925 // Update the console variable with the connect type\r
2926 //\r
2927 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
2928 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
2929 }\r
2930\r
2931 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
2932 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
2933 }\r
2934\r
2935 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
2936 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
2937 }\r
2938\r
2939 Index ++;\r
2940 }\r
2941 }\r
2942\r
2943 //\r
2944 // Connect ConIn first to give keyboard time to parse hot key event.\r
2945 //\r
2946 Status = BdsLibConnectConsoleVariable (L"ConIn");\r
2947 if (EFI_ERROR (Status)) {\r
2948 return Status;\r
2949 }\r
2950\r
2951 //\r
2952 // Make sure we have at least one active VGA, and have the right\r
2953 // active VGA in console variable\r
2954 //\r
2955 Status = PlatformBdsForceActiveVga ();\r
2956\r
2957 //\r
2958 // It seems impossible not to have any ConOut device on platform,\r
2959 // so we check the status here.\r
2960 //\r
2961 Status = BdsLibConnectConsoleVariable (L"ConOut");\r
2962 if (EFI_ERROR (Status)) {\r
2963 return Status;\r
2964 }\r
2965\r
2966 return EFI_SUCCESS;\r
2967}\r
2968\r
2969\r
2970/**\r
2971 Timer handler to convert the key from USB.\r
2972\r
2973 @param Event Indicates the event that invoke this function.\r
2974 @param Context Indicates the calling context.\r
2975**/\r
2976VOID\r
2977EFIAPI\r
2978HotKeyTimerHandler (\r
2979 IN EFI_EVENT Event,\r
2980 IN VOID *Context\r
2981 )\r
2982{\r
2983 EFI_STATUS Status;\r
2984 EFI_INPUT_KEY Key;\r
2985\r
2986 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
2987 if (EFI_ERROR (Status)) {\r
2988 return;\r
2989 }\r
2990\r
2991 switch(Key.ScanCode) {\r
2992 case SCAN_F2:\r
2993 gHotKey = 0;\r
2994 mHotKeyPressed = TRUE;\r
2995 break;\r
2996\r
2997 case SCAN_F5:\r
2998 gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
2999 mHotKeyPressed = TRUE;\r
3000 break;\r
3001\r
3002 case SCAN_F7:\r
3003 gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;\r
3004 mHotKeyPressed = TRUE;\r
3005 break;\r
3006\r
3007 case SCAN_F9:\r
3008 gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;\r
3009 mHotKeyPressed = TRUE;\r
3010 break;\r
3011 }\r
3012\r
3013 if (mHotKeyPressed) {\r
3014 gBS->SetTimer (\r
3015 mHotKeyTimerEvent,\r
3016 TimerCancel,\r
3017 0\r
3018 );\r
3019 gBS->CloseEvent (mHotKeyTimerEvent);\r
3020 mHotKeyTimerEvent = NULL;\r
3021 }\r
3022\r
3023 return;\r
3024}\r
3025\r
3026\r
3027/**\r
3028 Callback function for SimpleTextInEx protocol install events\r
3029\r
3030 @param Event the event that is signaled.\r
3031 @param Context not used here.\r
3032\r
3033**/\r
3034VOID\r
3035EFIAPI\r
3036HitHotkeyEvent (\r
3037 IN EFI_EVENT Event,\r
3038 IN VOID *Context\r
3039 )\r
3040{\r
3041 EFI_STATUS Status;\r
3042\r
3043 Status = gBS->CloseEvent(mHitHotkeyEvent);\r
3044 if (EFI_ERROR (Status)) {\r
3045 return;\r
3046 }\r
3047 Status = gBS->CreateEvent (\r
3048 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
3049 TPL_NOTIFY,\r
3050 HotKeyTimerHandler,\r
3051 NULL,\r
3052 &mHotKeyTimerEvent\r
3053 );\r
3054 if (EFI_ERROR (Status)) {\r
3055 return;\r
3056 }\r
3057 Status = gBS->SetTimer (\r
3058 mHotKeyTimerEvent,\r
3059 TimerPeriodic,\r
3060 KEYBOARD_TIMER_INTERVAL\r
3061 );\r
3062 if (EFI_ERROR (Status)) {\r
3063 return;\r
3064 }\r
3065\r
3066 return;\r
3067}\r
3068\r
3069\r
3070VOID\r
3071EFIAPI\r
3072PlatformBdsInitHotKeyEvent (\r
3073 VOID\r
3074 )\r
3075{\r
3076 EFI_STATUS Status;\r
3077\r
3078 //\r
3079 // Register Protocol notify for Hotkey service\r
3080 //\r
3081 Status = gBS->CreateEvent (\r
3082 EVT_NOTIFY_SIGNAL,\r
3083 TPL_CALLBACK,\r
3084 HitHotkeyEvent,\r
3085 NULL,\r
3086 &mHitHotkeyEvent\r
3087 );\r
3088 ASSERT_EFI_ERROR (Status);\r
3089\r
3090 //\r
3091 // Register for protocol notifications on this event\r
3092 //\r
3093 Status = gBS->RegisterProtocolNotify (\r
3094 &gEfiSimpleTextInputExProtocolGuid,\r
3095 mHitHotkeyEvent,\r
3096 &mHitHotkeyRegistration\r
3097 );\r
3098 ASSERT_EFI_ERROR (Status);\r
3099}\r