From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE738C43219 for ; Tue, 18 Oct 2022 00:14:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbiJRAOx (ORCPT ); Mon, 17 Oct 2022 20:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbiJRAOF (ORCPT ); Mon, 17 Oct 2022 20:14:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98F5C2649C; Mon, 17 Oct 2022 17:10:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A185EB81BF6; Tue, 18 Oct 2022 00:09:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73126C433C1; Tue, 18 Oct 2022 00:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666051751; bh=PfS3MUy2UbAlOBpNhWoak50h4hiUgoUdF/rPRSBR4fM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0guUD4w6J5h1RNZ8qIIeKgzsXN0QUvJkgRiWoOO8ejtrRct6Jiyb6KouQo75Wjib 7qlWD3Lmm005W8uMMK14Vcg+GxAyz4rhjmvKzGkVv+HIXJo0EijsUWw8n+Fpcwxs1X 5yjyDLw14aNDw1JSfOznpWjodXWlLm+vB7d59vIKR2xc+zPDEd1zazdLNuPm+vMA79 EdQN3j7y3ArUao/Z+6vJX1vogjy2RgS/MLiAbIvJKKN1GPx82pRYouH8M/0QcCeSyK nbFiDafpwPgzq7N2QFeQKzRe2SXxumLkKiVh43473ukWvPqYoKoml7AmD+45YtURyI AoD6MIrcm3ZuQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Robin Murphy , Serge Semin , Rob Herring , Sasha Levin , robh+dt@kernel.org, frowand.list@gmail.com, devicetree@vger.kernel.org Subject: [PATCH AUTOSEL 5.19 18/29] of: Fix "dma-ranges" handling for bus controllers Date: Mon, 17 Oct 2022 20:08:27 -0400 Message-Id: <20221018000839.2730954-18-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018000839.2730954-1-sashal@kernel.org> References: <20221018000839.2730954-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy [ Upstream commit f1ad5338a4d57fe1fe6475003acb8c70bf9d1bdf ] Commit 951d48855d86 ("of: Make of_dma_get_range() work on bus nodes") relaxed the handling of "dma-ranges" for any leaf node on the assumption that it would still represent a usage error for the property to be present on a non-bus leaf node. However there turns out to be a fiddly case where a bus also represents a DMA-capable device in its own right, such as a PCIe root complex with an integrated DMA engine on its platform side. In such cases, "dma-ranges" translation is entirely valid for devices discovered behind the bus, but should not be erroneously applied to the bus controller device itself which operates in its parent's address space. Fix this by restoring the previous behaviour for the specific case where a device is configured via its own OF node, since it is logical to assume that a device should never represent its own parent bus. Reported-by: Serge Semin Signed-off-by: Robin Murphy Link: https://lore.kernel.org/r/112e8f3d3e7c054ecf5e12b5ac0aa5596ec00681.1664455433.git.robin.murphy@arm.com Signed-off-by: Rob Herring Signed-off-by: Sasha Levin --- drivers/of/address.c | 4 +++- drivers/of/device.c | 9 ++++++++- drivers/of/of_private.h | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 94f017d808c4..d6f5a427a329 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -579,7 +579,8 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr) } EXPORT_SYMBOL(of_translate_address); -static struct device_node *__of_get_dma_parent(const struct device_node *np) +#ifdef CONFIG_HAS_DMA +struct device_node *__of_get_dma_parent(const struct device_node *np) { struct of_phandle_args args; int ret, index; @@ -596,6 +597,7 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np) return of_node_get(args.np); } +#endif static struct device_node *of_get_next_dma_parent(struct device_node *np) { diff --git a/drivers/of/device.c b/drivers/of/device.c index 75b6cbffa755..8cefe5a7d04e 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -116,12 +116,19 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, { const struct iommu_ops *iommu; const struct bus_dma_region *map = NULL; + struct device_node *bus_np; u64 dma_start = 0; u64 mask, end, size = 0; bool coherent; int ret; - ret = of_dma_get_range(np, &map); + if (np == dev->of_node) + bus_np = __of_get_dma_parent(np); + else + bus_np = of_node_get(np); + + ret = of_dma_get_range(bus_np, &map); + of_node_put(bus_np); if (ret < 0) { /* * For legacy reasons, we have to assume some devices need diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 9324483397f6..fb6792d381a6 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -155,12 +155,17 @@ struct bus_dma_region; #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map); +struct device_node *__of_get_dma_parent(const struct device_node *np); #else static inline int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) { return -ENODEV; } +static inline struct device_node *__of_get_dma_parent(const struct device_node *np) +{ + return of_get_parent(np); +} #endif void fdt_init_reserved_mem(void); -- 2.35.1