From nobody Mon May 6 12:53:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+56901+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56901+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1585831048; cv=none; d=zohomail.com; s=zohoarc; b=PwHPUmv30MN0IgL5IrI2fjj8F8yHR1yqfOMGmZQXnDKTUpYPsfMX4e/utLGBHBXVAsDXiU6PDN+VT9terV06kgazYZBfjYik2pLHPWfMwsub1cgsjA/zMwohIh1xCzk058QY28lC6U6vT0LR4uGoGhTX5wpL51KJF83K2bGav/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585831048; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Fp3hxvULBJH58Y0OgXlBhB1Uo52mZuBL7GVbGaDFe8c=; b=E8i8Bybm8Ov7rqiaDYf0NHE5MPNswcTN+9rA9wLWR7dw21D0uwygFz6pClvUpnqh5NeprGPzKEHiHWVh4c8TnTlFDwsJZo/NuIZ19fKTrTJ5YXUDTCInyHjb//hqgYCfiLgAQtX/cx4w6QeIfaa8CWplfYvyRbr05Gtcoxix9/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+56901+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1585831048512339.80472379012065; Thu, 2 Apr 2020 05:37:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YgOxYY1788612xh264bUEEf5; Thu, 02 Apr 2020 05:37:28 -0700 X-Received: from huawei.com (huawei.com [45.249.212.35]) by mx.groups.io with SMTP id smtpd.web10.5115.1585829304579309563 for ; Thu, 02 Apr 2020 05:08:25 -0700 X-Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B9E82C7EC6FC15A02DA7; Thu, 2 Apr 2020 20:08:21 +0800 (CST) X-Received: from DESKTOP-D7EVK5B.china.huawei.com (10.173.221.29) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Thu, 2 Apr 2020 20:08:14 +0800 From: Yubo Miao To: , , CC: , , Subject: [edk2-devel] [PATCH] ArmVirtPkg/FdtPciHostBridgeLib: add extra roots for Arm. Date: Thu, 2 Apr 2020 20:08:03 +0800 Message-ID: <20200402120803.1482-1-miaoyubo@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.221.29] X-CFilter-Loop: Reflected Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,miaoyubo@huawei.com X-Gm-Message-State: wMlFGeXyvKPKjKtt1ImdN2d9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1585831048; bh=v3UV1UUPB8y3J+wE+/iNRpcu82eFT0mJM3CkOuxX+pk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SQggVqxZnFypPcoqXIEReSx1buzH1ZnZxR5LDZDPgNcptzGbiYhWE1oDjfoz4misRM4 O+dRLueUGRUGJKOk2v6GIuVWP2Y6xiyP42IF9SwrSTgkeG9X4cfjhJVgtqA5w5GQlP+WO bLaOJC9aBTJfc4Aa2OxPFSziHXNp3ST/yng= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: miaoyubo Add support for extra roots for arm, in this patch, we import the scan for extra root buses therefore the uefi could recognize multiply roots for arm. The logic keeps the same with the logic in "OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c" Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: miaoyubo --- .../FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 264 +++++++++++++++--- .../FdtPciHostBridgeLib.inf | 3 + 2 files changed, 230 insertions(+), 37 deletions(-) diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b= /ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 496b192d22..706efeb416 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -14,6 +14,10 @@ #include #include #include +#include +#include +#include +#include =20 #include #include @@ -306,7 +310,70 @@ ProcessPciHost ( return Status; } =20 -STATIC PCI_ROOT_BRIDGE mRootBridge; +EFI_STATUS +InitRootBridge ( + IN UINT64 Supports, + IN UINT64 Attributes, + IN UINT64 AllocAttributes, + IN UINT8 RootBusNumber, + IN UINT8 MaxSubBusNumber, + IN PCI_ROOT_BRIDGE_APERTURE *Io, + IN PCI_ROOT_BRIDGE_APERTURE *Mem, + IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G, + IN PCI_ROOT_BRIDGE_APERTURE *PMem, + IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G, + OUT PCI_ROOT_BRIDGE *RootBus + ) +{ + EFI_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath; + + // + // Be safe if other fields are added to PCI_ROOT_BRIDGE later. + // + ZeroMem (RootBus, sizeof *RootBus); + + RootBus->Segment =3D 0; + RootBus->ResourceAssigned =3D FALSE; + RootBus->Supports =3D Supports; + RootBus->Attributes =3D Attributes; + + RootBus->DmaAbove4G =3D TRUE; + + RootBus->AllocationAttributes =3D AllocAttributes; + RootBus->Bus.Base =3D RootBusNumber; + RootBus->Bus.Limit =3D MaxSubBusNumber; + CopyMem (&RootBus->Io, Io, sizeof (*Io)); + CopyMem (&RootBus->Mem, Mem, sizeof (*Mem)); + CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G)); + CopyMem (&RootBus->PMem, PMem, sizeof (*PMem)); + CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G)); + + RootBus->NoExtendedConfigSpace =3D FALSE; + + DevicePath =3D AllocateCopyPool (sizeof mEfiPciRootBridgeDevicePath, + &mEfiPciRootBridgeDevicePath); + if (DevicePath =3D=3D NULL) { + DEBUG ((EFI_D_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES)); + return EFI_OUT_OF_RESOURCES; + } + DevicePath->AcpiDevicePath.UID =3D RootBusNumber; + RootBus->DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)DevicePath; + + DEBUG ((EFI_D_INFO, + "%a: populated root bus %d, with room for %d subordinate bus(es)\n", + __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber)); + return EFI_SUCCESS; +} + +STATIC +VOID +UninitRootBridge ( + IN PCI_ROOT_BRIDGE *RootBus + ) +{ + FreePool (RootBus->DevicePath); +} + =20 /** Return all the root bridge instances in an array. @@ -323,11 +390,25 @@ PciHostBridgeGetRootBridges ( UINTN *Count ) { - UINT64 IoBase, IoSize; - UINT64 Mmio32Base, Mmio32Size; - UINT64 Mmio64Base, Mmio64Size; - UINT32 BusMin, BusMax; - EFI_STATUS Status; + UINT64 IoBase, IoSize; + UINT64 Mmio32Base, Mmio32Size; + UINT64 Mmio64Base, Mmio64Size; + UINT32 BusMin, BusMax; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + UINT64 ExtraRootBridges; + PCI_ROOT_BRIDGE *Bridges; + UINTN Initialized; + UINTN LastRootBridgeNumber; + UINTN RootBridgeNumber; + UINT64 Attributes; + UINT64 AllocationAttributes; + EFI_STATUS Status; + PCI_ROOT_BRIDGE_APERTURE Io; + PCI_ROOT_BRIDGE_APERTURE PMem; + PCI_ROOT_BRIDGE_APERTURE PMemAbove4G; + PCI_ROOT_BRIDGE_APERTURE Mem; + PCI_ROOT_BRIDGE_APERTURE MemAbove4G; =20 if (PcdGet64 (PcdPciExpressBaseAddress) =3D=3D 0) { DEBUG ((EFI_D_INFO, "%a: PCI host bridge not present\n", __FUNCTION__)= ); @@ -345,33 +426,27 @@ PciHostBridgeGetRootBridges ( return NULL; } =20 - *Count =3D 1; + ZeroMem (&Io, sizeof (Io)); + ZeroMem (&Mem, sizeof (Mem)); + ZeroMem (&MemAbove4G, sizeof (MemAbove4G)); =20 - mRootBridge.Segment =3D 0; - mRootBridge.Supports =3D EFI_PCI_ATTRIBUTE_ISA_IO_16 | - EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO= | - EFI_PCI_ATTRIBUTE_VGA_IO_16 | - EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16; - mRootBridge.Attributes =3D mRootBridge.Supports; + Attributes =3D EFI_PCI_ATTRIBUTE_ISA_IO_16 | + EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO | + EFI_PCI_ATTRIBUTE_VGA_IO_16 | + EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16; =20 - mRootBridge.DmaAbove4G =3D TRUE; - mRootBridge.NoExtendedConfigSpace =3D FALSE; - mRootBridge.ResourceAssigned =3D FALSE; + AllocationAttributes =3D EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM; =20 - mRootBridge.AllocationAttributes =3D EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PM= EM; - - mRootBridge.Bus.Base =3D BusMin; - mRootBridge.Bus.Limit =3D BusMax; - mRootBridge.Io.Base =3D IoBase; - mRootBridge.Io.Limit =3D IoBase + IoSize - 1; - mRootBridge.Mem.Base =3D Mmio32Base; - mRootBridge.Mem.Limit =3D Mmio32Base + Mmio32Size - 1; + Io.Base =3D IoBase; + Io.Limit =3D IoBase + IoSize - 1; + Mem.Base =3D Mmio32Base; + Mem.Limit =3D Mmio32Base + Mmio32Size - 1; =20 if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { - mRootBridge.MemAbove4G.Base =3D Mmio64Base; - mRootBridge.MemAbove4G.Limit =3D Mmio64Base + Mmio64Size - 1; + MemAbove4G.Base =3D Mmio64Base; + MemAbove4G.Limit =3D Mmio64Base + Mmio64Size - 1; if (Mmio64Size > 0) { - mRootBridge.AllocationAttributes |=3D EFI_PCI_HOST_BRIDGE_MEM64_DECO= DE; + AllocationAttributes |=3D EFI_PCI_HOST_BRIDGE_MEM64_DECODE; } } else { // @@ -380,21 +455,127 @@ PciHostBridgeGetRootBridges ( // BARs unless they are allocated below 4 GB. So ignore the range above // 4 GB in this case. // - mRootBridge.MemAbove4G.Base =3D MAX_UINT64; - mRootBridge.MemAbove4G.Limit =3D 0; + MemAbove4G.Base =3D MAX_UINT64; + MemAbove4G.Limit =3D 0; } =20 // // No separate ranges for prefetchable and non-prefetchable BARs // - mRootBridge.PMem.Base =3D MAX_UINT64; - mRootBridge.PMem.Limit =3D 0; - mRootBridge.PMemAbove4G.Base =3D MAX_UINT64; - mRootBridge.PMemAbove4G.Limit =3D 0; + PMem.Base =3D MAX_UINT64; + PMem.Limit =3D 0; + PMemAbove4G.Base =3D MAX_UINT64; + PMemAbove4G.Limit =3D 0; + + // + // QEMU provides the number of extra root buses, shortening the exhausti= ve + // search below. If there is no hint, the feature is missing. + // + Status =3D QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgS= ize); + if (EFI_ERROR (Status) || FwCfgSize !=3D sizeof ExtraRootBridges) { + ExtraRootBridges =3D 0; + } else { + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges); =20 - mRootBridge.DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridg= eDevicePath; + if (ExtraRootBridges > BusMax) { + DEBUG ((EFI_D_ERROR, "%a: invalid count of extra root buses (%Lu) " + "reported by QEMU\n", __FUNCTION__, ExtraRootBridges)); + return NULL; + } + DEBUG ((EFI_D_INFO, "%a: %Lu extra root buses reported by QEMU\n", + __FUNCTION__, ExtraRootBridges)); + } =20 - return &mRootBridge; + // + // Allocate the "main" root bridge, and any extra root bridges. + // + Bridges =3D AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridge= s); + if (Bridges =3D=3D NULL) { + DEBUG ((EFI_D_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES)); + return NULL; + } + Initialized =3D 0; + + // + // The "main" root bus is always there. + // + LastRootBridgeNumber =3D 0; + // + // Scan all other root buses. If function 0 of any device on a bus retur= ns a + // VendorId register value different from all-bits-one, then that bus is + // alive. + // + for (RootBridgeNumber =3D 1; + RootBridgeNumber <=3D BusMax && Initialized < ExtraRootBridges; + ++RootBridgeNumber) { + UINTN Device; + + for (Device =3D 0; Device <=3D PCI_MAX_DEVICE; ++Device) { + if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0, + PCI_VENDOR_ID_OFFSET)) !=3D MAX_UINT16) { + break; + } + } + if (Device <=3D PCI_MAX_DEVICE) { + // + // Found the next root bus. We can now install the *previous* one, + // because now we know how big a bus number range *that* one has, fo= r any + // subordinate buses that might exist behind PCI bridges hanging off= it. + // + Status =3D InitRootBridge ( + Attributes, + Attributes, + AllocationAttributes, + (UINT8) LastRootBridgeNumber, + (UINT8) (RootBridgeNumber - 1), + &Io, + &Mem, + &MemAbove4G, + &PMem, + &PMemAbove4G, + &Bridges[Initialized] + ); + if (EFI_ERROR (Status)) { + goto FreeBridges; + } + ++Initialized; + LastRootBridgeNumber =3D RootBridgeNumber; + } + } + // + // Install the last root bus (which might be the only, ie. main, root bu= s, if + // we've found no extra root buses). + // + Status =3D InitRootBridge ( + Attributes, + Attributes, + AllocationAttributes, + (UINT8) LastRootBridgeNumber, + BusMax, + &Io, + &Mem, + &MemAbove4G, + &PMem, + &PMemAbove4G, + &Bridges[Initialized] + ); + if (EFI_ERROR (Status)) { + goto FreeBridges; + } + ++Initialized; + + *Count =3D Initialized; + return Bridges; + +FreeBridges: + while (Initialized > 0) { + --Initialized; + UninitRootBridge (&Bridges[Initialized]); + } + + FreePool (Bridges); + return NULL; } =20 /** @@ -411,9 +592,18 @@ PciHostBridgeFreeRootBridges ( UINTN Count ) { - ASSERT (Count =3D=3D 1); -} + if (Bridges =3D=3D NULL && Count =3D=3D 0) { + return; + } + ASSERT (Bridges !=3D NULL && Count > 0); + + do { + --Count; + UninitRootBridge (&Bridges[Count]); + } while (Count > 0); =20 + FreePool (Bridges); +} /** Inform the platform that the resource conflict happens. =20 diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf= b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf index 277ccfd245..3ac58855af 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf @@ -31,11 +31,14 @@ ArmVirtPkg/ArmVirtPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] DebugLib DevicePathLib DxeServicesTableLib + BaseMemoryLib + QemuFwCfgLib MemoryAllocationLib PciPcdProducerLib =20 --=20 2.19.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56901): https://edk2.groups.io/g/devel/message/56901 Mute This Topic: https://groups.io/mt/72723351/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-