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 F07B9C7EE22 for ; Tue, 9 May 2023 14:02:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E071A8598A; Tue, 9 May 2023 16:02:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kwiboo.se header.i=@kwiboo.se header.b="X0Z2I6Mt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E7BCB85B08; Tue, 9 May 2023 16:01:59 +0200 (CEST) Received: from s.wrqvtzvf.outbound-mail.sendgrid.net (s.wrqvtzvf.outbound-mail.sendgrid.net [149.72.126.143]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EBF1B8479E for ; Tue, 9 May 2023 16:01:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bounces+31435339-7456-u-boot=lists.denx.de@em2124.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=mime-version:subject:references:from:in-reply-to:to:cc:content-type: content-transfer-encoding:cc:content-type:from:subject:to; s=s1; bh=C7KQa7R3wMylqN3Ro93NaaeHJMXpNDxTlMOWxetldQA=; b=X0Z2I6Mt0obHVSB//XxSoIzsaz2kOgjTCtWM1gYL770dlXJSwuJPe1RyWBObqkUFZilH bYeX7mKVzPGhlX/200+9Qymj+lgjWaHTQuCaEdLWguUsg6fDibeGMSgxLMfD8w+zmSXLDm Op1LgvGC/UIdhV9vTgEMQG2n2XYqow5wwrER62e4NEsaKP/9vFf8EooNFXZeHM40GtqrkH ul78ApyfWOf7jWA24GLhnDMtO9B5tfddaOZCxVnEwp15nSZOAjTnP31CeabSEMapl+Z3tl YjKwYiM+ar1lSRge+hR1683Vvh3FRGr6Zszq4nwdLE/ccY+9RCc4oUrZGGhIh6SQ== Received: by filterdrecv-7946957d94-8w8qz with SMTP id filterdrecv-7946957d94-8w8qz-1-645A5252-71 2023-05-09 14:01:54.522499529 +0000 UTC m=+1212250.979839774 Received: from [192.168.1.50] (unknown) by geopod-ismtpd-canary-0 (SG) with ESMTP id KDGFcWTZTeqbEqci0iYZew Tue, 09 May 2023 14:01:54.011 +0000 (UTC) Message-ID: <73d115ca-fa68-541c-9d12-45d075f0e54b@kwiboo.se> Date: Tue, 09 May 2023 14:01:54 +0000 (UTC) MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 4/8] pci: pcie_dw_rockchip: Hide BARs of the root complex Content-Language: en-US References: <20230422181943.889436-1-jonas@kwiboo.se> <20230422181943.889436-5-jonas@kwiboo.se> From: Jonas Karlman In-Reply-To: X-SG-EID: =?us-ascii?Q?TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxA?= =?us-ascii?Q?fZekEeQsTe+RrMu3cja6a0h6Q4whRHFpUUs3vrL?= =?us-ascii?Q?axTZbEF1CaT9lsNnVUF4MeXjryhIKK0cKJP5N=2Fn?= =?us-ascii?Q?4+BtAITaMu=2FFZh6sjmPzbYFxspkKtD73UvqMzHT?= =?us-ascii?Q?NCCQgzWCxVqquq1JUzzbqY2qJFoPrzSyFBLVagU?= =?us-ascii?Q?Kf0sNmy6vu7cZ9ldq9P1yB+wkqWU2ab10K=2F=2FbF?= To: Kever Yang , Simon Glass , Philipp Tomsich Cc: Eugen Hristev , u-boot@lists.denx.de, =?UTF-8?b?5p6X5rab?= , =?UTF-8?b?5p6X6byO5by6?= X-Entity-ID: P7KYpSJvGCELWjBME/J5tg== Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Kever, On 2023-05-09 14:19, Kever Yang wrote: > Hi Jonas, > > On 2023/4/23 02:19, 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. >> >> Return an invalid value during config read of Root Complex BARs during >> autoconfig to work around such issue. > > Could you share the error message without this workaround? > > I think the driver can works without this patch, the 1GiB memory BAR > will assigned fail > > and has no affect to BAR allocate for attached device. > Both BAR0 and BAR1 of the Root Complex on RK3568 report that it wants 1 GiB allocations (value=c0000000). On RK3588 the Root Complex BARs was entirely skipped (value=0). The 1 GiB memory BAR assignment used to fail when a 0x0-0x3fffffff pci range was used, because u-boot would skip initial 4 KiB and instead use 0x1000-0x3fffffff as the pci range. https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/pci/pci_auto_common.c#L28 With the change to use a 0x40000000-0x7fffffff pci range, the first 1 GiB allocation instead succeed and consume the entire usable range, leaving allocation for BAR1 of the Root Complex and BARs for any attached devices to fail. I did not find any hw reg that could be used to control the returned value for the BAR0/1 or the Root Complex, value c0000000 was always read back. With this change to mask BAR0 and BAR1 for Root Complex on RK3568, the entire pci range is available for BARs of any attached device. Regards, Jonas > > Thanks, > > - Kever > >> >> Signed-off-by: Jonas Karlman >> --- >> 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 fd3da47272b3..924ecb93e963 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, >> }; >>