Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ECD1C4707F for ; Thu, 27 May 2021 06:23:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B568B610CC for ; Thu, 27 May 2021 06:23:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B568B610CC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4768081DB3; Thu, 27 May 2021 08:23:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1622096587; bh=RWYn2OQUisoXBQRFUzvTJ7owR3jaIad8yZlFfGMxew0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=y+7IpU/Q0lucqpMedu6GKv0uguMv/XvzgihcxkmwpUbdkoemSKImFgFxwdT/tICqC FgeGjbIPjvOviJyknOjc/csvRYdgVsgul7UMHdsWiQY7tnB1PvFNeSoaLy+7bSyKoW x8/qpJxRDduXMG1O4VxeTSq1pZ/sDLP98x7zztdSHmv8kgR1xIOhKiFdbeUUygmwjG Jvgf+mB98/nrRR9KYcNQUHHmjxQTWjlRP8w5CNEG6jy+8mwvPZ6oGSagfLLH8KRdfA EM3tkRyBGKA2KS2TNUAU8W9P5tPos9hGhgjzaENz0ZzKyuZ7EJJ7otWGAmrCswwS2b bRwkJp6lgbSzA== Received: by phobos.denx.de (Postfix, from userid 109) id C53DF8047F; Thu, 27 May 2021 08:23:04 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:1::465:107]) (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 333F18047F for ; Thu, 27 May 2021 08:23:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4FrHn072fKzQjBM; Thu, 27 May 2021 08:23:00 +0200 (CEST) Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id aUwSycGglCI5; Thu, 27 May 2021 08:22:56 +0200 (CEST) Subject: Re: [PATCH v2 5/7] arm: a37xx: pci: Fix a3700_fdt_fix_pcie_regions() function To: =?UTF-8?Q?Pali_Roh=c3=a1r?= , Konstantin Porotchkin Cc: =?UTF-8?Q?Marek_Beh=c3=ban?= , u-boot@lists.denx.de References: <20210517063956.30905-1-pali@kernel.org> <20210526155940.26141-1-pali@kernel.org> <20210526155940.26141-5-pali@kernel.org> From: Stefan Roese Message-ID: Date: Thu, 27 May 2021 08:22:56 +0200 MIME-Version: 1.0 In-Reply-To: <20210526155940.26141-5-pali@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit X-MBO-SPAM-Probability: X-Rspamd-Score: -8.29 / 15.00 / 15.00 X-Rspamd-Queue-Id: CB59A17CF X-Rspamd-UID: 3db9b1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean On 26.05.21 17:59, Pali Rohár wrote: > Current version of this function uses a lot of incorrect assumptions about > the `ranges` DT property: > > * parent(#address-cells) == 2 > * #size-cells == 2 > * number of entries == 2 > * address size of first entry == 0x1000000 > * second child address entry == base + 0x1000000 > > Trying to increase PCIe MEM space to more than 16 MiB leads to an overlap > with PCIe IO space, and trying to define additional MEM space (as a third > entry in the `ranges` DT property) causes U-Boot to crash when booting the > kernel. > > ## Flattened Device Tree blob at 04f00000 > Booting using the fdt blob at 0x4f00000 > Loading Device Tree to 000000001fb01000, end 000000001fb08f12 ... OK > ERROR: board-specific fdt fixup failed: > - must RESET the board to recover. > > Fix a3700_fdt_fix_pcie_regions() to properly parse and update all addresses > in the `ranges` property according to > https://elinux.org/Device_Tree_Usage#PCI_Address_Translation > > Now it is possible to increase PCIe MEM space from 16 MiB to maximal value > of 127 MiB. > > Signed-off-by: Pali Rohár > Reviewed-by: Marek Behún > Fixes: cb2ddb291ee6 ("arm64: mvebu: a37xx: add device-tree fixer for PCIe regions") Reviewed-by: Stefan Roese Thanks, Stefan > --- > arch/arm/mach-mvebu/armada3700/cpu.c | 74 ++++++++++++++++++++++------ > 1 file changed, 60 insertions(+), 14 deletions(-) > > diff --git a/arch/arm/mach-mvebu/armada3700/cpu.c b/arch/arm/mach-mvebu/armada3700/cpu.c > index 1abac7c9a47a..9aec0ce9a430 100644 > --- a/arch/arm/mach-mvebu/armada3700/cpu.c > +++ b/arch/arm/mach-mvebu/armada3700/cpu.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -280,36 +281,81 @@ static u32 find_pcie_window_base(void) > return -1; > } > > +static int fdt_setprop_inplace_u32_partial(void *blob, int node, > + const char *name, > + u32 idx, u32 val) > +{ > + val = cpu_to_fdt32(val); > + > + return fdt_setprop_inplace_namelen_partial(blob, node, name, > + strlen(name), > + idx * sizeof(u32), > + &val, sizeof(u32)); > +} > + > int a3700_fdt_fix_pcie_regions(void *blob) > { > - u32 new_ranges[14], base; > + int acells, pacells, scells; > + u32 base, fix_offset; > const u32 *ranges; > - int node, len; > + int node, pnode; > + int ret, i, len; > + > + base = find_pcie_window_base(); > + if (base == -1) > + return -ENOENT; > > node = fdt_node_offset_by_compatible(blob, -1, "marvell,armada-3700-pcie"); > if (node < 0) > return node; > > ranges = fdt_getprop(blob, node, "ranges", &len); > - if (!ranges) > + if (!ranges || len % sizeof(u32)) > return -ENOENT; > > - if (len != sizeof(new_ranges)) > - return -EINVAL; > - > - memcpy(new_ranges, ranges, len); > + /* > + * The "ranges" property is an array of > + * { } > + * > + * All 3 elements can span a diffent number of cells. Fetch their sizes. > + */ > + pnode = fdt_parent_offset(blob, node); > + acells = fdt_address_cells(blob, node); > + pacells = fdt_address_cells(blob, pnode); > + scells = fdt_size_cells(blob, node); > > - base = find_pcie_window_base(); > - if (base == -1) > + /* Child PCI addresses always use 3 cells */ > + if (acells != 3) > return -ENOENT; > > - new_ranges[2] = cpu_to_fdt32(base); > - new_ranges[4] = new_ranges[2]; > + /* Calculate fixup offset from first child address (in last cell) */ > + fix_offset = base - fdt32_to_cpu(ranges[2]); > > - new_ranges[9] = cpu_to_fdt32(base + 0x1000000); > - new_ranges[11] = new_ranges[9]; > + /* > + * Fix address (last cell) of each child address and each parent > + * address > + */ > + for (i = 0; i < len / sizeof(u32); i += acells + pacells + scells) { > + int idx; > + > + /* fix child address */ > + idx = i + acells - 1; > + ret = fdt_setprop_inplace_u32_partial(blob, node, "ranges", idx, > + fdt32_to_cpu(ranges[idx]) + > + fix_offset); > + if (ret) > + return ret; > + > + /* fix parent address */ > + idx = i + acells + pacells - 1; > + ret = fdt_setprop_inplace_u32_partial(blob, node, "ranges", idx, > + fdt32_to_cpu(ranges[idx]) + > + fix_offset); > + if (ret) > + return ret; > + } > > - return fdt_setprop_inplace(blob, node, "ranges", new_ranges, len); > + return 0; > } > > void reset_cpu(void) > Viele Grüße, Stefan -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de