]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.c
Vlv2TbltDevicePkg: Always enable QuietBoot to produce BGRT
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / PlatformBdsLib / BdsPlatform.c
CommitLineData
3cbfba02
DW
1/** @file\r
2\r
a4390a28 3 Copyright (c) 2004 - 2019, 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
927926f4 1359 &gUefiShellFileGuid,\r
69a99d0b
MG
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
927926f4 1531 &gUefiShellFileGuid,\r
69a99d0b
MG
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
a4390a28
MK
1705 DEBUG ((DEBUG_INFO, "BDS: BootMode=%02x\n", BootMode));\r
1706\r
3cbfba02
DW
1707 switch (BootMode) {\r
1708\r
1709 case BOOT_WITH_MINIMAL_CONFIGURATION:\r
1710 PlatformBdsInitHotKeyEvent ();\r
1711 PlatformBdsConnectSimpleConsole (gPlatformSimpleConsole);\r
1712\r
1713\r
1714 //\r
1715 // Check to see if it's needed to dispatch more DXE drivers.\r
1716 //\r
1717 for (Index = 0; Index < sizeof(ConnectDriverTable)/sizeof(EFI_GUID *); Index++) {\r
1718 Status = gBS->LocateHandleBuffer (\r
1719 ByProtocol,\r
1720 ConnectDriverTable[Index],\r
1721 NULL,\r
1722 &HandleCount,\r
1723 &HandleBuffer\r
1724 );\r
1725 if (!EFI_ERROR (Status)) {\r
1726 for (Index1 = 0; Index1 < HandleCount; Index1++) {\r
1727 gBS->ConnectController (\r
1728 HandleBuffer[Index1],\r
1729 NULL,\r
1730 NULL,\r
1731 TRUE\r
1732 );\r
1733 }\r
1734 }\r
1735\r
1736 if (HandleBuffer != NULL) {\r
1737 FreePool (HandleBuffer);\r
1738 }\r
1739\r
1740 gDS->Dispatch ();\r
1741 }\r
1742\r
1743 //\r
1744 // Locate the Global NVS Protocol.\r
1745 //\r
1746 Status = gBS->LocateProtocol (\r
1747 &gEfiGlobalNvsAreaProtocolGuid,\r
1748 NULL,\r
1749 (void **)&GlobalNvsArea\r
1750 );\r
1751 if (GlobalNvsArea->Area->emmcVersion == 0){\r
1752 EmmcBootDevPath = (PLATFORM_PCI_DEVICE_PATH *)gPlatformSimpleBootOption[0];\r
1753 EmmcBootDevPath->PciDevice.Device = 0x10;\r
1754 }\r
1755\r
1756 //\r
1757 // Connect boot device here to give time to read keyboard.\r
1758 //\r
1759 BdsLibConnectDevicePath (gPlatformSimpleBootOption[0]);\r
1760\r
1761 //\r
1762 // This is a workround for dectecting hotkey from USB keyboard.\r
1763 //\r
1764 gBS->Stall(KEYBOARD_TIMER_INTERVAL);\r
1765\r
1766 if (mHotKeyTimerEvent != NULL) {\r
1767 gBS->SetTimer (\r
1768 mHotKeyTimerEvent,\r
1769 TimerCancel,\r
1770 0\r
1771 );\r
1772 gBS->CloseEvent (mHotKeyTimerEvent);\r
1773 mHotKeyTimerEvent = NULL;\r
1774 }\r
1775 if (mHotKeyPressed) {\r
1776 //\r
1777 // Skip show progress count down\r
1778 //\r
1779 Timeout = 0xFFFF;\r
1780 goto FULL_CONFIGURATION;\r
1781 }\r
1782\r
a4390a28
MK
1783 EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
1784 if (!SystemConfiguration.QuietBoot) {\r
3cbfba02
DW
1785 PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);\r
1786 }\r
1787\r
1788\r
f4e7aa05
TH
1789 #ifdef TPM_ENABLED\r
1790 TcgPhysicalPresenceLibProcessRequest();\r
1791 #endif\r
1792 #ifdef FTPM_ENABLE\r
33aaf8d7 1793 Tcg2PhysicalPresenceLibProcessRequest(NULL);\r
f4e7aa05 1794 #endif\r
04d8d883
JY
1795\r
1796 if (EsrtManagement != NULL) {\r
1797 EsrtManagement->LockEsrtRepository();\r
1798 }\r
1799\r
3cbfba02
DW
1800 //\r
1801 // Close boot script and install ready to lock\r
1802 //\r
1803 InstallReadyToLock ();\r
1804\r
1805 //\r
04d8d883 1806 // Give one chance to enter the setup if we\r
3cbfba02
DW
1807 // select Gummiboot "Reboot Into Firmware Interface" and Fast Boot is enabled.\r
1808 //\r
1809 BootIntoFirmwareInterface();\r
1810 break;\r
1811\r
1812 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
1813\r
1814 //\r
1815 // In no-configuration boot mode, we can connect the\r
1816 // console directly.\r
1817 //\r
1818 BdsLibConnectAllDefaultConsoles ();\r
1819 PlatformBdsDiagnostics (IGNORE, TRUE, BaseMemoryTest);\r
1820\r
1821 //\r
1822 // Perform some platform specific connect sequence\r
1823 //\r
1824 PlatformBdsConnectSequence ();\r
1825\r
1826 //\r
1827 // As console is ready, perform user identification again.\r
1828 //\r
1829 if (mCurrentUser == NULL) {\r
1830 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);\r
1831 if (DeferredImageExist) {\r
1832 //\r
1833 // After user authentication, the deferred drivers was loaded again.\r
1834 // Here, need to ensure the deferred images are connected.\r
1835 //\r
1836 BdsLibConnectAllDefaultConsoles ();\r
1837 PlatformBdsConnectSequence ();\r
1838 }\r
1839 }\r
1840\r
04d8d883
JY
1841 if (EsrtManagement != NULL) {\r
1842 EsrtManagement->LockEsrtRepository();\r
1843 }\r
1844\r
3cbfba02
DW
1845 //\r
1846 // Close boot script and install ready to lock\r
1847 //\r
1848 InstallReadyToLock ();\r
1849\r
1850 //\r
1851 // Notes: current time out = 0 can not enter the\r
1852 // front page\r
1853 //\r
1854 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);\r
1855\r
1856 //\r
1857 // Check the boot option with the boot option list\r
1858 //\r
1859 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
1860 break;\r
1861\r
1862 case BOOT_ON_FLASH_UPDATE:\r
1863\r
1864 //\r
1865 // Boot with the specific configuration\r
1866 //\r
1867 PlatformBdsConnectConsole (gPlatformConsole);\r
a4390a28 1868 PlatformBdsDiagnostics (EXTENSIVE, TRUE, BaseMemoryTest);\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
a4390a28
MK
1971 EnableQuietBoot (PcdGetPtr(PcdLogoFile));\r
1972 if (!SystemConfiguration.QuietBoot) {\r
1973 PlatformBdsDiagnostics (IGNORE, FALSE, BaseMemoryTest);\r
3cbfba02
DW
1974 }\r
1975\r
1976 //\r
1977 // Do a pre-delay so Hard Disk can spin up and see more logo.\r
1978 //\r
1979 gBS->Stall(SystemConfiguration.HddPredelay * 1000000);\r
1980\r
1981 //\r
1982 // Perform user identification\r
1983 //\r
1984 if (mCurrentUser == NULL) {\r
1985 PlatformBdsUserIdentify (&mCurrentUser, &DeferredImageExist);\r
1986 if (DeferredImageExist) {\r
1987 //\r
1988 // After user authentication, the deferred drivers was loaded again.\r
1989 // Here, need to ensure the deferred drivers are connected.\r
1990 //\r
1991 Status = PlatformBdsConnectConsole (gPlatformConsole);\r
1992 if (EFI_ERROR (Status)) {\r
1993 PlatformBdsNoConsoleAction ();\r
1994 }\r
1995 PlatformBdsConnectSequence ();\r
1996 }\r
1997 }\r
f4e7aa05 1998 #ifdef TPM_ENABLED\r
3cbfba02 1999 TcgPhysicalPresenceLibProcessRequest();\r
f4e7aa05
TH
2000 #endif\r
2001 #ifdef FTPM_ENABLE\r
33aaf8d7 2002 Tcg2PhysicalPresenceLibProcessRequest(NULL);\r
f4e7aa05 2003 #endif\r
04d8d883
JY
2004\r
2005 if (EsrtManagement != NULL) {\r
2006 EsrtManagement->SyncEsrtFmp();\r
2007 }\r
3cbfba02
DW
2008 //\r
2009 // Close boot script and install ready to lock\r
2010 //\r
2011 InstallReadyToLock ();\r
2012\r
69a99d0b
MG
2013 //\r
2014 // Here we have enough time to do the enumeration of boot device\r
2015 //\r
2016 PlatformBdsLibEnumerateAllBootOption (BootOptionList);\r
2017\r
3cbfba02
DW
2018 //\r
2019 // Give one chance to enter the setup if we\r
2020 // have the time out\r
2021 //\r
2022 PlatformBdsEnterFrontPageWithHotKey (Timeout, FALSE);\r
2023\r
2024 //\r
04d8d883 2025 // Give one chance to enter the setup if we\r
3cbfba02
DW
2026 // select Gummiboot "Reboot Into Firmware Interface"\r
2027 //\r
2028 BootIntoFirmwareInterface();\r
2029\r
2030 //\r
2031 // In default boot mode, always find all boot\r
2032 // option and do enumerate all the default boot option\r
2033 //\r
2034 if (Timeout == 0) {\r
2035 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
2036 if (IsListEmpty(BootOptionList)) {\r
2037 PlatformBdsPredictBootOption (BootOptionList);\r
2038 }\r
2039\r
2040 return;\r
2041 }\r
2042\r
04d8d883 2043\r
3cbfba02
DW
2044 break;\r
2045 }\r
2046\r
2047\r
2048 IsFirstBoot = PcdGetBool(PcdBootState);\r
2049 if (IsFirstBoot) {\r
2050 PcdSetBool(PcdBootState, FALSE);\r
2051 }\r
2052 return;\r
2053\r
2054}\r
2055\r
2056/**\r
2057 Hook point after a boot attempt succeeds. We don't expect a boot option to\r
2058 return, so the UEFI 2.0 specification defines that you will default to an\r
2059 interactive mode and stop processing the BootOrder list in this case. This\r
2060 is alos a platform implementation and can be customized by IBV/OEM.\r
2061\r
2062 @param Option Pointer to Boot Option that succeeded to boot.\r
2063\r
2064 @retval None.\r
2065\r
2066**/\r
2067VOID\r
2068EFIAPI\r
2069PlatformBdsBootSuccess (\r
2070 IN BDS_COMMON_OPTION *Option\r
2071 )\r
2072{\r
2073 CHAR16 *TmpStr;\r
2074\r
2075 //\r
2076 // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
2077 // select loop then we need to pop up a UI and wait for user input.\r
2078 //\r
2079 TmpStr = Option->StatusString;\r
2080 if (TmpStr != NULL) {\r
2081 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
2082 FreePool(TmpStr);\r
2083 }\r
2084}\r
2085\r
2086/**\r
2087 Hook point after a boot attempt fails.\r
2088\r
2089 @param Option - Pointer to Boot Option that failed to boot.\r
2090 @param Status - Status returned from failed boot.\r
2091 @param ExitData - Exit data returned from failed boot.\r
2092 @param ExitDataSize - Exit data size returned from failed boot.\r
2093\r
2094 @retval None.\r
2095\r
2096**/\r
2097VOID\r
2098EFIAPI\r
2099PlatformBdsBootFail (\r
2100 IN BDS_COMMON_OPTION *Option,\r
2101 IN EFI_STATUS Status,\r
2102 IN CHAR16 *ExitData,\r
2103 IN UINTN ExitDataSize\r
2104 )\r
2105{\r
2106 CHAR16 *TmpStr;\r
2107 EFI_HANDLE FvProtocolHandle;\r
2108\r
2109 //\r
2110 // If Boot returned with failed status then we need to pop up a UI and wait\r
2111 // for user input.\r
2112 //\r
2113 TmpStr = Option->StatusString;\r
2114 if (TmpStr != NULL) {\r
2115 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
2116 FreePool(TmpStr);\r
2117 }\r
2118 if (PcdGet32(PcdFlashFvShellSize) > 0){\r
2119 gDS->ProcessFirmwareVolume (\r
2120 (VOID *)(UINTN)PcdGet32(PcdFlashFvShellBase),\r
2121 PcdGet32(PcdFlashFvShellSize),\r
2122 &FvProtocolHandle\r
2123 );\r
2124 }\r
2125 PlatformBdsConnectSequence ();\r
2126}\r
2127\r
2128/**\r
2129 This function is remained for IBV/OEM to do some platform action,\r
2130 if there no console device can be connected.\r
2131\r
2132 @param None.\r
2133\r
2134 @retval EFI_SUCCESS Direct return success now.\r
2135\r
2136**/\r
2137EFI_STATUS\r
2138PlatformBdsNoConsoleAction (\r
2139 VOID\r
2140 )\r
2141{\r
2142 return EFI_SUCCESS;\r
2143}\r
2144\r
2145/**\r
2146 This function locks the block\r
2147\r
2148 @param Base The base address flash region to be locked.\r
2149\r
2150**/\r
2151VOID\r
2152BdsLockFv (\r
2153 IN EFI_PHYSICAL_ADDRESS Base\r
2154 )\r
2155{\r
2156 EFI_FV_BLOCK_MAP_ENTRY *BlockMap;\r
2157 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
2158 EFI_PHYSICAL_ADDRESS BaseAddress;\r
3cbfba02
DW
2159 UINT32 BlockLength;\r
2160 UINTN Index;\r
2161\r
2162 BaseAddress = Base - 0x400000 + 2;\r
2163 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (Base));\r
2164 BlockMap = &(FvHeader->BlockMap[0]);\r
2165\r
2166 while ((BlockMap->NumBlocks != 0) && (BlockMap->Length != 0)) {\r
2167 BlockLength = BlockMap->Length;\r
2168 for (Index = 0; Index < BlockMap->NumBlocks; Index++) {\r
5fc1373d 2169 MmioOr8 ((UINTN) BaseAddress, 0x03);\r
3cbfba02
DW
2170 BaseAddress += BlockLength;\r
2171 }\r
2172 BlockMap++;\r
2173 }\r
2174}\r
2175\r
2176VOID\r
2177EFIAPI\r
2178PlatformBdsLockNonUpdatableFlash (\r
2179 VOID\r
2180 )\r
2181{\r
2182 EFI_PHYSICAL_ADDRESS Base;\r
2183\r
2184 Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvMainBase);\r
2185 if (Base > 0) {\r
2186 BdsLockFv (Base);\r
2187 }\r
2188\r
2189 Base = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashFvRecoveryBase);\r
2190 if (Base > 0) {\r
2191 BdsLockFv (Base);\r
2192 }\r
2193}\r
2194\r
2195/**\r
2196 Lock the ConsoleIn device in system table. All key\r
2197 presses will be ignored until the Password is typed in. The only way to\r
2198 disable the password is to type it in to a ConIn device.\r
2199\r
2200 @param Password Password used to lock ConIn device.\r
2201\r
2202 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.\r
2203 @retval EFI_UNSUPPORTED Password not found\r
2204\r
2205**/\r
2206EFI_STATUS\r
2207EFIAPI\r
2208LockKeyboards (\r
2209 IN CHAR16 *Password\r
2210 )\r
2211{\r
2212 return EFI_UNSUPPORTED;\r
2213}\r
2214\r
2215/**\r
2216 Connect the predefined platform default authentication devices.\r
2217\r
2218 This function connects the predefined device path for authentication device,\r
2219 and if the predefined device path has child device path, the child handle will\r
2220 be connected too. But the child handle of the child will not be connected.\r
2221\r
2222**/\r
2223VOID\r
2224EFIAPI\r
2225PlatformBdsConnectAuthDevice (\r
2226 VOID\r
2227 )\r
2228{\r
2229 EFI_STATUS Status;\r
2230 UINTN Index;\r
2231 UINTN HandleIndex;\r
2232 UINTN HandleCount;\r
2233 EFI_HANDLE *HandleBuffer;\r
2234 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
2235 EFI_USER_MANAGER_PROTOCOL *Manager;\r
2236\r
2237 Status = gBS->LocateProtocol (\r
2238 &gEfiUserManagerProtocolGuid,\r
2239 NULL,\r
2240 (VOID **) &Manager\r
2241 );\r
2242 if (EFI_ERROR (Status)) {\r
2243 //\r
2244 // As user manager protocol is not installed, the authentication devices\r
2245 // should not be connected.\r
2246 //\r
2247 return ;\r
2248 }\r
2249\r
2250 Index = 0;\r
2251 while (gUserAuthenticationDevice[Index] != NULL) {\r
2252 //\r
2253 // Connect the platform customized device paths\r
2254 //\r
2255 BdsLibConnectDevicePath (gUserAuthenticationDevice[Index]);\r
2256 Index++;\r
2257 }\r
2258\r
2259 //\r
2260 // Find and connect the child device paths of the platform customized device paths\r
2261 //\r
2262 HandleBuffer = NULL;\r
2263 for (Index = 0; gUserAuthenticationDevice[Index] != NULL; Index++) {\r
2264 HandleCount = 0;\r
2265 Status = gBS->LocateHandleBuffer (\r
2266 AllHandles,\r
2267 NULL,\r
2268 NULL,\r
2269 &HandleCount,\r
2270 &HandleBuffer\r
2271 );\r
2272 ASSERT (!EFI_ERROR (Status));\r
2273\r
2274 //\r
2275 // Find and connect the child device paths of gUserIdentificationDevice[Index]\r
2276 //\r
2277 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
2278 ChildDevicePath = NULL;\r
2279 Status = gBS->HandleProtocol (\r
2280 HandleBuffer[HandleIndex],\r
2281 &gEfiDevicePathProtocolGuid,\r
2282 (VOID **) &ChildDevicePath\r
2283 );\r
2284 if (EFI_ERROR (Status) || ChildDevicePath == NULL) {\r
2285 continue;\r
2286 }\r
2287\r
2288 if (CompareMem (\r
2289 ChildDevicePath,\r
2290 gUserAuthenticationDevice[Index],\r
2291 (GetDevicePathSize (gUserAuthenticationDevice[Index]) - sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
2292 ) != 0) {\r
2293 continue;\r
2294 }\r
2295 gBS->ConnectController (\r
2296 HandleBuffer[HandleIndex],\r
2297 NULL,\r
2298 NULL,\r
2299 TRUE\r
2300 );\r
2301 }\r
2302 }\r
2303\r
2304 if (HandleBuffer != NULL) {\r
2305 FreePool (HandleBuffer);\r
2306 }\r
2307}\r
2308\r
2309/**\r
2310 This function is to identify a user, and return whether deferred images exist.\r
2311\r
2312 @param[out] User Point to user profile handle.\r
2313 @param[out] DeferredImageExist On return, points to TRUE if the deferred image\r
2314 exist or FALSE if it did not exist.\r
2315\r
2316**/\r
2317VOID\r
2318EFIAPI\r
2319PlatformBdsUserIdentify (\r
2320 OUT EFI_USER_PROFILE_HANDLE *User,\r
2321 OUT BOOLEAN *DeferredImageExist\r
2322 )\r
2323{\r
2324 EFI_STATUS Status;\r
2325 EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage;\r
2326 UINTN HandleCount;\r
2327 EFI_HANDLE *HandleBuf;\r
2328 UINTN Index;\r
2329 UINTN DriverIndex;\r
2330 EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r
2331 VOID *DriverImage;\r
2332 UINTN ImageSize;\r
2333 BOOLEAN BootOption;\r
2334\r
2335 //\r
2336 // Perform user identification\r
2337 //\r
2338 do {\r
2339 Status = BdsLibUserIdentify (User);\r
2340 } while (EFI_ERROR (Status));\r
2341\r
2342 //\r
2343 // After user authentication now, try to find whether deferred image exists\r
2344 //\r
2345 HandleCount = 0;\r
2346 HandleBuf = NULL;\r
2347 *DeferredImageExist = FALSE;\r
2348 Status = gBS->LocateHandleBuffer (\r
2349 ByProtocol,\r
2350 &gEfiDeferredImageLoadProtocolGuid,\r
2351 NULL,\r
2352 &HandleCount,\r
2353 &HandleBuf\r
2354 );\r
2355 if (EFI_ERROR (Status)) {\r
2356 return ;\r
2357 }\r
2358\r
2359 for (Index = 0; Index < HandleCount; Index++) {\r
2360 Status = gBS->HandleProtocol (\r
2361 HandleBuf[Index],\r
2362 &gEfiDeferredImageLoadProtocolGuid,\r
2363 (VOID **) &DeferredImage\r
2364 );\r
2365 if (!EFI_ERROR (Status)) {\r
2366 //\r
2367 // Find whether deferred image exists in this instance.\r
2368 //\r
2369 DriverIndex = 0;\r
2370 Status = DeferredImage->GetImageInfo(\r
2371 DeferredImage,\r
2372 DriverIndex,\r
2373 &ImageDevicePath,\r
2374 (VOID **) &DriverImage,\r
2375 &ImageSize,\r
2376 &BootOption\r
2377 );\r
2378 if (!EFI_ERROR (Status)) {\r
2379 //\r
2380 // The deferred image is found.\r
2381 //\r
2382 FreePool (HandleBuf);\r
2383 *DeferredImageExist = TRUE;\r
2384 return ;\r
2385 }\r
2386 }\r
2387 }\r
2388\r
2389 FreePool (HandleBuf);\r
2390}\r
2391\r
2392UINTN gHotKey = 0;\r
2393\r
2394\r
2395EFI_STATUS\r
2396ShowProgressHotKey (\r
2397 IN UINT16 TimeoutDefault\r
2398 )\r
2399{\r
2400 CHAR16 *TmpStr;\r
2401 UINT16 TimeoutRemain;\r
2402 EFI_STATUS Status;\r
2403 EFI_INPUT_KEY Key;\r
2404 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
2405 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
2406 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r
2407 UINT32 GpioValue;\r
1ed0b254
JY
2408 CHAR16 *TmpStr1;\r
2409 CHAR16 *TmpStr2;\r
2410 CHAR16 *TmpStr3;\r
2411 UINTN TmpStrSize;\r
2412 VOID *Buffer;\r
2413 UINTN Size;\r
3cbfba02
DW
2414\r
2415 if (TimeoutDefault == 0) {\r
2416 return EFI_TIMEOUT;\r
2417 }\r
2418\r
c7d161de
DW
2419 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
2420 \r
3cbfba02
DW
2421 if (DebugAssertEnabled())\r
2422 {\r
2423 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
2424 }\r
2425 else\r
2426 { \r
2427 #ifdef __GNUC__\r
2428 SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)[GCC]", 76);\r
2429 #else\r
2430 SerialPortWrite((UINT8 *)"\n\n>>>>Start boot option, Press <F2> or <DEL> to enter setup page(5 Sec)", 71);\r
2431 #endif\r
2432 } \r
2433 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
2434 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
2435 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
2436\r
1ed0b254
JY
2437 TmpStr2 = NULL;\r
2438 TmpStr3 = NULL;\r
2439\r
2440 //\r
2441 // Check if the platform is using test key.\r
2442 //\r
2443 Status = GetSectionFromAnyFv(\r
2444 PcdGetPtr(PcdEdkiiRsa2048Sha256TestPublicKeyFileGuid),\r
2445 EFI_SECTION_RAW,\r
2446 0,\r
2447 &Buffer,\r
2448 &Size\r
2449 );\r
2450 if (!EFI_ERROR(Status)) {\r
2451 if ((Size == PcdGetSize(PcdRsa2048Sha256PublicKeyBuffer)) &&\r
2452 (CompareMem(Buffer, PcdGetPtr(PcdRsa2048Sha256PublicKeyBuffer), Size) == 0)) {\r
2453 TmpStr2 = L"WARNING: Recovery Test Key is used.\r\n";\r
2454 if (DebugAssertEnabled()) {\r
2455 DEBUG ((DEBUG_INFO, "\n\nWARNING: Recovery Test Key is used.\n"));\r
2456 } else {\r
2457 SerialPortWrite((UINT8 *)"\n\nWARNING: Recovery Test Key is used.", sizeof("\n\nWARNING: Recovery Test Key is used."));\r
2458 }\r
2459 PcdSetBoolS(PcdTestKeyUsed, TRUE);\r
2460 }\r
2461 FreePool(Buffer);\r
2462 }\r
2463 Status = GetSectionFromAnyFv(\r
2464 PcdGetPtr(PcdEdkiiPkcs7TestPublicKeyFileGuid),\r
2465 EFI_SECTION_RAW,\r
2466 0,\r
2467 &Buffer,\r
2468 &Size\r
2469 );\r
2470 if (!EFI_ERROR(Status)) {\r
2471 if ((Size == PcdGetSize(PcdPkcs7CertBuffer)) &&\r
2472 (CompareMem(Buffer, PcdGetPtr(PcdPkcs7CertBuffer), Size) == 0)) {\r
2473 TmpStr3 = L"WARNING: Capsule Test Key is used.\r\n";\r
2474 if (DebugAssertEnabled()) {\r
2475 DEBUG ((DEBUG_INFO, "\n\nWARNING: Capsule Test Key is used.\r\n"));\r
2476 } else {\r
2477 SerialPortWrite((UINT8 *)"\n\nWARNING: Capsule Test Key is used.", sizeof("\n\nWARNING: Capsule Test Key is used."));\r
2478 }\r
2479 PcdSetBoolS(PcdTestKeyUsed, TRUE);\r
2480 }\r
2481 FreePool(Buffer);\r
2482 }\r
2483\r
3cbfba02
DW
2484 //\r
2485 // Clear the progress status bar first\r
2486 //\r
1ed0b254
JY
2487 TmpStr1 = L"Start boot option, Press <F2> or <DEL> to enter setup page.\r\n";\r
2488 TmpStrSize = StrSize(TmpStr1);\r
2489 if (TmpStr2 != NULL) {\r
2490 TmpStrSize += StrSize(TmpStr2);\r
2491 }\r
2492 if (TmpStr3 != NULL) {\r
2493 TmpStrSize += StrSize(TmpStr3);\r
2494 }\r
2495 TmpStr = AllocatePool (TmpStrSize);\r
2496 if (TmpStr == NULL) {\r
2497 TmpStr = TmpStr1;\r
2498 } else {\r
2499 StrCpyS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr1);\r
2500 if (TmpStr2 != NULL) {\r
2501 StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr2);\r
2502 }\r
2503 if (TmpStr3 != NULL) {\r
2504 StrCatS(TmpStr, TmpStrSize/sizeof(CHAR16), TmpStr3);\r
2505 }\r
2506 }\r
3cbfba02
DW
2507 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);\r
2508\r
2509 TimeoutRemain = TimeoutDefault;\r
2510 while (TimeoutRemain != 0) {\r
2511 if (DebugAssertEnabled())\r
2512 {\r
2513 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));\r
2514 }\r
2515 else\r
2516 { \r
2517 SerialPortWrite ((UINT8 *)".", 1);\r
2518 }\r
2519 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);\r
2520 if (Status != EFI_TIMEOUT) {\r
2521 break;\r
2522 }\r
2523 TimeoutRemain--;\r
2524\r
2525 //\r
2526 // Show progress\r
2527 //\r
2528 if (TmpStr != NULL) {\r
2529 PlatformBdsShowProgress (\r
2530 Foreground,\r
2531 Background,\r
2532 TmpStr,\r
2533 Color,\r
2534 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),\r
2535 0\r
2536 );\r
2537 }\r
2538 }\r
2539\r
2540 //\r
2541 // Timeout expired\r
2542 //\r
2543 if (TimeoutRemain == 0) {\r
2544 if (DebugAssertEnabled())\r
2545 {\r
2546 }\r
2547 else\r
2548 { \r
2549 SerialPortWrite ((UINT8 *)"\r\n", 2);\r
2550 }\r
2551 return EFI_TIMEOUT;\r
2552 }\r
2553\r
2554 //\r
2555 // User pressed some key\r
2556 //\r
2557 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
2558 if (EFI_ERROR (Status)) {\r
2559 return Status;\r
2560 }\r
2561\r
2562 //\r
2563 // Check Volume Up Key to enter Setup\r
2564 //\r
2565 GpioValue = MmioRead32 (IO_BASE_ADDRESS + 0x0668); // The value of GPIOC_5\r
2566 if (((GpioValue & BIT0) == 0) && (Key.ScanCode == SCAN_UP)) {\r
2567 gHotKey = 0;\r
2568 return EFI_SUCCESS;\r
2569 }\r
2570\r
2571 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
2572 //\r
2573 // User pressed enter, equivalent to select "continue"\r
2574 //\r
2575 return EFI_TIMEOUT;\r
2576 }\r
2577\r
2578 //\r
2579 //F2 -- Front Page\r
2580 //F5 -- Device Manager\r
2581 //F7 -- Boot Manager\r
2582 // do not use F8. generally people assume it is windows safe mode key.\r
2583 //F9 -- Boot order\r
2584 //\r
2585 DEBUG ((EFI_D_INFO, "[Key Pressed]: ScanCode 0x%x\n", Key.ScanCode));\r
2586 switch(Key.ScanCode) {\r
2587 case SCAN_F2:\r
2588 gHotKey = 0;\r
2589 break;\r
2590\r
2591 case SCAN_DELETE:\r
2592 gHotKey = 0;\r
2593 break;\r
2594\r
2595 case SCAN_F5:\r
2596 gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
2597 break;\r
2598\r
2599 case SCAN_F7:\r
2600 gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;\r
2601 break;\r
2602\r
2603 case SCAN_F9:\r
2604 gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;\r
2605 break;\r
2606\r
2607 default:\r
2608 //set gHotKey to continue so that flow will not go into CallFrontPage\r
2609 gHotKey = FRONT_PAGE_KEY_CONTINUE;\r
2610 return EFI_TIMEOUT;\r
2611 break;\r
2612 }\r
2613\r
2614 return EFI_SUCCESS;\r
2615}\r
2616\r
2617\r
2618\r
2619/**\r
2620 This function is the main entry of the platform setup entry.\r
2621 The function will present the main menu of the system setup,\r
2622 this is the platform reference part and can be customize.\r
2623\r
2624\r
2625 @param TimeoutDefault The fault time out value before the system\r
2626 continue to boot.\r
2627 @param ConnectAllHappened The indicater to check if the connect all have\r
2628 already happened.\r
2629\r
2630**/\r
2631VOID\r
2632PlatformBdsEnterFrontPageWithHotKey (\r
2633 IN UINT16 TimeoutDefault,\r
2634 IN BOOLEAN ConnectAllHappened\r
2635 )\r
2636{\r
2637 EFI_STATUS Status;\r
2638\r
af7bc37a
KM
2639 EFI_STATUS LogoStatus;\r
2640 EFI_BOOT_LOGO_PROTOCOL *BootLogo;\r
3cbfba02
DW
2641 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
2642 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
2643 UINTN BootTextColumn;\r
2644 UINTN BootTextRow;\r
2645\r
2646 GraphicsOutput = NULL;\r
2647 SimpleTextOut = NULL;\r
2648\r
2649 PERF_START (NULL, "BdsTimeOut", "BDS", 0);\r
2650\r
2651 //\r
2652 // Indicate if we need connect all in the platform setup\r
2653 //\r
2654 if (ConnectAllHappened) {\r
2655 gConnectAllHappened = TRUE;\r
2656 }\r
2657\r
2658 if (!mModeInitialized) {\r
2659 //\r
2660 // After the console is ready, get current video resolution\r
2661 // and text mode before launching setup at first time.\r
2662 //\r
2663 Status = gBS->HandleProtocol (\r
2664 gST->ConsoleOutHandle,\r
2665 &gEfiGraphicsOutputProtocolGuid,\r
2666 (VOID**)&GraphicsOutput\r
2667 );\r
2668 if (EFI_ERROR (Status)) {\r
2669 GraphicsOutput = NULL;\r
2670 }\r
2671\r
2672 Status = gBS->HandleProtocol (\r
2673 gST->ConsoleOutHandle,\r
2674 &gEfiSimpleTextOutProtocolGuid,\r
2675 (VOID**)&SimpleTextOut\r
2676 );\r
2677 if (EFI_ERROR (Status)) {\r
2678 SimpleTextOut = NULL;\r
2679 }\r
2680\r
2681 if (GraphicsOutput != NULL) {\r
2682 //\r
2683 // Get current video resolution and text mode.\r
2684 //\r
2685 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
2686 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r
2687 }\r
2688\r
2689 if (SimpleTextOut != NULL) {\r
2690 Status = SimpleTextOut->QueryMode (\r
2691 SimpleTextOut,\r
2692 SimpleTextOut->Mode->Mode,\r
2693 &BootTextColumn,\r
2694 &BootTextRow\r
2695 );\r
2696 mBootTextModeColumn = (UINT32)BootTextColumn;\r
2697 mBootTextModeRow = (UINT32)BootTextRow;\r
2698 }\r
2699\r
2700 //\r
2701 // Get user defined text mode for setup.\r
2702 //\r
2703 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);\r
2704 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);\r
2705 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);\r
2706 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);\r
2707\r
2708 mModeInitialized = TRUE;\r
2709 }\r
2710\r
2711 if (TimeoutDefault != 0xffff) {\r
2712 Status = ShowProgressHotKey (TimeoutDefault);\r
2713\r
2714 //\r
2715 // Ensure screen is clear when switch Console from Graphics mode to Text mode\r
2716 //\r
2717 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
2718 gST->ConOut->ClearScreen (gST->ConOut);\r
2719\r
af7bc37a
KM
2720 //\r
2721 // Boot Logo is corrupted, report it using Boot Logo protocol.\r
2722 //\r
2723 LogoStatus = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
2724 if (!EFI_ERROR (LogoStatus) && (BootLogo != NULL)) {\r
2725 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);\r
2726 }\r
2727\r
3cbfba02
DW
2728 if (EFI_ERROR (Status)) {\r
2729 //\r
2730 // Timeout or user press enter to continue\r
2731 //\r
2732 goto Exit;\r
2733 }\r
2734 }\r
af7bc37a 2735\r
4139580d
SL
2736 //\r
2737 // Install BM HiiPackages. \r
2738 // Keep BootMaint HiiPackage, so that it can be covered by global setting. \r
2739 //\r
2740 InitBMPackage ();\r
3cbfba02
DW
2741 do {\r
2742\r
2743 BdsSetConsoleMode (TRUE);\r
2744\r
2745 InitializeFrontPage (FALSE);\r
2746\r
2747 //\r
2748 // Update Front Page strings\r
2749 //\r
2750 UpdateFrontPageStrings ();\r
2751\r
2752 Status = EFI_SUCCESS;\r
2753 gCallbackKey = 0;\r
2754 if (gHotKey == 0) {\r
2755 Status = CallFrontPage ();\r
2756 } else {\r
2757 gCallbackKey = gHotKey;\r
2758 gHotKey = 0;\r
2759 }\r
2760\r
2761 //\r
2762 // If gCallbackKey is greater than 1 and less or equal to 5,\r
2763 // it will launch configuration utilities.\r
2764 // 2 = set language\r
2765 // 3 = boot manager\r
2766 // 4 = device manager\r
2767 // 5 = boot maintenance manager\r
2768 //\r
2769 if (gCallbackKey != 0) {\r
2770 REPORT_STATUS_CODE (\r
2771 EFI_PROGRESS_CODE,\r
2772 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)\r
2773 );\r
2774 }\r
2775\r
2776 //\r
2777 // Based on the key that was set, we can determine what to do\r
2778 //\r
2779 switch (gCallbackKey) {\r
2780 //\r
2781 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can\r
2782 // describe to their customers in documentation how to find their setup information (namely\r
2783 // under the device manager and specific buckets)\r
2784 //\r
2785 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager\r
2786 //\r
2787 case FRONT_PAGE_KEY_CONTINUE:\r
2788\r
2789 //\r
2790 // User hit continue\r
2791 //\r
2792 break;\r
2793\r
2794 case FRONT_PAGE_KEY_LANGUAGE:\r
2795\r
2796 //\r
2797 // User made a language setting change - display front page again\r
2798 //\r
2799 break;\r
2800\r
2801 case FRONT_PAGE_KEY_BOOT_MANAGER:\r
4139580d
SL
2802 //\r
2803 // Remove the installed BootMaint HiiPackages when exit.\r
2804 //\r
2805 FreeBMPackage ();\r
3cbfba02
DW
2806\r
2807 //\r
2808 // User chose to run the Boot Manager\r
2809 //\r
2810 CallBootManager ();\r
4139580d
SL
2811 \r
2812 //\r
2813 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.\r
2814 //\r
2815 InitBMPackage ();\r
3cbfba02
DW
2816 break;\r
2817\r
2818 case FRONT_PAGE_KEY_DEVICE_MANAGER:\r
2819\r
2820 //\r
2821 // Display the Device Manager\r
2822 //\r
2823 do {\r
2824 CallDeviceManager ();\r
2825 } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);\r
2826 break;\r
2827\r
2828 case FRONT_PAGE_KEY_BOOT_MAINTAIN:\r
2829\r
2830 //\r
2831 // Display the Boot Maintenance Manager\r
2832 //\r
2833 BdsStartBootMaint ();\r
2834 break;\r
2835 }\r
2836\r
2837 } while (((UINTN)gCallbackKey) != FRONT_PAGE_KEY_CONTINUE);\r
2838\r
2839 //\r
2840 //Will leave browser, check any reset required change is applied? if yes, reset system\r
2841 //\r
2842 SetupResetReminder ();\r
4139580d
SL
2843 //\r
2844 // Remove the installed BootMaint HiiPackages when exit.\r
2845 //\r
2846 FreeBMPackage ();\r
3cbfba02
DW
2847\r
2848Exit:\r
2849 //\r
2850 // Automatically load current entry\r
2851 // Note: The following lines of code only execute when Auto boot\r
2852 // takes affect\r
2853 //\r
2854 PERF_END (NULL, "BdsTimeOut", "BDS", 0);\r
2855}\r
2856\r
2857\r
2858VOID \r
2859BootIntoFirmwareInterface(\r
2860VOID\r
2861)\r
2862{\r
2863 EFI_STATUS Status;\r
2864 UINTN DataSize;\r
2865 UINT16 Timeout; \r
2866 UINT64 OsIndication;\r
2867\r
2868 \r
2869 OsIndication = 0;\r
2870 DataSize = sizeof(UINT64);\r
2871 Status = gRT->GetVariable (\r
2872 L"OsIndications",\r
2873 &gEfiGlobalVariableGuid,\r
2874 NULL,\r
2875 &DataSize,\r
2876 &OsIndication\r
2877 );\r
2878 \r
2879 DEBUG ((EFI_D_INFO, "OSIndication Variable Value %d\n", OsIndication));\r
2880 //\r
2881 //Goto FrontPage directly when bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI in OSIndication Variable is setted.\r
2882 // \r
2883 if (!EFI_ERROR(Status) && (OsIndication != 0)) { \r
2884 Timeout = 0xffff;\r
2885 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
2886 }\r
2887}\r
2888\r
2889\r
2890EFI_STATUS\r
2891PlatformBdsConnectSimpleConsole (\r
2892 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r
2893)\r
2894{\r
2895 EFI_STATUS Status;\r
2896 UINTN Index;\r
2897 EFI_DEVICE_PATH_PROTOCOL *VarConout;\r
2898 EFI_DEVICE_PATH_PROTOCOL *VarConin;\r
2899 UINTN DevicePathSize;\r
2900\r
2901\r
2902 Index = 0;\r
2903 Status = EFI_SUCCESS;\r
2904 DevicePathSize = 0;\r
2905 VarConout = BdsLibGetVariableAndSize (\r
2906 L"ConOut",\r
2907 &gEfiGlobalVariableGuid,\r
2908 &DevicePathSize\r
2909 );\r
2910 VarConin = BdsLibGetVariableAndSize (\r
2911 L"ConIn",\r
2912 &gEfiGlobalVariableGuid,\r
2913 &DevicePathSize\r
2914 );\r
2915 if (VarConout == NULL || VarConin == NULL) {\r
2916 //\r
2917 // Have chance to connect the platform default console,\r
2e182e30 2918 // the platform default console is the minimum device group\r
3cbfba02
DW
2919 // the platform should support\r
2920 //\r
2921 while (PlatformConsole[Index].DevicePath != NULL) {\r
2922\r
2923 //\r
2924 // Update the console variable with the connect type\r
2925 //\r
2926 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
2927 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
2928 }\r
2929\r
2930 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
2931 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
2932 }\r
2933\r
2934 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
2935 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
2936 }\r
2937\r
2938 Index ++;\r
2939 }\r
2940 }\r
2941\r
2942 //\r
2943 // Connect ConIn first to give keyboard time to parse hot key event.\r
2944 //\r
2945 Status = BdsLibConnectConsoleVariable (L"ConIn");\r
2946 if (EFI_ERROR (Status)) {\r
2947 return Status;\r
2948 }\r
2949\r
2950 //\r
2951 // Make sure we have at least one active VGA, and have the right\r
2952 // active VGA in console variable\r
2953 //\r
2954 Status = PlatformBdsForceActiveVga ();\r
2955\r
2956 //\r
2957 // It seems impossible not to have any ConOut device on platform,\r
2958 // so we check the status here.\r
2959 //\r
2960 Status = BdsLibConnectConsoleVariable (L"ConOut");\r
2961 if (EFI_ERROR (Status)) {\r
2962 return Status;\r
2963 }\r
2964\r
2965 return EFI_SUCCESS;\r
2966}\r
2967\r
2968\r
2969/**\r
2970 Timer handler to convert the key from USB.\r
2971\r
2972 @param Event Indicates the event that invoke this function.\r
2973 @param Context Indicates the calling context.\r
2974**/\r
2975VOID\r
2976EFIAPI\r
2977HotKeyTimerHandler (\r
2978 IN EFI_EVENT Event,\r
2979 IN VOID *Context\r
2980 )\r
2981{\r
2982 EFI_STATUS Status;\r
2983 EFI_INPUT_KEY Key;\r
2984\r
2985 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
2986 if (EFI_ERROR (Status)) {\r
2987 return;\r
2988 }\r
2989\r
2990 switch(Key.ScanCode) {\r
2991 case SCAN_F2:\r
2992 gHotKey = 0;\r
2993 mHotKeyPressed = TRUE;\r
2994 break;\r
2995\r
2996 case SCAN_F5:\r
2997 gHotKey = FRONT_PAGE_KEY_DEVICE_MANAGER;\r
2998 mHotKeyPressed = TRUE;\r
2999 break;\r
3000\r
3001 case SCAN_F7:\r
3002 gHotKey = FRONT_PAGE_KEY_BOOT_MANAGER;\r
3003 mHotKeyPressed = TRUE;\r
3004 break;\r
3005\r
3006 case SCAN_F9:\r
3007 gHotKey = FRONT_PAGE_KEY_BOOT_MAINTAIN;\r
3008 mHotKeyPressed = TRUE;\r
3009 break;\r
3010 }\r
3011\r
3012 if (mHotKeyPressed) {\r
3013 gBS->SetTimer (\r
3014 mHotKeyTimerEvent,\r
3015 TimerCancel,\r
3016 0\r
3017 );\r
3018 gBS->CloseEvent (mHotKeyTimerEvent);\r
3019 mHotKeyTimerEvent = NULL;\r
3020 }\r
3021\r
3022 return;\r
3023}\r
3024\r
3025\r
3026/**\r
3027 Callback function for SimpleTextInEx protocol install events\r
3028\r
3029 @param Event the event that is signaled.\r
3030 @param Context not used here.\r
3031\r
3032**/\r
3033VOID\r
3034EFIAPI\r
3035HitHotkeyEvent (\r
3036 IN EFI_EVENT Event,\r
3037 IN VOID *Context\r
3038 )\r
3039{\r
3040 EFI_STATUS Status;\r
3041\r
3042 Status = gBS->CloseEvent(mHitHotkeyEvent);\r
3043 if (EFI_ERROR (Status)) {\r
3044 return;\r
3045 }\r
3046 Status = gBS->CreateEvent (\r
3047 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
3048 TPL_NOTIFY,\r
3049 HotKeyTimerHandler,\r
3050 NULL,\r
3051 &mHotKeyTimerEvent\r
3052 );\r
3053 if (EFI_ERROR (Status)) {\r
3054 return;\r
3055 }\r
3056 Status = gBS->SetTimer (\r
3057 mHotKeyTimerEvent,\r
3058 TimerPeriodic,\r
3059 KEYBOARD_TIMER_INTERVAL\r
3060 );\r
3061 if (EFI_ERROR (Status)) {\r
3062 return;\r
3063 }\r
3064\r
3065 return;\r
3066}\r
3067\r
3068\r
3069VOID\r
3070EFIAPI\r
3071PlatformBdsInitHotKeyEvent (\r
3072 VOID\r
3073 )\r
3074{\r
3075 EFI_STATUS Status;\r
3076\r
3077 //\r
3078 // Register Protocol notify for Hotkey service\r
3079 //\r
3080 Status = gBS->CreateEvent (\r
3081 EVT_NOTIFY_SIGNAL,\r
3082 TPL_CALLBACK,\r
3083 HitHotkeyEvent,\r
3084 NULL,\r
3085 &mHitHotkeyEvent\r
3086 );\r
3087 ASSERT_EFI_ERROR (Status);\r
3088\r
3089 //\r
3090 // Register for protocol notifications on this event\r
3091 //\r
3092 Status = gBS->RegisterProtocolNotify (\r
3093 &gEfiSimpleTextInputExProtocolGuid,\r
3094 mHitHotkeyEvent,\r
3095 &mHitHotkeyRegistration\r
3096 );\r
3097 ASSERT_EFI_ERROR (Status);\r
3098}\r