From eedcdea6104f6740517ab3fa7b97aaa2a7dbad4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=BBygowski?= Date: Mon, 13 Apr 2026 17:56:06 +0200 Subject: [PATCH] DasharoPayloadPkg: Add support for AMD GOP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modern AMD platforms cannot initialize graphics in 32bit mode (using PEI GOP or VBIOS), because of UMA memory allocation above 4G by default. One would have to force the recovery path so that UMA is allocated below 4G. To allow running AMD x64 GOP, some modifications are needed. Firstly, the GOP still needs VBIOS, so PCI IO must provide it from FFS. Then, the GOP driver must also be included in the FFS, so that DXE dispatcher picks it up and runs it. TEST=Successfully initialize integrated graphics on MSI PRO B850-P WIFI. Signed-off-by: Michał Żygowski --- DasharoPayloadPkg/DasharoPayloadPkg.dec | 5 + DasharoPayloadPkg/DasharoPayloadPkg.dsc | 7 +- DasharoPayloadPkg/DasharoPayloadPkg.fdf | 12 +- .../PciPlatformDxe/PciPlatformDxe.c | 131 ++++++++++++++++++ .../PciPlatformDxe/PciPlatformDxe.inf | 4 + 5 files changed, 155 insertions(+), 4 deletions(-) diff --git a/DasharoPayloadPkg/DasharoPayloadPkg.dec b/DasharoPayloadPkg/DasharoPayloadPkg.dec index 6922ad9574..3a54ee7266 100644 --- a/DasharoPayloadPkg/DasharoPayloadPkg.dec +++ b/DasharoPayloadPkg/DasharoPayloadPkg.dec @@ -70,6 +70,8 @@ gDasharoPayloadPkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x gDasharoPayloadPkgTokenSpaceGuid.PcdiPXEFile|{ 0xC7, 0x53, 0x86, 0xb6, 0xA1, 0xEE, 0x35, 0x44, 0xA1, 0x99, 0xA4, 0x4F, 0x59, 0xE4, 0x47, 0x6C }|VOID*|0x10000006 gDasharoPayloadPkgTokenSpaceGuid.PcdiPXEOptionName|L"iPXE"|VOID*|0x10000007 +# FFS file name to find VBIOS +gDasharoPayloadPkgTokenSpaceGuid.AmdVbiosOptionRomFileName|{ 0x34, 0x9a, 0x8a, 0xc3, 0x05, 0x20, 0x6e, 0x49, 0x94, 0xf2, 0x8e, 0x10, 0x20, 0xb8, 0xfc, 0x6e }|VOID*|0x10000008 ## Used to help reduce fragmentation in the EFI memory map gDasharoPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0x08|UINT32|0x10000012 @@ -103,3 +105,6 @@ gDasharoPayloadPkgTokenSpaceGuid.PcdPrintSolStrings|FALSE|BOOLEAN|0x0000000A gDasharoPayloadPkgTokenSpaceGuid.PcdSerialOnSuperIo|FALSE|BOOLEAN|0x0000000B gDasharoPayloadPkgTokenSpaceGuid.PcdShowCapsuleReport|FALSE|BOOLEAN|0x0000000C + +gDasharoPayloadPkgTokenSpaceGuid.AmdVbiosOptionRomVendorId|0|UINT16|0x0000000D +gDasharoPayloadPkgTokenSpaceGuid.AmdVbiosOptionRomDeviceId|0|UINT16|0x0000000E diff --git a/DasharoPayloadPkg/DasharoPayloadPkg.dsc b/DasharoPayloadPkg/DasharoPayloadPkg.dsc index 45bce1bf26..c57028e111 100644 --- a/DasharoPayloadPkg/DasharoPayloadPkg.dsc +++ b/DasharoPayloadPkg/DasharoPayloadPkg.dsc @@ -111,12 +111,16 @@ DEFINE RAM_DISK_ENABLE = FALSE DEFINE APU_CONFIG_ENABLE = FALSE DEFINE USE_PLATFORM_GOP = FALSE + DEFINE USE_AMD_PLATFORM_GOP = FALSE DEFINE USE_LAPTOP_LID_LIB = FALSE DEFINE USE_UEFIVAR_BACKED_TPM_PPI = FALSE DEFINE CAPSULE_SUPPORT = FALSE DEFINE CAPSULE_MAIN_FW_GUID = DEFINE GRAPHICAL_CAPSULE_PROGRESS = TRUE + DEFINE AMD_GOP_DRIVER_GUID = 2C4CB22B-E0F8-4457-A238-576A3D0201D6 + DEFINE AMD_GOP_VBIOS_GUID = C38A9A34-2005-496E-94F2-8E1020B8FC6E + # # Network definition # @@ -972,11 +976,10 @@ OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrd !if $(USE_PLATFORM_GOP) == TRUE DasharoPayloadPkg/PlatformGopPolicy/PlatformGopPolicy.inf -!else +!elseif $(USE_AMD_PLATFORM_GOP) == FALSE DasharoPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf !endif - # # Network Support # diff --git a/DasharoPayloadPkg/DasharoPayloadPkg.fdf b/DasharoPayloadPkg/DasharoPayloadPkg.fdf index 3d921f53fd..77a6538bac 100644 --- a/DasharoPayloadPkg/DasharoPayloadPkg.fdf +++ b/DasharoPayloadPkg/DasharoPayloadPkg.fdf @@ -208,12 +208,20 @@ FILE FREEFORM = 878AC2CC-5343-46F2-B563-51F89DAF56BA { SECTION RAW = DasharoPayloadPkg/vbt.bin SECTION UI = "IntelGopVbt" } +!elseif $(USE_AMD_PLATFORM_GOP) == TRUE +!if "X64" in $(ARCH) +FILE DRIVER = $(AMD_GOP_DRIVER_GUID) { + SECTION PE32 = DasharoPayloadPkg/AmdGopDriver.efi + SECTION UI = "AmdGopDriver" +} +FILE FREEFORM = $(AMD_GOP_VBIOS_GUID) { + SECTION RAW = DasharoPayloadPkg/Vbios.bin +} +!endif !else INF DasharoPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf !endif - - # # SCSI/ATA/IDE/DISK Support # diff --git a/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.c b/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.c index 2c1ff401b8..0f0ed7d73f 100644 --- a/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.c +++ b/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.c @@ -10,6 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "PciPlatformDxe.h" #include #include +#include #include #include @@ -144,6 +145,127 @@ ShouldLoadOptionRom ( return FALSE; } +EFI_STATUS +GetPciRomFromFv ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + OUT VOID **RomImage, + OUT UINTN *RomSize + ) +{ + EFI_STATUS Status; + UINT16 VendorId; + UINT16 DeviceId; + UINT16 OffsetPcir; + UINT8 *RomBarOffset; + BOOLEAN FirstCheck; + PCI_EXPANSION_ROM_HEADER *RomHeader; + PCI_DATA_STRUCTURE *RomPcir; + UINT64 RomImageSize; + UINT32 LegacyImageLength; + UINT8 CodeType; + UINT8 Indicator; + + if (FixedPcdGet16(AmdVbiosOptionRomVendorId) == 0 || + FixedPcdGet16(AmdVbiosOptionRomDeviceId) == 0) { + return EFI_NOT_FOUND; + } + + PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0, 1, &VendorId); + PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 2, 1, &DeviceId); + + DEBUG ((DEBUG_INFO, "GetPciRomFromFV for Vid %04X, Did: %04X\n", VendorId, DeviceId)); + + if (VendorId != FixedPcdGet16(AmdVbiosOptionRomVendorId) || + DeviceId != FixedPcdGet16(AmdVbiosOptionRomDeviceId)) { + return EFI_NOT_FOUND; + } + + Status = GetSectionFromFv ( + (CONST EFI_GUID *)PcdGetPtr(AmdVbiosOptionRomFileName), + EFI_SECTION_RAW, + 0, + RomImage, + RomSize + ); + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_INFO, "GetPciRomFromFV for Vid %04X, Did: %04X Status: %r\n", + VendorId, DeviceId, Status)); + return Status; + } + + DEBUG ((DEBUG_INFO, "GetPciRomFromFV for Vid %04X, Did: %04X ==> RomImage: %llx, Size %llx\n", + VendorId, DeviceId, *RomImage, *RomSize)); + + + FirstCheck = TRUE; + LegacyImageLength = 0; + RomImageSize = 0; + RomBarOffset = (UINT8 *)*RomImage; + + do { + if ((*RomSize - RomImageSize) < sizeof(PCI_EXPANSION_ROM_HEADER)) { + break; + } + + RomHeader = (PCI_EXPANSION_ROM_HEADER *)RomBarOffset; + DEBUG ((EFI_D_INFO, "%a: RomHeader->Signature %x\n", __FUNCTION__, RomHeader->Signature)); + if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) { + RomBarOffset = RomBarOffset + 512; + if (FirstCheck) { + break; + } else { + RomImageSize = RomImageSize + 512; + continue; + } + } + + FirstCheck = FALSE; + OffsetPcir = RomHeader->PcirOffset; + // + // If the pointer to the PCI Data Structure is invalid, no further images can be located. + // The PCI Data Structure must be DWORD aligned. + // + if (OffsetPcir == 0 || + (OffsetPcir & 3) != 0 || + RomImageSize + OffsetPcir + sizeof (PCI_DATA_STRUCTURE) > *RomSize) { + break; + } + + RomPcir = (PCI_DATA_STRUCTURE *)(RomBarOffset + OffsetPcir); + + DEBUG ((EFI_D_INFO, "%a: RomPcir->Signature %x\n", __FUNCTION__, RomPcir->Signature)); + + // + // If a valid signature is not present in the PCI Data Structure, no further images can be located. + // + if (RomPcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) { + break; + } + if (RomImageSize + RomPcir->ImageLength * 512 > *RomSize) { + break; + } + if (RomPcir->CodeType == PCI_CODE_TYPE_PCAT_IMAGE) { + CodeType = PCI_CODE_TYPE_PCAT_IMAGE; + LegacyImageLength = ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)RomHeader)->Size512) * 512; + } + Indicator = RomPcir->Indicator; + RomImageSize = RomImageSize + RomPcir->ImageLength * 512; + RomBarOffset = RomBarOffset + RomPcir->ImageLength * 512; + } while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - (UINT8 *)(*RomImage)) < *RomSize)); + + // + // Some Legacy Cards do not report the correct ImageLength so used the maximum + // of the legacy length and the PCIR Image Length + // + if (CodeType == PCI_CODE_TYPE_PCAT_IMAGE) { + RomImageSize = MAX (RomImageSize, LegacyImageLength); + } + + *RomSize = RomImageSize; + + return EFI_SUCCESS; +} + EFI_STATUS EFIAPI PciGetPciRom ( @@ -215,6 +337,15 @@ PciGetPciRom ( DEBUG ((EFI_D_INFO, " PciDevice - %02x\n", PciDevice)); DEBUG ((EFI_D_INFO, " PciFunction - %02x\n", PciFunction)); + + if (!EFI_ERROR (GetPciRomFromFv (PciIo, RomImage, RomSize))) { + PciIoDevice->EmbeddedRom = FALSE; + PciIoDevice->PciIo.RomSize = *RomSize; + PciIoDevice->PciIo.RomImage = *RomImage; + + return EFI_SUCCESS; + } + // // 0x30 // diff --git a/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf b/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf index 31aca0adef..0ac612b2aa 100644 --- a/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf +++ b/DasharoPayloadPkg/PciPlatformDxe/PciPlatformDxe.inf @@ -36,6 +36,7 @@ UefiDriverEntryPoint UefiBootServicesTableLib UefiRuntimeServicesTableLib + DxeServicesLib DxeServicesTableLib DebugLib MemoryAllocationLib @@ -55,3 +56,6 @@ [Pcd] gDasharoPayloadPkgTokenSpaceGuid.PcdLoadOptionRoms gEfiMdePkgTokenSpaceGuid.PcdFastBootFeatureEnabled + gDasharoPayloadPkgTokenSpaceGuid.AmdVbiosOptionRomVendorId + gDasharoPayloadPkgTokenSpaceGuid.AmdVbiosOptionRomDeviceId + gDasharoPayloadPkgTokenSpaceGuid.AmdVbiosOptionRomFileName