BoardBdsHookLib.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /** @file
  2. This library registers Bds callbacks. It is a default library
  3. implementation instance of the BDS hook library
  4. Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Guid/EventGroup.h>
  8. #include <Library/IoLib.h>
  9. #include <Library/PciLib.h>
  10. #include <Library/UefiBootManagerLib.h>
  11. #include <Library/Tcg2PhysicalPresenceLib.h>
  12. #include <Protocol/BlockIo.h>
  13. #include <Protocol/UsbIo.h>
  14. #include <Protocol/PciEnumerationComplete.h>
  15. #include "BoardBdsHook.h"
  16. GLOBAL_REMOVE_IF_UNREFERENCED EFI_BOOT_MODE gBootMode;
  17. BOOLEAN gPPRequireUIConfirm;
  18. extern UINTN mBootMenuOptionNumber;
  19. GLOBAL_REMOVE_IF_UNREFERENCED USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath = {
  20. {
  21. {
  22. MESSAGING_DEVICE_PATH,
  23. MSG_USB_CLASS_DP,
  24. {
  25. (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)),
  26. (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8)
  27. }
  28. },
  29. 0xffff, // VendorId
  30. 0xffff, // ProductId
  31. CLASS_HID, // DeviceClass
  32. SUBCLASS_BOOT, // DeviceSubClass
  33. PROTOCOL_KEYBOARD // DeviceProtocol
  34. },
  35. gEndEntire
  36. };
  37. //
  38. // BDS Platform Functions
  39. //
  40. BOOLEAN
  41. IsMorBitSet (
  42. VOID
  43. )
  44. {
  45. UINTN MorControl;
  46. EFI_STATUS Status;
  47. UINTN DataSize;
  48. //
  49. // Check if the MOR bit is set.
  50. //
  51. DataSize = sizeof (MorControl);
  52. Status = gRT->GetVariable (
  53. MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
  54. &gEfiMemoryOverwriteControlDataGuid,
  55. NULL,
  56. &DataSize,
  57. &MorControl
  58. );
  59. if (EFI_ERROR (Status)) {
  60. DEBUG ((DEBUG_INFO, " gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));
  61. MorControl = 0;
  62. } else {
  63. DEBUG ((DEBUG_INFO, " Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", MorControl));
  64. }
  65. return (BOOLEAN) (MorControl & 0x01);
  66. }
  67. /**
  68. Prints device paths.
  69. @param Name The device name.
  70. @param DevicePath The device path to be printed
  71. **/
  72. VOID
  73. EFIAPI
  74. DumpDevicePath (
  75. IN CHAR16 *Name,
  76. IN EFI_DEVICE_PATH *DevicePath
  77. )
  78. {
  79. CHAR16 *Str;
  80. Str = ConvertDevicePathToText (DevicePath, TRUE, TRUE);
  81. DEBUG ((DEBUG_INFO, "%s: %s\n", Name, Str));
  82. if (Str != NULL) {
  83. FreePool (Str);
  84. }
  85. }
  86. /**
  87. Return whether the device is trusted console.
  88. @param Device The device to be tested.
  89. @retval TRUE The device can be trusted.
  90. @retval FALSE The device cannot be trusted.
  91. **/
  92. BOOLEAN
  93. IsTrustedConsole (
  94. IN CONSOLE_TYPE ConsoleType,
  95. IN EFI_DEVICE_PATH_PROTOCOL *Device
  96. )
  97. {
  98. VOID *TrustedConsoleDevicepath;
  99. EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
  100. EFI_DEVICE_PATH_PROTOCOL *Instance;
  101. UINTN Size;
  102. EFI_DEVICE_PATH_PROTOCOL *ConsoleDevice;
  103. if (Device == NULL) {
  104. return FALSE;
  105. }
  106. ConsoleDevice = DuplicateDevicePath (Device);
  107. TrustedConsoleDevicepath = NULL;
  108. switch (ConsoleType) {
  109. case ConIn:
  110. TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleInputDevicePath);
  111. break;
  112. case ConOut:
  113. //
  114. // Check GOP and remove last node
  115. //
  116. TempDevicePath = ConsoleDevice;
  117. while (!IsDevicePathEndType (TempDevicePath)) {
  118. if (DevicePathType (TempDevicePath) == ACPI_DEVICE_PATH &&
  119. DevicePathSubType (TempDevicePath) == ACPI_ADR_DP) {
  120. SetDevicePathEndNode (TempDevicePath);
  121. break;
  122. }
  123. TempDevicePath = NextDevicePathNode (TempDevicePath);
  124. }
  125. TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleOutputDevicePath);
  126. break;
  127. default:
  128. ASSERT (FALSE);
  129. break;
  130. }
  131. TempDevicePath = TrustedConsoleDevicepath;
  132. do {
  133. Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
  134. if (Instance == NULL) {
  135. break;
  136. }
  137. if (CompareMem (ConsoleDevice, Instance, Size - END_DEVICE_PATH_LENGTH) == 0) {
  138. FreePool (Instance);
  139. FreePool (ConsoleDevice);
  140. return TRUE;
  141. }
  142. FreePool (Instance);
  143. } while (TempDevicePath != NULL);
  144. FreePool (ConsoleDevice);
  145. return FALSE;
  146. }
  147. /**
  148. Return whether the USB device path is in a short form.
  149. @param DevicePath The device path to be tested.
  150. @retval TRUE The device path is in short form.
  151. @retval FALSE The device path is not in short form.
  152. **/
  153. BOOLEAN
  154. IsUsbShortForm (
  155. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
  156. )
  157. {
  158. if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
  159. ((DevicePathSubType (DevicePath) == MSG_USB_CLASS_DP) ||
  160. (DevicePathSubType (DevicePath) == MSG_USB_WWID_DP)) ) {
  161. return TRUE;
  162. }
  163. return FALSE;
  164. }
  165. /**
  166. Connect the USB short form device path.
  167. @param DevicePath USB short form device path
  168. @retval EFI_SUCCESS Successfully connected the USB device
  169. @retval EFI_NOT_FOUND Cannot connect the USB device
  170. @retval EFI_INVALID_PARAMETER The device path is invalid.
  171. **/
  172. EFI_STATUS
  173. ConnectUsbShortFormDevicePath (
  174. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
  175. )
  176. {
  177. EFI_STATUS Status;
  178. EFI_HANDLE *Handles;
  179. UINTN HandleCount;
  180. UINTN Index;
  181. EFI_PCI_IO_PROTOCOL *PciIo;
  182. UINT8 Class[3];
  183. BOOLEAN AtLeastOneConnected;
  184. //
  185. // Check the passed in parameters
  186. //
  187. if (DevicePath == NULL) {
  188. return EFI_INVALID_PARAMETER;
  189. }
  190. if (!IsUsbShortForm (DevicePath)) {
  191. return EFI_INVALID_PARAMETER;
  192. }
  193. //
  194. // Find the usb host controller firstly, then connect with the remaining device path
  195. //
  196. AtLeastOneConnected = FALSE;
  197. Status = gBS->LocateHandleBuffer (
  198. ByProtocol,
  199. &gEfiPciIoProtocolGuid,
  200. NULL,
  201. &HandleCount,
  202. &Handles
  203. );
  204. for (Index = 0; Index < HandleCount; Index++) {
  205. Status = gBS->HandleProtocol (
  206. Handles[Index],
  207. &gEfiPciIoProtocolGuid,
  208. (VOID **) &PciIo
  209. );
  210. if (!EFI_ERROR (Status)) {
  211. //
  212. // Check whether the Pci device is the wanted usb host controller
  213. //
  214. Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
  215. if (!EFI_ERROR (Status) &&
  216. ((PCI_CLASS_SERIAL == Class[2]) && (PCI_CLASS_SERIAL_USB == Class[1]))) {
  217. Status = gBS->ConnectController (
  218. Handles[Index],
  219. NULL,
  220. DevicePath,
  221. FALSE
  222. );
  223. if (!EFI_ERROR(Status)) {
  224. AtLeastOneConnected = TRUE;
  225. }
  226. }
  227. }
  228. }
  229. return AtLeastOneConnected ? EFI_SUCCESS : EFI_NOT_FOUND;
  230. }
  231. /**
  232. Return whether the Handle is a vga handle.
  233. @param Handle The handle to be tested.
  234. @retval TRUE The handle is a vga handle.
  235. @retval FALSE The handle is not a vga handle..
  236. **/
  237. BOOLEAN
  238. IsVgaHandle (
  239. IN EFI_HANDLE Handle
  240. )
  241. {
  242. EFI_PCI_IO_PROTOCOL *PciIo;
  243. PCI_TYPE00 Pci;
  244. EFI_STATUS Status;
  245. Status = gBS->HandleProtocol (
  246. Handle,
  247. &gEfiPciIoProtocolGuid,
  248. (VOID **)&PciIo
  249. );
  250. if (!EFI_ERROR (Status)) {
  251. Status = PciIo->Pci.Read (
  252. PciIo,
  253. EfiPciIoWidthUint32,
  254. 0,
  255. sizeof (Pci) / sizeof (UINT32),
  256. &Pci
  257. );
  258. if (!EFI_ERROR (Status)) {
  259. if (IS_PCI_VGA (&Pci) || IS_PCI_OLD_VGA (&Pci)) {
  260. return TRUE;
  261. }
  262. }
  263. }
  264. return FALSE;
  265. }
  266. /**
  267. Return whether the device path points to a video controller.
  268. @param DevicePath The device path to be tested.
  269. @retval TRUE The device path points to a video controller.
  270. @retval FALSE The device path does not point to a video controller.
  271. **/
  272. EFI_HANDLE
  273. IsVideoController (
  274. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
  275. )
  276. {
  277. EFI_DEVICE_PATH_PROTOCOL *DupDevicePath;
  278. EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
  279. EFI_STATUS Status;
  280. EFI_HANDLE DeviceHandle;
  281. DupDevicePath = DuplicateDevicePath (DevicePath);
  282. ASSERT (DupDevicePath != NULL);
  283. if (DupDevicePath == NULL) {
  284. return NULL;
  285. }
  286. TempDevicePath = DupDevicePath;
  287. Status = gBS->LocateDevicePath (
  288. &gEfiDevicePathProtocolGuid,
  289. &TempDevicePath,
  290. &DeviceHandle
  291. );
  292. FreePool (DupDevicePath);
  293. if (EFI_ERROR (Status)) {
  294. return NULL;
  295. }
  296. if (IsVgaHandle (DeviceHandle)) {
  297. return DeviceHandle;
  298. } else {
  299. return NULL;
  300. }
  301. }
  302. /**
  303. Return whether the device path is a GOP device path.
  304. @param DevicePath The device path to be tested.
  305. @retval TRUE The device path is a GOP device path.
  306. @retval FALSE The device on the device path is not a GOP device path.
  307. **/
  308. BOOLEAN
  309. IsGopDevicePath (
  310. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
  311. )
  312. {
  313. while (!IsDevicePathEndType (DevicePath)) {
  314. if (DevicePathType (DevicePath) == ACPI_DEVICE_PATH &&
  315. DevicePathSubType (DevicePath) == ACPI_ADR_DP) {
  316. return TRUE;
  317. }
  318. DevicePath = NextDevicePathNode (DevicePath);
  319. }
  320. return FALSE;
  321. }
  322. /**
  323. Remove all GOP device path instance from DevicePath and add the Gop to the DevicePath.
  324. @param DevicePath The device path to be removed
  325. @param Gop The device path to be added.
  326. @retval Return The updated device path.
  327. **/
  328. EFI_DEVICE_PATH_PROTOCOL *
  329. UpdateGopDevicePath (
  330. EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  331. EFI_DEVICE_PATH_PROTOCOL *Gop
  332. )
  333. {
  334. UINTN Size;
  335. UINTN GopSize;
  336. EFI_DEVICE_PATH_PROTOCOL *Temp;
  337. EFI_DEVICE_PATH_PROTOCOL *Return;
  338. EFI_DEVICE_PATH_PROTOCOL *Instance;
  339. BOOLEAN Exist;
  340. Exist = FALSE;
  341. Return = NULL;
  342. GopSize = GetDevicePathSize (Gop);
  343. do {
  344. Instance = GetNextDevicePathInstance (&DevicePath, &Size);
  345. if (Instance == NULL) {
  346. break;
  347. }
  348. if (!IsGopDevicePath (Instance) ||
  349. (Size == GopSize && CompareMem (Instance, Gop, GopSize) == 0)
  350. ) {
  351. if (Size == GopSize && CompareMem (Instance, Gop, GopSize) == 0) {
  352. Exist = TRUE;
  353. }
  354. Temp = Return;
  355. Return = AppendDevicePathInstance (Return, Instance);
  356. if (Temp != NULL) {
  357. FreePool (Temp);
  358. }
  359. }
  360. FreePool (Instance);
  361. } while (DevicePath != NULL);
  362. if (!Exist) {
  363. Temp = Return;
  364. Return = AppendDevicePathInstance (Return, Gop);
  365. if (Temp != NULL) {
  366. FreePool (Temp);
  367. }
  368. }
  369. return Return;
  370. }
  371. /**
  372. Get Graphics Controller Handle.
  373. @param NeedTrustedConsole The flag to determine if trusted console
  374. or non trusted console should be returned
  375. @retval NULL Console not found
  376. @retval PciHandles Successfully located
  377. **/
  378. EFI_HANDLE
  379. EFIAPI
  380. GetGraphicsController (
  381. IN BOOLEAN NeedTrustedConsole
  382. )
  383. {
  384. EFI_STATUS Status;
  385. UINTN Index;
  386. EFI_HANDLE *PciHandles;
  387. UINTN PciHandlesSize;
  388. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  389. Status = gBS->LocateHandleBuffer (
  390. ByProtocol,
  391. &gEfiPciIoProtocolGuid,
  392. NULL,
  393. &PciHandlesSize,
  394. &PciHandles
  395. );
  396. if (EFI_ERROR (Status)) {
  397. return NULL;
  398. }
  399. for (Index = 0; Index < PciHandlesSize; Index++) {
  400. Status = gBS->HandleProtocol (
  401. PciHandles[Index],
  402. &gEfiDevicePathProtocolGuid,
  403. (VOID **) &DevicePath
  404. );
  405. if (EFI_ERROR(Status)) {
  406. continue;
  407. }
  408. if (!IsVgaHandle (PciHandles[Index])) {
  409. continue;
  410. }
  411. if ((NeedTrustedConsole && IsTrustedConsole (ConOut, DevicePath)) ||
  412. ((!NeedTrustedConsole) && (!IsTrustedConsole (ConOut, DevicePath)))) {
  413. return PciHandles[Index];
  414. }
  415. }
  416. return NULL;
  417. }
  418. /**
  419. Updates Graphic ConOut variable.
  420. @param NeedTrustedConsole The flag that determines if trusted console
  421. or non trusted console should be returned
  422. **/
  423. VOID
  424. UpdateGraphicConOut (
  425. IN BOOLEAN NeedTrustedConsole
  426. )
  427. {
  428. EFI_HANDLE GraphicsControllerHandle;
  429. EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
  430. EFI_DEVICE_PATH_PROTOCOL *ConOutDevicePath;
  431. EFI_DEVICE_PATH_PROTOCOL *UpdatedConOutDevicePath;
  432. //
  433. // Update ConOut variable
  434. //
  435. GraphicsControllerHandle = GetGraphicsController (NeedTrustedConsole);
  436. if (GraphicsControllerHandle != NULL) {
  437. //
  438. // Connect the GOP driver
  439. //
  440. gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE);
  441. //
  442. // Get the GOP device path
  443. // NOTE: We may get a device path that contains Controller node in it.
  444. //
  445. GopDevicePath = EfiBootManagerGetGopDevicePath (GraphicsControllerHandle);
  446. if (GopDevicePath != NULL) {
  447. GetEfiGlobalVariable2 (L"ConOut", (VOID **)&ConOutDevicePath, NULL);
  448. UpdatedConOutDevicePath = UpdateGopDevicePath (ConOutDevicePath, GopDevicePath);
  449. if (ConOutDevicePath != NULL) {
  450. FreePool (ConOutDevicePath);
  451. }
  452. FreePool (GopDevicePath);
  453. gRT->SetVariable (
  454. L"ConOut",
  455. &gEfiGlobalVariableGuid,
  456. EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,
  457. GetDevicePathSize (UpdatedConOutDevicePath),
  458. UpdatedConOutDevicePath
  459. );
  460. }
  461. }
  462. }
  463. /**
  464. The function connects the trusted consoles.
  465. **/
  466. VOID
  467. ConnectTrustedConsole (
  468. VOID
  469. )
  470. {
  471. EFI_DEVICE_PATH_PROTOCOL *Consoles;
  472. EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
  473. EFI_DEVICE_PATH_PROTOCOL *Instance;
  474. EFI_DEVICE_PATH_PROTOCOL *Next;
  475. UINTN Size;
  476. UINTN Index;
  477. EFI_HANDLE Handle;
  478. EFI_STATUS Status;
  479. CHAR16 *ConsoleVar[] = {L"ConIn", L"ConOut"};
  480. VOID *TrustedConsoleDevicepath;
  481. TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleInputDevicePath);
  482. DumpDevicePath (L"TrustedConsoleIn", TrustedConsoleDevicepath);
  483. TrustedConsoleDevicepath = PcdGetPtr (PcdTrustedConsoleOutputDevicePath);
  484. DumpDevicePath (L"TrustedConsoleOut", TrustedConsoleDevicepath);
  485. for (Index = 0; Index < sizeof (ConsoleVar) / sizeof (ConsoleVar[0]); Index++) {
  486. GetEfiGlobalVariable2 (ConsoleVar[Index], (VOID **)&Consoles, NULL);
  487. TempDevicePath = Consoles;
  488. do {
  489. Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
  490. if (Instance == NULL) {
  491. break;
  492. }
  493. if (IsTrustedConsole (Index, Instance)) {
  494. if (IsUsbShortForm (Instance)) {
  495. ConnectUsbShortFormDevicePath (Instance);
  496. } else {
  497. for (Next = Instance; !IsDevicePathEnd (Next); Next = NextDevicePathNode (Next)) {
  498. if (DevicePathType (Next) == ACPI_DEVICE_PATH && DevicePathSubType (Next) == ACPI_ADR_DP) {
  499. break;
  500. } else if (DevicePathType (Next) == HARDWARE_DEVICE_PATH &&
  501. DevicePathSubType (Next) == HW_CONTROLLER_DP &&
  502. DevicePathType (NextDevicePathNode (Next)) == ACPI_DEVICE_PATH &&
  503. DevicePathSubType (NextDevicePathNode (Next)) == ACPI_ADR_DP
  504. ) {
  505. break;
  506. }
  507. }
  508. if (!IsDevicePathEnd (Next)) {
  509. SetDevicePathEndNode (Next);
  510. Status = EfiBootManagerConnectDevicePath (Instance, &Handle);
  511. if (!EFI_ERROR (Status)) {
  512. gBS->ConnectController (Handle, NULL, NULL, TRUE);
  513. }
  514. } else {
  515. EfiBootManagerConnectDevicePath (Instance, NULL);
  516. }
  517. }
  518. }
  519. FreePool (Instance);
  520. } while (TempDevicePath != NULL);
  521. if (Consoles != NULL) {
  522. FreePool (Consoles);
  523. }
  524. }
  525. }
  526. /**
  527. The function connects the trusted Storages.
  528. **/
  529. VOID
  530. ConnectTrustedStorage (
  531. VOID
  532. )
  533. {
  534. VOID *TrustedStorageDevicepath;
  535. EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
  536. EFI_DEVICE_PATH_PROTOCOL *Instance;
  537. UINTN Size;
  538. EFI_DEVICE_PATH_PROTOCOL *TempStorageDevicePath;
  539. EFI_STATUS Status;
  540. EFI_HANDLE DeviceHandle;
  541. TrustedStorageDevicepath = PcdGetPtr (PcdTrustedStorageDevicePath);
  542. DumpDevicePath (L"TrustedStorage", TrustedStorageDevicepath);
  543. TempDevicePath = TrustedStorageDevicepath;
  544. do {
  545. Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
  546. if (Instance == NULL) {
  547. break;
  548. }
  549. EfiBootManagerConnectDevicePath (Instance, NULL);
  550. TempStorageDevicePath = Instance;
  551. Status = gBS->LocateDevicePath (
  552. &gEfiDevicePathProtocolGuid,
  553. &TempStorageDevicePath,
  554. &DeviceHandle
  555. );
  556. if (!EFI_ERROR (Status)) {
  557. gBS->ConnectController (DeviceHandle, NULL, NULL, FALSE);
  558. }
  559. FreePool (Instance);
  560. } while (TempDevicePath != NULL);
  561. }
  562. /**
  563. Check if current BootCurrent variable is internal shell boot option.
  564. @retval TRUE BootCurrent is internal shell.
  565. @retval FALSE BootCurrent is not internal shell.
  566. **/
  567. BOOLEAN
  568. BootCurrentIsInternalShell (
  569. VOID
  570. )
  571. {
  572. UINTN VarSize;
  573. UINT16 BootCurrent;
  574. CHAR16 BootOptionName[16];
  575. UINT8 *BootOption;
  576. UINT8 *Ptr;
  577. BOOLEAN Result;
  578. EFI_STATUS Status;
  579. EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
  580. EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
  581. EFI_GUID *GuidPoint;
  582. BootOption = NULL;
  583. Result = FALSE;
  584. //
  585. // Get BootCurrent variable
  586. //
  587. VarSize = sizeof (UINT16);
  588. Status = gRT->GetVariable (
  589. L"BootCurrent",
  590. &gEfiGlobalVariableGuid,
  591. NULL,
  592. &VarSize,
  593. &BootCurrent
  594. );
  595. if (EFI_ERROR (Status)) {
  596. return FALSE;
  597. }
  598. //
  599. // Create boot option Bootxxxx from BootCurrent
  600. //
  601. UnicodeSPrint (BootOptionName, sizeof(BootOptionName), L"Boot%04X", BootCurrent);
  602. GetEfiGlobalVariable2 (BootOptionName, (VOID **) &BootOption, &VarSize);
  603. if (BootOption == NULL || VarSize == 0) {
  604. return FALSE;
  605. }
  606. Ptr = BootOption;
  607. Ptr += sizeof (UINT32);
  608. Ptr += sizeof (UINT16);
  609. Ptr += StrSize ((CHAR16 *) Ptr);
  610. TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;
  611. LastDeviceNode = TempDevicePath;
  612. while (!IsDevicePathEnd (TempDevicePath)) {
  613. LastDeviceNode = TempDevicePath;
  614. TempDevicePath = NextDevicePathNode (TempDevicePath);
  615. }
  616. GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (
  617. (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode
  618. );
  619. if ((GuidPoint != NULL) &&
  620. ((CompareGuid (GuidPoint, &gUefiShellFileGuid)))) {
  621. //
  622. // if this option is internal shell, return TRUE
  623. //
  624. Result = TRUE;
  625. }
  626. if (BootOption != NULL) {
  627. FreePool (BootOption);
  628. BootOption = NULL;
  629. }
  630. return Result;
  631. }
  632. /**
  633. This function will change video resolution and text mode
  634. for internl shell when internal shell is launched.
  635. @param None.
  636. @retval EFI_SUCCESS Mode is changed successfully.
  637. @retval Others Mode failed to changed.
  638. **/
  639. EFI_STATUS
  640. EFIAPI
  641. ChangeModeForInternalShell (
  642. VOID
  643. )
  644. {
  645. EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
  646. EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
  647. UINTN SizeOfInfo;
  648. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  649. UINT32 MaxGopMode;
  650. UINT32 MaxTextMode;
  651. UINT32 ModeNumber;
  652. UINTN HandleCount;
  653. EFI_HANDLE *HandleBuffer;
  654. EFI_STATUS Status;
  655. UINTN Index;
  656. UINTN CurrentColumn;
  657. UINTN CurrentRow;
  658. //
  659. // Internal shell mode
  660. //
  661. UINT32 mShellModeColumn;
  662. UINT32 mShellModeRow;
  663. UINT32 mShellHorizontalResolution;
  664. UINT32 mShellVerticalResolution;
  665. //
  666. // Get user defined text mode for internal shell only once.
  667. //
  668. mShellHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
  669. mShellVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
  670. mShellModeColumn = PcdGet32 (PcdSetupConOutColumn);
  671. mShellModeRow = PcdGet32 (PcdSetupConOutRow);
  672. Status = gBS->HandleProtocol (
  673. gST->ConsoleOutHandle,
  674. &gEfiGraphicsOutputProtocolGuid,
  675. (VOID**)&GraphicsOutput
  676. );
  677. if (EFI_ERROR (Status)) {
  678. GraphicsOutput = NULL;
  679. }
  680. Status = gBS->HandleProtocol (
  681. gST->ConsoleOutHandle,
  682. &gEfiSimpleTextOutProtocolGuid,
  683. (VOID**)&SimpleTextOut
  684. );
  685. if (EFI_ERROR (Status)) {
  686. SimpleTextOut = NULL;
  687. }
  688. if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
  689. return EFI_UNSUPPORTED;
  690. }
  691. MaxGopMode = GraphicsOutput->Mode->MaxMode;
  692. MaxTextMode = SimpleTextOut->Mode->MaxMode;
  693. //
  694. // 1. If current video resolution is same with new video resolution,
  695. // video resolution need not be changed.
  696. // 1.1. If current text mode is same with new text mode, text mode need not be change.
  697. // 1.2. If current text mode is different with new text mode, text mode need be change to new text mode.
  698. // 2. If current video resolution is different with new video resolution, we need restart whole console drivers.
  699. //
  700. for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
  701. Status = GraphicsOutput->QueryMode (
  702. GraphicsOutput,
  703. ModeNumber,
  704. &SizeOfInfo,
  705. &Info
  706. );
  707. if (!EFI_ERROR (Status)) {
  708. if ((Info->HorizontalResolution == mShellHorizontalResolution) &&
  709. (Info->VerticalResolution == mShellVerticalResolution)) {
  710. if ((GraphicsOutput->Mode->Info->HorizontalResolution == mShellHorizontalResolution) &&
  711. (GraphicsOutput->Mode->Info->VerticalResolution == mShellVerticalResolution)) {
  712. //
  713. // If current video resolution is same with new resolution,
  714. // then check if current text mode is same with new text mode.
  715. //
  716. Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
  717. ASSERT_EFI_ERROR (Status);
  718. if (CurrentColumn == mShellModeColumn && CurrentRow == mShellModeRow) {
  719. //
  720. // Current text mode is same with new text mode, text mode need not be change.
  721. //
  722. FreePool (Info);
  723. return EFI_SUCCESS;
  724. } else {
  725. //
  726. // Current text mode is different with new text mode, text mode need be change to new text mode.
  727. //
  728. for (Index = 0; Index < MaxTextMode; Index++) {
  729. Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);
  730. if (!EFI_ERROR(Status)) {
  731. if ((CurrentColumn == mShellModeColumn) && (CurrentRow == mShellModeRow)) {
  732. //
  733. // New text mode is supported, set it.
  734. //
  735. Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
  736. ASSERT_EFI_ERROR (Status);
  737. //
  738. // Update text mode PCD.
  739. //
  740. Status = PcdSet32S (PcdConOutColumn, mShellModeColumn);
  741. ASSERT_EFI_ERROR (Status);
  742. Status = PcdSet32S (PcdConOutRow, mShellModeRow);
  743. ASSERT_EFI_ERROR (Status);
  744. FreePool (Info);
  745. return EFI_SUCCESS;
  746. }
  747. }
  748. }
  749. if (Index == MaxTextMode) {
  750. //
  751. // If new text mode is not supported, return error.
  752. //
  753. FreePool (Info);
  754. return EFI_UNSUPPORTED;
  755. }
  756. }
  757. } else {
  758. FreePool (Info);
  759. //
  760. // If current video resolution is not same with the new one, set new video resolution.
  761. // In this case, the driver which produces simple text out need be restarted.
  762. //
  763. Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
  764. if (!EFI_ERROR (Status)) {
  765. //
  766. // Set PCD to restart GraphicsConsole and Consplitter to change video resolution
  767. // and produce new text mode based on new resolution.
  768. //
  769. Status = PcdSet32S (PcdVideoHorizontalResolution, mShellHorizontalResolution);
  770. ASSERT_EFI_ERROR (Status);
  771. Status = PcdSet32S (PcdVideoVerticalResolution, mShellVerticalResolution);
  772. ASSERT_EFI_ERROR (Status);
  773. Status = PcdSet32S (PcdConOutColumn, mShellModeColumn);
  774. ASSERT_EFI_ERROR (Status);
  775. Status = PcdSet32S (PcdConOutRow, mShellModeRow);
  776. ASSERT_EFI_ERROR (Status);
  777. Status = gBS->LocateHandleBuffer (
  778. ByProtocol,
  779. &gEfiSimpleTextOutProtocolGuid,
  780. NULL,
  781. &HandleCount,
  782. &HandleBuffer
  783. );
  784. if (!EFI_ERROR (Status)) {
  785. for (Index = 0; Index < HandleCount; Index++) {
  786. gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
  787. }
  788. for (Index = 0; Index < HandleCount; Index++) {
  789. gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
  790. }
  791. if (HandleBuffer != NULL) {
  792. FreePool (HandleBuffer);
  793. }
  794. break;
  795. }
  796. }
  797. }
  798. }
  799. FreePool (Info);
  800. }
  801. }
  802. if (ModeNumber == MaxGopMode) {
  803. //
  804. // If the new resolution is not supported, return error.
  805. //
  806. return EFI_UNSUPPORTED;
  807. }
  808. return EFI_SUCCESS;
  809. }
  810. /**
  811. The function connects the trusted consoles and then call the PP processing library interface.
  812. **/
  813. VOID
  814. ProcessTcgPp (
  815. VOID
  816. )
  817. {
  818. gPPRequireUIConfirm |= Tcg2PhysicalPresenceLibNeedUserConfirm();
  819. if (gPPRequireUIConfirm) {
  820. ConnectTrustedConsole ();
  821. }
  822. Tcg2PhysicalPresenceLibProcessRequest (NULL);
  823. }
  824. /**
  825. The function connects the trusted storage to perform TPerReset.
  826. **/
  827. VOID
  828. ProcessTcgMor (
  829. VOID
  830. )
  831. {
  832. if (IsMorBitSet ()) {
  833. ConnectTrustedConsole();
  834. ConnectTrustedStorage();
  835. }
  836. }
  837. /**
  838. Update the ConIn variable with USB Keyboard device path,if its not already exists in ConIn
  839. **/
  840. VOID
  841. EnumUsbKeyboard (
  842. VOID
  843. )
  844. {
  845. DEBUG ((DEBUG_INFO, "[EnumUsbKeyboard]\n"));
  846. EfiBootManagerUpdateConsoleVariable (ConIn, (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, NULL);
  847. //
  848. // Append Usb Keyboard short form DevicePath into "ConInDev"
  849. //
  850. EfiBootManagerUpdateConsoleVariable (ConInDev, (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath, NULL);
  851. }
  852. /**
  853. Connect with predeined platform connect sequence,
  854. the OEM/IBV can customize with their own connect sequence.
  855. @param[in] BootMode Boot mode of this boot.
  856. **/
  857. VOID
  858. ConnectSequence (
  859. IN EFI_BOOT_MODE BootMode
  860. )
  861. {
  862. EfiBootManagerConnectAll ();
  863. }
  864. /**
  865. The function is to consider the boot order which is not in our expectation.
  866. In the case that we need to re-sort the boot option.
  867. @retval TRUE Need to sort Boot Option.
  868. @retval FALSE Don't need to sort Boot Option.
  869. **/
  870. BOOLEAN
  871. IsNeedSortBootOption (
  872. VOID
  873. )
  874. {
  875. EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
  876. UINTN BootOptionCount;
  877. BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
  878. //
  879. // If setup is the first priority in boot option, we need to sort boot option.
  880. //
  881. if ((BootOptionCount > 1) &&
  882. (((StrnCmp (BootOptions->Description, L"Enter Setup", StrLen (L"Enter Setup"))) == 0) ||
  883. ((StrnCmp (BootOptions->Description, L"BootManagerMenuApp", StrLen (L"BootManagerMenuApp"))) == 0))) {
  884. return TRUE;
  885. }
  886. return FALSE;
  887. }
  888. /**
  889. Connects Root Bridge
  890. **/
  891. VOID
  892. ConnectRootBridge (
  893. BOOLEAN Recursive
  894. )
  895. {
  896. UINTN RootBridgeHandleCount;
  897. EFI_HANDLE *RootBridgeHandleBuffer;
  898. UINTN RootBridgeIndex;
  899. RootBridgeHandleCount = 0;
  900. gBS->LocateHandleBuffer (
  901. ByProtocol,
  902. &gEfiPciRootBridgeIoProtocolGuid,
  903. NULL,
  904. &RootBridgeHandleCount,
  905. &RootBridgeHandleBuffer
  906. );
  907. for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) {
  908. gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, Recursive);
  909. }
  910. }
  911. VOID
  912. AddConsoleVariable (
  913. IN CONSOLE_TYPE ConsoleType,
  914. IN EFI_DEVICE_PATH *ConsoleDevicePath
  915. )
  916. {
  917. EFI_DEVICE_PATH *TempDevicePath;
  918. EFI_DEVICE_PATH *Instance;
  919. UINTN Size;
  920. EFI_HANDLE GraphicsControllerHandle;
  921. EFI_DEVICE_PATH *GopDevicePath;
  922. TempDevicePath = ConsoleDevicePath;
  923. do {
  924. Instance = GetNextDevicePathInstance (&TempDevicePath, &Size);
  925. if (Instance == NULL) {
  926. break;
  927. }
  928. switch (ConsoleType) {
  929. case ConIn:
  930. if (IsUsbShortForm (Instance)) {
  931. //
  932. // Append Usb Keyboard short form DevicePath into "ConInDev"
  933. //
  934. EfiBootManagerUpdateConsoleVariable (ConInDev, Instance, NULL);
  935. }
  936. EfiBootManagerUpdateConsoleVariable (ConsoleType, Instance, NULL);
  937. break;
  938. case ConOut:
  939. GraphicsControllerHandle = IsVideoController (Instance);
  940. if (GraphicsControllerHandle == NULL) {
  941. EfiBootManagerUpdateConsoleVariable (ConsoleType, Instance, NULL);
  942. } else {
  943. //
  944. // Connect the GOP driver
  945. //
  946. gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE);
  947. //
  948. // Get the GOP device path
  949. // NOTE: We may get a device path that contains Controller node in it.
  950. //
  951. GopDevicePath = EfiBootManagerGetGopDevicePath (GraphicsControllerHandle);
  952. if (GopDevicePath != NULL) {
  953. EfiBootManagerUpdateConsoleVariable (ConsoleType, GopDevicePath, NULL);
  954. }
  955. }
  956. break;
  957. default:
  958. ASSERT(FALSE);
  959. break;
  960. }
  961. FreePool (Instance);
  962. } while (TempDevicePath != NULL);
  963. }
  964. /**
  965. This is the callback function for PCI ENUMERATION COMPLETE.
  966. @param[in] Event The Event this notify function registered to.
  967. @param[in] Context Pointer to the context data registered to the Event.
  968. **/
  969. VOID
  970. EFIAPI
  971. BdsPciEnumCompleteCallback (
  972. IN EFI_EVENT Event,
  973. IN VOID *Context
  974. )
  975. {
  976. EFI_STATUS Status;
  977. VOID *ProtocolPointer;
  978. EFI_DEVICE_PATH_PROTOCOL *VarConOut;
  979. EFI_DEVICE_PATH_PROTOCOL *VarConIn;
  980. Status = EFI_SUCCESS;
  981. //
  982. // Check if this is first time called by EfiCreateProtocolNotifyEvent() or not,
  983. // if it is, we will skip it until real event is triggered
  984. //
  985. Status = gBS->LocateProtocol (&gEfiPciEnumerationCompleteProtocolGuid, NULL, (VOID **) &ProtocolPointer);
  986. if (EFI_SUCCESS != Status) {
  987. return;
  988. }
  989. //gBS->CloseEvent (Event);
  990. DEBUG ((DEBUG_INFO, "Event BdsPciEnumCompleteCallback callback starts\n"));
  991. gBootMode = GetBootModeHob ();
  992. //
  993. // Fill ConIn/ConOut in Full Configuration boot mode
  994. //
  995. DEBUG ((DEBUG_INFO, "PlatformBootManagerInit - %x\n", gBootMode));
  996. if (gBootMode == BOOT_WITH_FULL_CONFIGURATION ||
  997. gBootMode == BOOT_WITH_DEFAULT_SETTINGS ||
  998. gBootMode == BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS ||
  999. gBootMode == BOOT_IN_RECOVERY_MODE) {
  1000. GetEfiGlobalVariable2 (L"ConOut", (VOID **)&VarConOut, NULL);
  1001. if (VarConOut != NULL) {
  1002. FreePool (VarConOut);
  1003. }
  1004. GetEfiGlobalVariable2 (L"ConIn", (VOID **)&VarConIn, NULL);
  1005. if (VarConIn != NULL) {
  1006. FreePool (VarConIn);
  1007. }
  1008. //
  1009. // Only fill ConIn/ConOut when ConIn/ConOut is empty because we may drop to Full Configuration boot mode in non-first boot
  1010. //
  1011. if (VarConOut == NULL || VarConIn == NULL) {
  1012. if (PcdGetSize (PcdTrustedConsoleOutputDevicePath) >= sizeof(EFI_DEVICE_PATH_PROTOCOL)) {
  1013. AddConsoleVariable (ConOut, PcdGetPtr (PcdTrustedConsoleOutputDevicePath));
  1014. }
  1015. if (PcdGetSize (PcdTrustedConsoleInputDevicePath) >= sizeof(EFI_DEVICE_PATH_PROTOCOL)) {
  1016. AddConsoleVariable (ConIn, PcdGetPtr (PcdTrustedConsoleInputDevicePath));
  1017. }
  1018. }
  1019. }
  1020. //
  1021. // Enumerate USB keyboard
  1022. //
  1023. EnumUsbKeyboard ();
  1024. //
  1025. // For trusted console it must be handled here.
  1026. //
  1027. UpdateGraphicConOut (TRUE);
  1028. //
  1029. // Register Boot Options
  1030. //
  1031. RegisterDefaultBootOption ();
  1032. //
  1033. // Register Static Hot keys
  1034. //
  1035. RegisterStaticHotkey ();
  1036. //
  1037. // Process Physical Preo
  1038. //
  1039. PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7010);
  1040. if (PcdGetBool (PcdTpm2Enable)) {
  1041. ProcessTcgPp ();
  1042. ProcessTcgMor ();
  1043. }
  1044. PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7011);
  1045. //
  1046. // Perform memory test
  1047. // We should make all UEFI memory and GCD information populated before ExitPmAuth.
  1048. // SMM may consume these information.
  1049. //
  1050. MemoryTest((EXTENDMEM_COVERAGE_LEVEL) PcdGet32 (PcdPlatformMemoryCheckLevel));
  1051. }
  1052. /**
  1053. This is the callback function for Smm Ready To Lock.
  1054. @param[in] Event The Event this notify function registered to.
  1055. @param[in] Context Pointer to the context data registered to the Event.
  1056. **/
  1057. VOID
  1058. EFIAPI
  1059. BdsSmmReadyToLockCallback (
  1060. IN EFI_EVENT Event,
  1061. IN VOID *Context
  1062. )
  1063. {
  1064. VOID *ProtocolPointer;
  1065. EFI_STATUS Status;
  1066. //
  1067. // Check if this is first time called by EfiCreateProtocolNotifyEvent() or not,
  1068. // if it is, we will skip it until real event is triggered
  1069. //
  1070. Status = gBS->LocateProtocol (&gEfiDxeSmmReadyToLockProtocolGuid, NULL, (VOID **) &ProtocolPointer);
  1071. if (EFI_SUCCESS != Status) {
  1072. return;
  1073. }
  1074. DEBUG ((DEBUG_INFO, "Event gEfiDxeSmmReadyToLockProtocolGuid callback starts\n"));
  1075. //
  1076. // Dispatch the deferred 3rd party images.
  1077. //
  1078. EfiBootManagerDispatchDeferredImages ();
  1079. //
  1080. // For non-trusted console it must be handled here.
  1081. //
  1082. UpdateGraphicConOut (FALSE);
  1083. }
  1084. /**
  1085. ReadyToBoot callback to set video and text mode for internal shell boot.
  1086. That will not connect USB controller while CSM and FastBoot are disabled, we need to connect them
  1087. before booting to Shell for showing USB devices in Shell.
  1088. When FastBoot is enabled and Windows Console is the chosen Console behavior, input devices will not be connected
  1089. by default. Hence, when booting to EFI shell, connecting input consoles are required.
  1090. @param Event Pointer to this event
  1091. @param Context Event hanlder private data
  1092. @retval None.
  1093. **/
  1094. VOID
  1095. EFIAPI
  1096. BdsReadyToBootCallback (
  1097. IN EFI_EVENT Event,
  1098. IN VOID *Context
  1099. )
  1100. {
  1101. DEBUG ((DEBUG_INFO, "BdsReadyToBootCallback\n"));
  1102. if (BootCurrentIsInternalShell ()) {
  1103. ChangeModeForInternalShell ();
  1104. EfiBootManagerConnectAllDefaultConsoles ();
  1105. gDS->Dispatch ();
  1106. }
  1107. }
  1108. /**
  1109. Before console after trusted console event callback
  1110. @param[in] Event The Event this notify function registered to.
  1111. @param[in] Context Pointer to the context data registered to the Event.
  1112. **/
  1113. VOID
  1114. BdsBeforeConsoleAfterTrustedConsoleCallback (
  1115. IN EFI_EVENT Event,
  1116. IN VOID *Context
  1117. )
  1118. {
  1119. DEBUG ((DEBUG_INFO, "Event gBdsEventBeforeConsoleBeforeEndOfDxeGuid callback starts\n"));
  1120. //
  1121. // Connect Root Bridge to make PCI BAR resource allocated and all PciIo created
  1122. //
  1123. ConnectRootBridge (FALSE);
  1124. }
  1125. /**
  1126. Before console before end of DXE event callback
  1127. @param[in] Event The Event this notify function registered to.
  1128. @param[in] Context Pointer to the context data registered to the Event.
  1129. **/
  1130. VOID
  1131. BdsBeforeConsoleBeforeEndOfDxeGuidCallback (
  1132. IN EFI_EVENT Event,
  1133. IN VOID *Context
  1134. )
  1135. {
  1136. DEBUG ((DEBUG_INFO, "Event gBdsBeforeConsoleBeforeEndOfDxeGuid callback starts\n"));
  1137. }
  1138. /**
  1139. After console ready before boot option event callback
  1140. @param[in] Event The Event this notify function registered to.
  1141. @param[in] Context Pointer to the context data registered to the Event.
  1142. **/
  1143. VOID
  1144. BdsAfterConsoleReadyBeforeBootOptionCallback (
  1145. IN EFI_EVENT Event,
  1146. IN VOID *Context
  1147. )
  1148. {
  1149. EFI_BOOT_MODE LocalBootMode;
  1150. DEBUG ((DEBUG_INFO, "Event gBdsAfterConsoleReadyBeforeBootOptionEvent callback starts\n"));
  1151. //
  1152. // Get current Boot Mode
  1153. //
  1154. LocalBootMode = gBootMode;
  1155. DEBUG ((DEBUG_INFO, "Current local bootmode - %x\n", LocalBootMode));
  1156. //
  1157. // Go the different platform policy with different boot mode
  1158. // Notes: this part code can be change with the table policy
  1159. //
  1160. switch (LocalBootMode) {
  1161. case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
  1162. case BOOT_WITH_MINIMAL_CONFIGURATION:
  1163. case BOOT_ON_S4_RESUME:
  1164. //
  1165. // Perform some platform specific connect sequence
  1166. //
  1167. PERF_START_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7050);
  1168. ConnectSequence (LocalBootMode);
  1169. PERF_END_EX(NULL,"EventRec", NULL, AsmReadTsc(), 0x7051);
  1170. break;
  1171. case BOOT_WITH_FULL_CONFIGURATION:
  1172. case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
  1173. case BOOT_WITH_DEFAULT_SETTINGS:
  1174. default:
  1175. //
  1176. // Perform some platform specific connect sequence
  1177. //
  1178. ConnectSequence (LocalBootMode);
  1179. //
  1180. // Only in Full Configuration boot mode we do the enumeration of boot device
  1181. //
  1182. //
  1183. // Dispatch all but Storage Oprom explicitly, because we assume Int13Thunk driver is there.
  1184. //
  1185. //
  1186. // PXE boot option may appear after boot option enumeration
  1187. //
  1188. break;
  1189. }
  1190. Print (L"Press F7 for BootMenu!\n");
  1191. EfiBootManagerRefreshAllBootOption ();
  1192. if (IsNeedSortBootOption()) {
  1193. EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
  1194. }
  1195. }