Skip to content

Commit

Permalink
Merge pull request #9 from 9elements/feature/primaryScreen
Browse files Browse the repository at this point in the history
UefiPayloadPkg/Library/PlatformBootManagerLib: Handle Primary Video
  • Loading branch information
sylv-io authored Jul 27, 2020
2 parents e91f03a + d1f7789 commit 4e181db
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 2 deletions.
4 changes: 4 additions & 0 deletions MdeModulePkg/Include/Library/PlatformBootManagerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ PlatformBootManagerUnableToBoot (
VOID
);

VOID
EFIAPI
SetPrimaryVideoOutput (
);
#endif
9 changes: 9 additions & 0 deletions MdeModulePkg/Universal/BdsDxe/BdsEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ BdsEntry (
EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_STATUS BootManagerMenuStatus;
EFI_BOOT_MANAGER_LOAD_OPTION PlatformDefaultBootOption;
EFI_EVENT Event;

HotkeyTriggered = NULL;
Status = EFI_SUCCESS;
Expand Down Expand Up @@ -981,6 +982,14 @@ BdsEntry (
ASSERT_EFI_ERROR (Status);
}

Status = EfiCreateEventReadyToBootEx (
TPL_CALLBACK,
SetPrimaryVideoOutput,
NULL,
&Event
);
ASSERT_EFI_ERROR (Status);

//
// Launch Boot Manager Menu directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
//
Expand Down
190 changes: 190 additions & 0 deletions UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#include "PlatformBootManager.h"
#include "PlatformConsole.h"
#include <Library/FrameBufferBltLib.h>
#include <Library/UefiBootManagerLib.h>
#include <string.h>
#include <Guid/BoardSettingsGuid.h>

#define PCIE_SLOT1 L"PciRoot(0x0)/Pci(0x1B" //Wildcard
#define PCIE_SLOT2 L"PciRoot(0x0)/Pci(0x1,0x0)"
#define PCIE_SLOT3 L"PciRoot(0x0)/Pci(0x1C,0x0)"
#define PCIE_SLOT4 L"PciRoot(0x0)/Pci(0x1,0x2)"
#define PCIE_SLOT5 L"PciRoot(0x0)/Pci(0x1D,0x0)"
#define PCIE_SLOT6 L"PciRoot(0x0)/Pci(0x1,0x1)"
#define GRAPHICS_IGD_OUTPUT L"PciRoot(0x0)/Pci(0x2,0x0)"
#define GRAPHICS_KVM_OUTPUT L"PciRoot(0x0)/Pci(0x1D,0x6)"

VOID
InstallReadyToLock (
Expand Down Expand Up @@ -211,6 +224,183 @@ ConnectRootBridge (
return Status;
}

EFI_GRAPHICS_OUTPUT_PROTOCOL *mGop = NULL;

VOID
EFIAPI
SetPrimaryVideoOutput(
VOID
)
{
EFI_STATUS Status;
UINTN HandleCount;
EFI_HANDLE *Handle;
UINTN Index;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
CHAR16 *Str;
BOARD_SETTINGS BoardSettings;
UINTN BoardSettingsSize;

Handle = NULL;
Index = 0;
BoardSettingsSize = sizeof(BOARD_SETTINGS);

DEBUG ((EFI_D_ERROR, "SetPrimaryVideoOutput\n"));

// Fetch Board Settings
Status = gRT->GetVariable(BOARD_SETTINGS_NAME,
&gEfiBoardSettingsVariableGuid,
NULL,
&BoardSettingsSize,
&BoardSettings);

if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "Fetching Board Settings errored with %x\n", Status));
return;
}

// Locate all GOPs
Status = gBS->LocateHandleBuffer(ByProtocol,
&gEfiGraphicsOutputProtocolGuid,
NULL,
&HandleCount,
&Handle);

if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "Fetching handles errored with %x\n", Status));
return;
}

DEBUG ((EFI_D_INFO, "Amount of Handles: %x\n", HandleCount));

// Loop through all GOPs to find the primary one
for (Index=0; Index < HandleCount; Index++) {
// Get Device Path of GOP
Status = gBS->HandleProtocol (Handle[Index], &gEfiDevicePathProtocolGuid, (VOID*)&TempDevicePath);
if (EFI_ERROR (Status)) {
continue;
}
// Get Protocol of GOP
Status = gBS->HandleProtocol (Handle[Index], &gEfiGraphicsOutputProtocolGuid, (VOID**)&mGop);
if (EFI_ERROR (Status)) {
continue;
}

Str = ConvertDevicePathToText(TempDevicePath, FALSE, TRUE);
DEBUG ((EFI_D_INFO, "Current Device: %s\n", Str));
// Check which GOP should be enabled
if ((!StrnCmp(Str, GRAPHICS_KVM_OUTPUT, StrLen(GRAPHICS_KVM_OUTPUT))) && (HandleCount > 2)) {
DEBUG ((EFI_D_INFO, "Found the KVM Device.."));
// If Primary Video not KVM - disable.
if (BoardSettings.PrimaryVideo != 0) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}
DEBUG ((EFI_D_INFO, "\n"));
} else if (!StrnCmp(Str, GRAPHICS_IGD_OUTPUT, StrLen(GRAPHICS_IGD_OUTPUT))) {
DEBUG ((EFI_D_INFO, "Found the IGD Device.."));
// If Primary Video not IGD - disable.
if (BoardSettings.PrimaryVideo != 1) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}
DEBUG ((EFI_D_INFO, "\n"));
} else if
(!StrnCmp(Str, PCIE_SLOT1, StrLen(PCIE_SLOT1)))
{
DEBUG ((EFI_D_INFO, "Found PCI SLOT1 Graphics Device.."));
// If Primary Video not PCI - disable.
if (BoardSettings.PrimaryVideo != 2) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}
DEBUG ((EFI_D_INFO, "\n"));
} else if
(!StrnCmp(Str, PCIE_SLOT2, StrLen(PCIE_SLOT2)))
{
DEBUG ((EFI_D_INFO, "Found PCI SLOT2 Graphics Device.."));
// If Primary Video not PEG - disable.
if (BoardSettings.PrimaryVideo != 3) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}

DEBUG ((EFI_D_INFO, "\n"));
} else if
(!StrnCmp(Str, PCIE_SLOT3, StrLen(PCIE_SLOT3)))
{
DEBUG ((EFI_D_INFO, "Found PCI SLOT3 Graphics Device.."));
// If Primary Video not PEG - disable.
if (BoardSettings.PrimaryVideo != 4) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}

DEBUG ((EFI_D_INFO, "\n"));
} else if
(!StrnCmp(Str, PCIE_SLOT4, StrLen(PCIE_SLOT4)))
{
DEBUG ((EFI_D_INFO, "Found PCI SLOT4 Graphics Device.."));
// If Primary Video not PEG - disable.
if (BoardSettings.PrimaryVideo != 5) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}

DEBUG ((EFI_D_INFO, "\n"));
} else if
(!StrnCmp(Str, PCIE_SLOT5, StrLen(PCIE_SLOT5)))
{
DEBUG ((EFI_D_INFO, "Found PCI SLOT5 Graphics Device.."));
// If Primary Video not PEG - disable.
if (BoardSettings.PrimaryVideo != 6) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}

DEBUG ((EFI_D_INFO, "\n"));
} else if
(!StrnCmp(Str, PCIE_SLOT6, StrLen(PCIE_SLOT6)))
{
DEBUG ((EFI_D_INFO, "Found PCI SLOT2 Graphics Device.."));
// If Primary Video not PEG - disable.
if (BoardSettings.PrimaryVideo != 7) {
DEBUG ((EFI_D_INFO, "Disabling"));
Status = gBS->UninstallProtocolInterface(Handle[Index], &gEfiGraphicsOutputProtocolGuid, mGop);
if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "Uninstalling Handle errored with %x\n", Status));
}
}

DEBUG ((EFI_D_INFO, "\n"));
}

} // for loop

return;
}

/**
Do the platform specific action before the console is connected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

[Guids]
gEfiEndOfDxeEventGroupGuid
gEfiBoardSettingsVariableGuid

[Protocols]
gEfiGenericMemTestProtocolGuid ## CONSUMES
Expand All @@ -59,6 +60,7 @@
gEfiDxeSmmReadyToLockProtocolGuid
gEfiSmmAccess2ProtocolGuid
gEfiPciRootBridgeIoProtocolGuid ## CONSUMES
gEfiDevicePathProtocolGuid ## CONSUMES

[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut
Expand Down
Binary file modified UefiPayloadPkg/NetworkDrivers/ipxe.efi
Binary file not shown.
3 changes: 1 addition & 2 deletions UefiPayloadPkg/SmbusConfigLoaderDxe/SMBusConfigLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ReadBoardOptionFromEEPROM (
DEBUG ((EFI_D_ERROR, "Failed to read SMBUS byte at offset 0x%x\n", Index));
continue;
}
DEBUG (( EFI_D_ERROR, "Read %x\n", Value));
CopyMem(&Buffer[Index-BOARD_SETTINGS_OFFSET], &Value, sizeof(Value));
}
}
Expand Down Expand Up @@ -129,7 +128,7 @@ InstallSMBusConfigLoader (

CRC32Array = CalculateCrc32(&Array[4], BOARD_SETTINGS_SIZE - 4);
if (CRC32Array != BoardSettings.Signature) {
DEBUG ((EFI_D_ERROR, "SMBusConfigLoader: Checksum invalid. Reseting to defaults."));
DEBUG ((EFI_D_ERROR, "SMBusConfigLoader: Checksum invalid. Should be %04X - is: %04x.\nReseting to defaults.\n", CRC32Array, BoardSettings.Signature));
BoardSettings.PrimaryVideo = 0;
BoardSettings.SecureBoot = 1;
}
Expand Down

0 comments on commit 4e181db

Please sign in to comment.