From: Robin Murphy <robin.murphy@arm.com>
To: Mikko Perttunen <mperttunen@nvidia.com>,
thierry.reding@gmail.com, jonathanh@nvidia.com, joro@8bytes.org,
will@kernel.org, robh+dt@kernel.org, frowand.list@gmail.com
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
Subject: Re: [RFC PATCH 1/8] of/device: Allow specifying a custom iommu_spec to of_dma_configure
Date: Tue, 16 Feb 2021 12:47:43 +0000 [thread overview]
Message-ID: <1c33f914-9109-42aa-01f3-04e50cf038c6@arm.com> (raw)
In-Reply-To: <20210208163848.2504291-2-mperttunen@nvidia.com>
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 <mperttunen@nvidia.com>
> ---
> 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
next prev parent reply other threads:[~2021-02-16 12:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-08 16:38 [RFC PATCH 0/8] Host1x context isolation support Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 1/8] of/device: Allow specifying a custom iommu_spec to of_dma_configure Mikko Perttunen
2021-02-08 16:53 ` Mikko Perttunen
2021-02-16 12:47 ` Robin Murphy [this message]
2021-02-16 13:20 ` Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 2/8] gpu: host1x: Add context bus Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 3/8] gpu: host1x: Add context device management code Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 4/8] gpu: host1x: Program context stream ID on submission Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 5/8] iommu/arm-smmu: Attach to host1x context device bus Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 6/8] arm64: tegra: Add Host1x context stream IDs on Tegra186+ Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 7/8] drm/tegra: Support context isolation Mikko Perttunen
2021-02-08 16:38 ` [RFC PATCH 8/8] drm/tegra: vic: Implement get_streamid_offset Mikko Perttunen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1c33f914-9109-42aa-01f3-04e50cf038c6@arm.com \
--to=robin.murphy@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=frowand.list@gmail.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mperttunen@nvidia.com \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).