Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F996EB64D9 for ; Thu, 29 Jun 2023 10:26:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EB11485DCE; Thu, 29 Jun 2023 12:26:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id D181285DCE; Thu, 29 Jun 2023 12:26:16 +0200 (CEST) Received: from mail-m11886.qiye.163.com (mail-m11886.qiye.163.com [115.236.118.86]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0486C8666F for ; Thu, 29 Jun 2023 12:26:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kever.yang@rock-chips.com Received: from [172.16.12.93] (unknown [58.22.7.114]) by mail-m11886.qiye.163.com (Hmail) with ESMTPA id DB24B801BB; Thu, 29 Jun 2023 18:25:51 +0800 (CST) Message-ID: <4ba74058-26f6-6ea1-7bde-ecc9d32fd244@rock-chips.com> Date: Thu, 29 Jun 2023 18:25:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v2 5/9] pci: pcie_dw_rockchip: Hide BARs of the root complex Content-Language: en-US To: Jonas Karlman , Simon Glass , =?UTF-8?B?5p6X6byO5by6?= Cc: Eugen Hristev , u-boot@lists.denx.de References: <20230517225337.2089287-1-jonas@kwiboo.se> <20230517225337.2089287-6-jonas@kwiboo.se> From: Kever Yang In-Reply-To: <20230517225337.2089287-6-jonas@kwiboo.se> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGRpMSVZJGRodS01IHU1NSx1VEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSk5MSUpJVUpLS1VKQl kG X-HM-Tid: 0a8906b01b892ebakusndb24b801bb X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NxQ6Nww4AT0DOkI3CE8tOEsL PhAwCSNVSlVKTUNDS0hPSE5JTE9JVTMWGhIXVRAeDR4JVQIaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFOQ0tINwY+ X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Hi Jonas,     Sorry for reply late for this patch.     I have check internally again for this BAR issue, the BAR alloce fail for RC would not affect other process, and it always works on vendor U-Boot tree.     And if we have to handle this, we can disable the BAR instead of this workaround. Thanks, - Kever On 2023/5/18 06:53, Jonas Karlman wrote: > PCI Autoconfig read the Root Complex BARs and try to claim the entire > 1 GiB memory region on RK3568, leaving no space for any attached device. > > With a memory region less than 1 GiB this was not a real issue: > > PCI Autoconfig: Bus Memory region: [0-3eefffff], > PCI Autoconfig: Bus I/O region: [3ef00000-3effffff], > PCI Autoconfig: Found P2P bridge, device 0 > PCI Autoconfig: BAR 0, Mem, size=0x40000000, No room in resource, avail start=1000 / size=3ef00000, need=40000000 > PCI: Failed autoconfig bar 10 > PCI Autoconfig: BAR 1, Mem, size=0x40000000, No room in resource, avail start=1000 / size=3ef00000, need=40000000 > PCI: Failed autoconfig bar 14 > PCI Autoconfig: ROM, size=0x10000, address=0x10000 bus_lower=0x20000 > > PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x100000 bus_lower=0x104000 > > With a memory region of the entire 1 GiB this leads to: > > PCI Autoconfig: Bus Memory region: [40000000-7fffffff], > PCI Autoconfig: Bus I/O region: [f0100000-f01fffff], > PCI Autoconfig: Found P2P bridge, device 0 > PCI Autoconfig: BAR 0, Mem, size=0x40000000, address=0x40000000 bus_lower=0x80000000 > PCI Autoconfig: BAR 1, Mem, size=0x40000000, No room in resource, avail start=80000000 / size=40000000, need=40000000 > PCI: Failed autoconfig bar 14 > PCI Autoconfig: ROM, size=0x10000, No room in resource, avail start=80000000 / size=40000000, need=10000 > > PCI Autoconfig: BAR 0, Mem64, size=0x4000, No room in resource, avail start=80000000 / size=40000000, need=4000 > PCI: Failed autoconfig bar 10 > > After this change with a memory region of the entire 1 GiB: > > PCI Autoconfig: Bus Memory region: [40000000-7fffffff], > PCI Autoconfig: Bus I/O region: [f0100000-f01fffff], > PCI Autoconfig: Found P2P bridge, device 0 > PCI Autoconfig: ROM, size=0x10000, address=0x40000000 bus_lower=0x40010000 > > PCI Autoconfig: BAR 0, Mem64, size=0x4000, address=0x40100000 bus_lower=0x40104000 > > Return an invalid value during config read of Root Complex BARs during > autoconfig to work around such issue. > > Signed-off-by: Jonas Karlman > --- > v2: > - Update commit message > > drivers/pci/pcie_dw_rockchip.c | 28 +++++++++++++++++++++++++++- > 1 file changed, 27 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c > index 82a8b9c96e2b..f56773c2e58c 100644 > --- a/drivers/pci/pcie_dw_rockchip.c > +++ b/drivers/pci/pcie_dw_rockchip.c > @@ -146,6 +146,32 @@ static inline void rk_pcie_writel_apb(struct rk_pcie *rk_pcie, u32 reg, > __rk_pcie_write_apb(rk_pcie, rk_pcie->apb_base, reg, 0x4, val); > } > > +/** > + * The BARs of bridge should be hidden during enumeration to avoid > + * allocation of the entire memory region by PCIe core on RK3568. > + */ > +static bool rk_pcie_hide_rc_bar(struct pcie_dw *pcie, pci_dev_t bdf, > + uint offset) > +{ > + int bus = PCI_BUS(bdf) - pcie->first_busno; > + > + return bus == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 && > + offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_1; > +} > + > +static int rk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf, > + uint offset, ulong *valuep, > + enum pci_size_t size) > +{ > + struct pcie_dw *pcie = dev_get_priv(bus); > + int ret = pcie_dw_read_config(bus, bdf, offset, valuep, size); > + > + if (!ret && rk_pcie_hide_rc_bar(pcie, bdf, offset)) > + *valuep = pci_get_ff(size); > + > + return ret; > +} > + > /** > * rk_pcie_configure() - Configure link capabilities and speed > * > @@ -476,7 +502,7 @@ rockchip_pcie_probe_err_init_port: > } > > static const struct dm_pci_ops rockchip_pcie_ops = { > - .read_config = pcie_dw_read_config, > + .read_config = rk_pcie_read_config, > .write_config = pcie_dw_write_config, > }; >