From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by mx.groups.io with SMTP id smtpd.web11.20220.1644228071672383549 for ; Mon, 07 Feb 2022 02:01:12 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@9elements.com header.s=google header.b=Pl6lD9s8; spf=pass (domain: 9elements.com, ip: 209.85.218.46, mailfrom: patrick.rudolph@9elements.com) Received: by mail-ej1-f46.google.com with SMTP id m4so40469508ejb.9 for ; Mon, 07 Feb 2022 02:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DDeKmv6IowpTlDE8xxeaki0xcqo14kqhjDeEQ1R0ScM=; b=Pl6lD9s8uzLfn4b50/ky8dOhgqfhfROp+wdYifOSzfy+PKEBfglKAyy6mhrxRl27A0 ZYMv2I/EFVSONjfbb9xZhZiQVaUv/7cYEhILVqiFHveIx09V5/Miju5qr/3dUH7493a1 X249Xff2ORwhS1D8hjVEkPjmGu+CrK/Om1zOOT07ediL9Q+0hAzNhII/MGqiKOC5ghlc DVAfciD8ctO8TEwK3M396JxP2sTS7+vWUmbet/b/LURiGMf5WywDal1vZK2VmMmmwLKp 9MqKbaZz96ZL57MEH1ERIk78Y7VN6d64cD+p4NVwzkGWyAmW35J3ATptJph65QWBnXGI DxRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DDeKmv6IowpTlDE8xxeaki0xcqo14kqhjDeEQ1R0ScM=; b=KqwOY/Ga5rn87nKwbEcHU+Q2HcuXYlhKnA9kPDGDJ5TS/T7fll+0YJIcqfiePU7OSL i0Cycggu4GJ0upzZQwv+Pj2LbRLLZ8QRz6ptxWc5d2X+FSxkps4i5vgp6rodKjmaCBTH G3cJCzclOVmPsqUKefkH+7M78ZQTa6YS49hQg0q+Cw0nBIFlhf4sIwsTC0lwfHISQzP2 rTbIC9XGNsvr4yssQ88jcPAe5HRLFfs0uNradh+s2Tq9KbalkYlsMHTatvjqsosYIexz KGY+qqHJhY9XIlsyIgfWZCGW5eRO4Se3I4vnWljyAqS3Hlceznbvy0COaDXCKAeZ2wIw 6grg== X-Gm-Message-State: AOAM530FqTG13UTNhLtFK4ipbdDh5AEXyunGL/x2L+2AMKKANEv8MTdK p/qTXltNSB+s+upsiJnh1ursO8oym3bQ1Q== X-Google-Smtp-Source: ABdhPJzZv9z49AteAVtsevl7xY6vqQ57wvQx1LGJQsA8LnUOJ6M88O8YaK6fy3xO7sJsJQcgWjueBw== X-Received: by 2002:a17:906:cc54:: with SMTP id mm20mr8991269ejb.313.1644228070206; Mon, 07 Feb 2022 02:01:10 -0800 (PST) Return-Path: Received: from fedora.. (ip-088-153-139-166.um27.pools.vodafone-ip.de. [88.153.139.166]) by smtp.gmail.com with ESMTPSA id en9sm341731edb.71.2022.02.07.02.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 02:01:09 -0800 (PST) From: "Patrick Rudolph" To: devel@edk2.groups.io Cc: ray.ni@intel.com, maurice.ma@intel.com, benjamin.you@intel.com, guo.dong@intel.com Subject: [edk2-platform][PATCH] UefiPayloadPkg: Fix PciHostBridgeLib Date: Mon, 7 Feb 2022 11:01:08 +0100 Message-Id: <20220207100108.108899-1-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On modern platforms with TBT devices the coreboot resource allocator opens large PCI bridge MMIO windows above 4GiB to place hotplugable PCI BARs there as they won't fit below 4GiB. In addition modern GPGPU devices have very big PCI bars that doesn't fit below 4GiB. The PciHostBridgeLib made lots of assumptions about the coreboot resource allocator that were not verified at runtime and are no longer true. Remove all of the 'coreboot specific' code and implement the same logic as OvmfPkg's ScanForRootBridges. Fixes assertion "ASSERT [PciHostBridgeDxe] Bridge->Mem.Limit < 0x0000000100000000ULL". Tested with coreboot as bootloader on platforms that have PCI resources above 4GiB and on platforms that don't have resources above 4GiB. Signed-off-by: Patrick Rudolph --- UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c | 137 +++--= --------------- 1 file changed, 18 insertions(+), 119 deletions(-) diff --git a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c= b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c index bf2d10f4bf..8a890b6b53 100644 --- a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c +++ b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c @@ -18,92 +18,6 @@ #include =0D #include "PciHostBridge.h"=0D =0D -/**=0D - Adjust the collected PCI resource.=0D -=0D - @param[in] Io IO aperture.=0D -=0D - @param[in] Mem MMIO aperture.=0D -=0D - @param[in] MemAbove4G MMIO aperture above 4G.=0D -=0D - @param[in] PMem Prefetchable MMIO aperture.=0D -=0D - @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.=0D -**/=0D -VOID=0D -AdjustRootBridgeResource (=0D - IN PCI_ROOT_BRIDGE_APERTURE *Io,=0D - IN PCI_ROOT_BRIDGE_APERTURE *Mem,=0D - IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,=0D - IN PCI_ROOT_BRIDGE_APERTURE *PMem,=0D - IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G=0D - )=0D -{=0D - UINT64 Mask;=0D -=0D - //=0D - // For now try to downgrade everything into MEM32 since=0D - // - coreboot does not assign resource above 4GB=0D - // - coreboot might allocate interleaved MEM32 and PMEM32 resource=0D - // in some cases=0D - //=0D - if (PMem->Base < Mem->Base) {=0D - Mem->Base =3D PMem->Base;=0D - }=0D -=0D - if (PMem->Limit > Mem->Limit) {=0D - Mem->Limit =3D PMem->Limit;=0D - }=0D -=0D - PMem->Base =3D MAX_UINT64;=0D - PMem->Limit =3D 0;=0D -=0D - if (MemAbove4G->Base < 0x100000000ULL) {=0D - if (MemAbove4G->Base < Mem->Base) {=0D - Mem->Base =3D MemAbove4G->Base;=0D - }=0D -=0D - if (MemAbove4G->Limit > Mem->Limit) {=0D - Mem->Limit =3D MemAbove4G->Limit;=0D - }=0D -=0D - MemAbove4G->Base =3D MAX_UINT64;=0D - MemAbove4G->Limit =3D 0;=0D - }=0D -=0D - if (PMemAbove4G->Base < 0x100000000ULL) {=0D - if (PMemAbove4G->Base < Mem->Base) {=0D - Mem->Base =3D PMemAbove4G->Base;=0D - }=0D -=0D - if (PMemAbove4G->Limit > Mem->Limit) {=0D - Mem->Limit =3D PMemAbove4G->Limit;=0D - }=0D -=0D - PMemAbove4G->Base =3D MAX_UINT64;=0D - PMemAbove4G->Limit =3D 0;=0D - }=0D -=0D - //=0D - // Align IO resource at 4K boundary=0D - //=0D - Mask =3D 0xFFFULL;=0D - Io->Limit =3D ((Io->Limit + Mask) & ~Mask) - 1;=0D - if (Io->Base !=3D MAX_UINT64) {=0D - Io->Base &=3D ~Mask;=0D - }=0D -=0D - //=0D - // Align MEM resource at 1MB boundary=0D - //=0D - Mask =3D 0xFFFFFULL;=0D - Mem->Limit =3D ((Mem->Limit + Mask) & ~Mask) - 1;=0D - if (Mem->Base !=3D MAX_UINT64) {=0D - Mem->Base &=3D ~Mask;=0D - }=0D -}=0D -=0D /**=0D Probe a bar is existed or not.=0D =0D @@ -114,28 +28,24 @@ AdjustRootBridgeResource ( STATIC=0D VOID=0D PcatPciRootBridgeBarExisted (=0D - IN UINT64 Address,=0D + IN UINTN Address,=0D OUT UINT32 *OriginalValue,=0D OUT UINT32 *Value=0D )=0D {=0D - UINTN PciAddress;=0D -=0D - PciAddress =3D (UINTN)Address;=0D -=0D //=0D // Preserve the original value=0D //=0D - *OriginalValue =3D PciRead32 (PciAddress);=0D + *OriginalValue =3D PciRead32 (Address);=0D =0D //=0D // Disable timer interrupt while the BAR is probed=0D //=0D DisableInterrupts ();=0D =0D - PciWrite32 (PciAddress, 0xFFFFFFFF);=0D - *Value =3D PciRead32 (PciAddress);=0D - PciWrite32 (PciAddress, *OriginalValue);=0D + PciWrite32 (Address, 0xFFFFFFFF);=0D + *Value =3D PciRead32 (Address);=0D + PciWrite32 (Address, *OriginalValue);=0D =0D //=0D // Enable interrupt=0D @@ -179,9 +89,7 @@ PcatPciRootBridgeParseBars ( IN UINTN BarOffsetEnd,=0D IN PCI_ROOT_BRIDGE_APERTURE *Io,=0D IN PCI_ROOT_BRIDGE_APERTURE *Mem,=0D - IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,=0D - IN PCI_ROOT_BRIDGE_APERTURE *PMem,=0D - IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G=0D + IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G=0D =0D )=0D {=0D @@ -246,11 +154,7 @@ PcatPciRootBridgeParseBars ( //=0D Length =3D ((~Length) + 1) & 0xffffffff;=0D =0D - if ((Value & BIT3) =3D=3D BIT3) {=0D - MemAperture =3D PMem;=0D - } else {=0D - MemAperture =3D Mem;=0D - }=0D + MemAperture =3D Mem;=0D } else {=0D //=0D // 64bit=0D @@ -269,8 +173,8 @@ PcatPciRootBridgeParseBars ( Length =3D LShiftU64 (1ULL, LowBit);=0D }=0D =0D - if ((Value & BIT3) =3D=3D BIT3) {=0D - MemAperture =3D PMemAbove4G;=0D + if (Base < BASE_4GB) {=0D + MemAperture =3D Mem;=0D } else {=0D MemAperture =3D MemAbove4G;=0D }=0D @@ -291,6 +195,8 @@ PcatPciRootBridgeParseBars ( }=0D }=0D =0D +STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture =3D { MAX_UINT64, 0 };= =0D +=0D /**=0D Scan for all root bridges in platform.=0D =0D @@ -317,8 +223,6 @@ ScanForRootBridges ( PCI_ROOT_BRIDGE_APERTURE Io;=0D PCI_ROOT_BRIDGE_APERTURE Mem;=0D PCI_ROOT_BRIDGE_APERTURE MemAbove4G;=0D - PCI_ROOT_BRIDGE_APERTURE PMem;=0D - PCI_ROOT_BRIDGE_APERTURE PMemAbove4G;=0D PCI_ROOT_BRIDGE_APERTURE *MemAperture;=0D PCI_ROOT_BRIDGE *RootBridges;=0D UINTN BarOffsetEnd;=0D @@ -338,9 +242,7 @@ ScanForRootBridges ( ZeroMem (&Io, sizeof (Io));=0D ZeroMem (&Mem, sizeof (Mem));=0D ZeroMem (&MemAbove4G, sizeof (MemAbove4G));=0D - ZeroMem (&PMem, sizeof (PMem));=0D - ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G));=0D - Io.Base =3D Mem.Base =3D MemAbove4G.Base =3D PMem.Base =3D PMemAbove4G= .Base =3D MAX_UINT64;=0D + Io.Base =3D Mem.Base =3D MemAbove4G.Base =3D MAX_UINT64;=0D //=0D // Scan all the PCI devices on the primary bus of the PCI root bridge= =0D //=0D @@ -446,16 +348,17 @@ ScanForRootBridges ( =0D //=0D // Get the Prefetchable Memory range that the PPB is decoding=0D + // and merge it into Memory range=0D //=0D Value =3D Pci.Bridge.PrefetchableMemoryBase & 0x0f;=0D Base =3D ((UINT32)Pci.Bridge.PrefetchableMemoryBase & 0xfff0) <= < 16;=0D Limit =3D (((UINT32)Pci.Bridge.PrefetchableMemoryLimit & 0xfff0)= =0D << 16) | 0xfffff;=0D - MemAperture =3D &PMem;=0D + MemAperture =3D &Mem;=0D if (Value =3D=3D BIT0) {=0D Base |=3D LShiftU64 (Pci.Bridge.PrefetchableBaseUpper32,= 32);=0D Limit |=3D LShiftU64 (Pci.Bridge.PrefetchableLimitUpper32= , 32);=0D - MemAperture =3D &PMemAbove4G;=0D + MemAperture =3D &MemAbove4G;=0D }=0D =0D if ((Base > 0) && (Base < Limit)) {=0D @@ -513,9 +416,7 @@ ScanForRootBridges ( BarOffsetEnd,=0D &Io,=0D &Mem,=0D - &MemAbove4G,=0D - &PMem,=0D - &PMemAbove4G=0D + &MemAbove4G=0D );=0D =0D //=0D @@ -593,8 +494,6 @@ ScanForRootBridges ( );=0D ASSERT (RootBridges !=3D NULL);=0D =0D - AdjustRootBridgeResource (&Io, &Mem, &MemAbove4G, &PMem, &PMemAbove4= G);=0D -=0D InitRootBridge (=0D Attributes,=0D Attributes,=0D @@ -604,8 +503,8 @@ ScanForRootBridges ( &Io,=0D &Mem,=0D &MemAbove4G,=0D - &PMem,=0D - &PMemAbove4G,=0D + &mNonExistAperture,=0D + &mNonExistAperture,=0D &RootBridges[*NumberOfRootBridges]=0D );=0D RootBridges[*NumberOfRootBridges].ResourceAssigned =3D TRUE;=0D --=20 2.34.1