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