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 X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 AE539C433DB for ; Tue, 16 Feb 2021 12:49:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 627A064D5D for ; Tue, 16 Feb 2021 12:49:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 627A064D5D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VdOCUBkvnyjuS2jAWDHN8lDjcQALF3zPBdq7P0YNsnQ=; b=hbmrIN5X4nAZyKitRH8SdgAIi zXgaEx56xKfgwRyaQXa0sLqyTk+dBz047Af46U84gI+UYp2Mg86VDnx6jnbeVEF5FJKVRgkKZMO8N d+TwlSVmR8j1wIi2vVYFlPwpRHP5Lf3+iECb3wCIN9Wj/+OGMePvGSnxlDIbUsS7XTdR91FgRrjZU gZ7qctnyhQbf0MV5WahdOnG8S8OrNNtX10tT84n9fz8BuPKOiJZRgDW6j+AtwIGXi3bXfYk9z7KAE akNM5kx6driDjtDHR01cxNua/kXlbHhPo+/z/d2Okwq6ae4KH8lZhRbjzA6NVckYzk8DPIx0sbi85 LZJO4sgRQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBzln-0003wV-H6; Tue, 16 Feb 2021 12:47:59 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBzlk-0003vV-Tz for linux-arm-kernel@lists.infradead.org; Tue, 16 Feb 2021 12:47:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 00B151FB; Tue, 16 Feb 2021 04:47:50 -0800 (PST) Received: from [10.57.48.219] (unknown [10.57.48.219]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D7AED3F694; Tue, 16 Feb 2021 04:47:47 -0800 (PST) Subject: Re: [RFC PATCH 1/8] of/device: Allow specifying a custom iommu_spec to of_dma_configure To: Mikko Perttunen , thierry.reding@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, will@kernel.org, robh+dt@kernel.org, frowand.list@gmail.com References: <20210208163848.2504291-1-mperttunen@nvidia.com> <20210208163848.2504291-2-mperttunen@nvidia.com> From: Robin Murphy Message-ID: <1c33f914-9109-42aa-01f3-04e50cf038c6@arm.com> Date: Tue, 16 Feb 2021 12:47:43 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210208163848.2504291-2-mperttunen@nvidia.com> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210216_074757_131562_1F8BDE18 X-CRM114-Status: GOOD ( 30.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Mikko, On 2021-02-08 16:38, Mikko Perttunen wrote: > To allow for more customized device tree bindings that point to IOMMUs, > allow manual specification of iommu_spec to of_dma_configure. > > The initial use case for this is with Host1x, where the driver manages > a set of device tree-defined IOMMU contexts that are dynamically > allocated to various users. These contexts don't correspond to > platform devices and are instead attached to dummy devices on a custom > software bus. I'd suggest taking a closer look at the patches that made this of_dma_configure_id() in the first place, and the corresponding bus code in fsl-mc. At this level, Host1x sounds effectively identical to DPAA2 in terms of being a bus of logical devices composed from bits of implicit behind-the-scenes hardware. I mean, compare your series title to the fact that their identifiers are literally named "Isolation Context ID" ;) Please just use the existing mechanisms to describe a mapping between Host1x context IDs and SMMU Stream IDs, rather than what looks like a giant hacky mess here. (This also reminds me I wanted to rip out all the PCI special-cases and convert pci_dma_configure() over to passing its own IDs too, so thanks for the memory-jog...) Robin. > Signed-off-by: Mikko Perttunen > --- > drivers/iommu/of_iommu.c | 12 ++++++++---- > drivers/of/device.c | 9 +++++---- > include/linux/of_device.h | 34 +++++++++++++++++++++++++++------- > include/linux/of_iommu.h | 6 ++++-- > 4 files changed, 44 insertions(+), 17 deletions(-) > > diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c > index e505b9130a1c..3fefa6c63863 100644 > --- a/drivers/iommu/of_iommu.c > +++ b/drivers/iommu/of_iommu.c > @@ -87,8 +87,7 @@ int of_get_dma_window(struct device_node *dn, const char *prefix, int index, > } > EXPORT_SYMBOL_GPL(of_get_dma_window); > > -static int of_iommu_xlate(struct device *dev, > - struct of_phandle_args *iommu_spec) > +int of_iommu_xlate(struct device *dev, struct of_phandle_args *iommu_spec) > { > const struct iommu_ops *ops; > struct fwnode_handle *fwnode = &iommu_spec->np->fwnode; > @@ -117,6 +116,7 @@ static int of_iommu_xlate(struct device *dev, > module_put(ops->owner); > return ret; > } > +EXPORT_SYMBOL_GPL(of_iommu_xlate); > > static int of_iommu_configure_dev_id(struct device_node *master_np, > struct device *dev, > @@ -177,7 +177,8 @@ static int of_iommu_configure_device(struct device_node *master_np, > > const struct iommu_ops *of_iommu_configure(struct device *dev, > struct device_node *master_np, > - const u32 *id) > + const u32 *id, > + struct of_phandle_args *iommu_spec) > { > const struct iommu_ops *ops = NULL; > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > @@ -209,7 +210,10 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, > err = pci_for_each_dma_alias(to_pci_dev(dev), > of_pci_iommu_init, &info); > } else { > - err = of_iommu_configure_device(master_np, dev, id); > + if (iommu_spec) > + err = of_iommu_xlate(dev, iommu_spec); > + else > + err = of_iommu_configure_device(master_np, dev, id); > > fwspec = dev_iommu_fwspec_get(dev); > if (!err && fwspec) > diff --git a/drivers/of/device.c b/drivers/of/device.c > index aedfaaafd3e7..84ada2110c5b 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -88,8 +88,9 @@ int of_device_add(struct platform_device *ofdev) > * can use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE events > * to fix up DMA configuration. > */ > -int of_dma_configure_id(struct device *dev, struct device_node *np, > - bool force_dma, const u32 *id) > +int __of_dma_configure(struct device *dev, struct device_node *np, > + bool force_dma, const u32 *id, > + struct of_phandle_args *iommu_spec) > { > const struct iommu_ops *iommu; > const struct bus_dma_region *map = NULL; > @@ -170,7 +171,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > dev_dbg(dev, "device is%sdma coherent\n", > coherent ? " " : " not "); > > - iommu = of_iommu_configure(dev, np, id); > + iommu = of_iommu_configure(dev, np, id, iommu_spec); > if (PTR_ERR(iommu) == -EPROBE_DEFER) { > kfree(map); > return -EPROBE_DEFER; > @@ -184,7 +185,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > dev->dma_range_map = map; > return 0; > } > -EXPORT_SYMBOL_GPL(of_dma_configure_id); > +EXPORT_SYMBOL_GPL(__of_dma_configure); > > int of_device_register(struct platform_device *pdev) > { > diff --git a/include/linux/of_device.h b/include/linux/of_device.h > index 07ca187fc5e4..40cc3e788cb9 100644 > --- a/include/linux/of_device.h > +++ b/include/linux/of_device.h > @@ -55,14 +55,27 @@ static inline struct device_node *of_cpu_device_node_get(int cpu) > return of_node_get(cpu_dev->of_node); > } > > -int of_dma_configure_id(struct device *dev, > +int __of_dma_configure(struct device *dev, > struct device_node *np, > - bool force_dma, const u32 *id); > + bool force_dma, const u32 *id, > + struct of_phandle_args *iommu_spec); > static inline int of_dma_configure(struct device *dev, > struct device_node *np, > bool force_dma) > { > - return of_dma_configure_id(dev, np, force_dma, NULL); > + return __of_dma_configure(dev, np, force_dma, NULL, NULL); > +} > +static inline int of_dma_configure_id(struct device *dev, > + struct device_node *np, > + bool force_dma, const u32 *id) > +{ > + return __of_dma_configure(dev, np, force_dma, id, NULL); > +} > +static inline int > +of_dma_configure_iommu_spec(struct device *dev, struct device_node *np, > + bool force_dma, struct of_phandle_args *iommu_spec) > +{ > + return __of_dma_configure(dev, np, force_dma, NULL, iommu_spec); > } > #else /* CONFIG_OF */ > > @@ -112,18 +125,25 @@ static inline struct device_node *of_cpu_device_node_get(int cpu) > return NULL; > } > > -static inline int of_dma_configure_id(struct device *dev, > +static inline int of_dma_configure(struct device *dev, > struct device_node *np, > bool force_dma) > { > return 0; > } > -static inline int of_dma_configure(struct device *dev, > - struct device_node *np, > - bool force_dma) > + > +static inline int of_dma_configure_id(struct device *dev, > + struct device_node *np, > + bool force_dma, const u32 *id) > { > return 0; > } > + > +static inline int > +of_dma_configure_iommu_spec(struct device *dev, struct device_node *np, > + bool force_dma, struct of_phandle_args *iommu_spec) > +{ return 0; > +} > #endif /* CONFIG_OF */ > > #endif /* _LINUX_OF_DEVICE_H */ > diff --git a/include/linux/of_iommu.h b/include/linux/of_iommu.h > index 16f4b3e87f20..e8d1e6d32d77 100644 > --- a/include/linux/of_iommu.h > +++ b/include/linux/of_iommu.h > @@ -14,7 +14,8 @@ extern int of_get_dma_window(struct device_node *dn, const char *prefix, > > extern const struct iommu_ops *of_iommu_configure(struct device *dev, > struct device_node *master_np, > - const u32 *id); > + const u32 *id, > + struct of_phandle_args *iommu_spec); > > #else > > @@ -27,7 +28,8 @@ static inline int of_get_dma_window(struct device_node *dn, const char *prefix, > > static inline const struct iommu_ops *of_iommu_configure(struct device *dev, > struct device_node *master_np, > - const u32 *id) > + const u32 *id, > + struct of_phandle_args *iommu_spec); > { > return NULL; > } > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel