From 661da8820b3afeff4fc9b32e0412f67d554c52a0 Mon Sep 17 00:00:00 2001 From: "Chen, Pai-chingX" Date: Wed, 1 Nov 2017 14:26:00 +0800 Subject: Decouple Graphics Console Selection from MinPlatformPkg Cc: Michael A Kubacki Cc: Amy Chan Cc: Chasel Chiu Cc: Rangasai V Chaganty Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Pai-chingX Chen Reviewed-by: Jiewen Yao --- .../DxePlatformBootManagerLib/BdsPlatform.c | 139 ++++++++++++++------- .../DxePlatformBootManagerLib.inf | 10 +- Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec | 5 + 3 files changed, 108 insertions(+), 46 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c index 74c0d2d9a6..ef0bf0bb89 100644 --- a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/BdsPlatform.c @@ -19,6 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include #include @@ -791,6 +792,66 @@ OnReadyToBootCallBack ( } } +/** + Get Graphics Controller Handle. + + @retval GraphicsController Successfully located + @retval NULL Failed to locate +**/ +EFI_HANDLE +EFIAPI +GetGraphicsController ( + VOID + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_HANDLE *PciHandles; + UINTN PciHandlesSize; + EFI_PCI_IO_PROTOCOL *PciIo; + EFI_HANDLE GraphicsController; + UINTN GraphicsPciSeg; + UINTN GraphicsPciBus; + UINTN GraphicsPciDev; + UINTN GraphicsPciFun; + + GraphicsController = NULL; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiPciIoProtocolGuid, + NULL, + &PciHandlesSize, + &PciHandles + ); + if (!RETURN_ERROR (Status)) { + for (Index = 0; Index < PciHandlesSize; Index++) { + gBS->HandleProtocol ( + PciHandles[Index], + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo + ); + Status = PciIo->GetLocation ( + PciIo, + &GraphicsPciSeg, + &GraphicsPciBus, + &GraphicsPciDev, + &GraphicsPciFun + ); + if (!RETURN_ERROR (Status) && + (UINT16) GraphicsPciSeg == PcdGet16 (PcdGraphicsPciSeg) && + (UINT8) GraphicsPciBus == PcdGet8 (PcdGraphicsPciBus) && + (UINT8) GraphicsPciDev == PcdGet8 (PcdGraphicsPciDev) && + (UINT8) GraphicsPciFun == PcdGet8 (PcdGraphicsPciFun)) { + GraphicsController = PciHandles[Index]; + Index = PciHandlesSize; + } + } + } + + return GraphicsController; +} + /** Platform Bds init. Incude the platform firmware vendor, revision and so crc check. @@ -805,13 +866,12 @@ PlatformBootManagerBeforeConsole ( UINTN Index; EFI_DEVICE_PATH_PROTOCOL *VarConOut; EFI_DEVICE_PATH_PROTOCOL *VarConIn; - EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - EFI_DEVICE_PATH_PROTOCOL *ConsoleOut; - EFI_DEVICE_PATH_PROTOCOL *Temp; + EFI_DEVICE_PATH_PROTOCOL *GopDevicePath; + EFI_DEVICE_PATH_PROTOCOL *ConOutDevicePath; + EFI_DEVICE_PATH_PROTOCOL *UpdatedConOutDevicePath; EFI_DEVICE_PATH_PROTOCOL *Instance; EFI_DEVICE_PATH_PROTOCOL *Next; - EFI_HANDLE VideoHandle; - BOOLEAN IsIgd; + EFI_HANDLE GraphicsControllerHandle; EFI_EVENT Event; UINTN InstanceSize; @@ -851,44 +911,6 @@ PlatformBootManagerBeforeConsole ( // ConnectRootBridge (FALSE); - // - // Update ConOut variable according to the PrimaryDisplay setting - // - GetEfiGlobalVariable2 (L"ConOut", &ConsoleOut, NULL); - // - // Add IGD to ConOut - // - IsIgd = TRUE; - TempDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &gPlatformIGDDevice; - Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &TempDevicePath, &VideoHandle); - - if ((VideoHandle != NULL) && (IsIgd == TRUE)) { - // - // Connect the GOP driver - // - gBS->ConnectController (VideoHandle, NULL, NULL, TRUE); - - // - // Get the GOP device path - // NOTE: We may get a device path that contains Controller node in it. - // - TempDevicePath = EfiBootManagerGetGopDevicePath (VideoHandle); - if (TempDevicePath != NULL) { - Temp = ConsoleOut; - ConsoleOut = UpdateDevicePath (ConsoleOut, TempDevicePath); - if (Temp != NULL) { - FreePool (Temp); - } - FreePool (TempDevicePath); - Status = gRT->SetVariable ( - L"ConOut", - &gEfiGlobalVariableGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, - GetDevicePathSize (ConsoleOut), - ConsoleOut - ); - } - } // // Fill ConIn/ConOut in Full Configuration boot mode // @@ -988,6 +1010,37 @@ PlatformBootManagerBeforeConsole ( // EfiBootManagerDispatchDeferredImages (); + // + // Update ConOut variable + // + GraphicsControllerHandle = GetGraphicsController (); + if (GraphicsControllerHandle != NULL) { + // + // Connect the GOP driver + // + gBS->ConnectController (GraphicsControllerHandle, NULL, NULL, TRUE); + + // + // Get the GOP device path + // NOTE: We may get a device path that contains Controller node in it. + // + GopDevicePath = EfiBootManagerGetGopDevicePath (GraphicsControllerHandle); + if (GopDevicePath != NULL) { + GetEfiGlobalVariable2 (L"ConOut", &ConOutDevicePath, NULL); + UpdatedConOutDevicePath = UpdateDevicePath (ConOutDevicePath, GopDevicePath); + if (ConOutDevicePath != NULL) { + FreePool (ConOutDevicePath); + } + FreePool (GopDevicePath); + Status = gRT->SetVariable ( + L"ConOut", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS, + GetDevicePathSize (UpdatedConOutDevicePath), + UpdatedConOutDevicePath + ); + } + } } diff --git a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf index 19d3b1acca..fb4435203e 100644 --- a/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf +++ b/Platform/Intel/MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf @@ -54,7 +54,7 @@ MinPlatformPkg/MinPlatformPkg.dec [Pcd] - gMinPlatformModuleTokenSpaceGuid.PcdTpm2Enable ## CONSUMES + gMinPlatformModuleTokenSpaceGuid.PcdTpm2Enable ## CONSUMES gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## PRODUCES gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution ## PRODUCES gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution ## PRODUCES @@ -65,8 +65,12 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## PRODUCES - gMinPlatformModuleTokenSpaceGuid.PcdPlatformMemoryCheckLevel ## CONSUMES - gMinPlatformModuleTokenSpaceGuid.PcdBootToShellOnly + gMinPlatformModuleTokenSpaceGuid.PcdPlatformMemoryCheckLevel ## CONSUMES + gMinPlatformModuleTokenSpaceGuid.PcdBootToShellOnly ## CONSUMES + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciSeg ## CONSUMES + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciBus ## CONSUMES + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciDev ## CONSUMES + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciFun ## CONSUMES [Sources] BdsPlatform.c diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec index 05bdf234c5..71a2afcb93 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec @@ -174,6 +174,11 @@ gMinPlatformModuleTokenSpaceGuid.PcdTestPointIbvPlatformFeature|{0x01, 0x7F, 0x3 [PcdsDynamic] [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] + + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciSeg|0x0|UINT16|0x00020000 + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciBus|0x0|UINT8|0x00020001 + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciDev|0x2|UINT8|0x00020002 + gMinPlatformModuleTokenSpaceGuid.PcdGraphicsPciFun|0x0|UINT8|0x00020003 ## ## Allocate 56 KB [0x2000..0xFFFF] of I/O space for Pci Devices -- cgit v1.2.3