From: laurent.pinchart@ideasonboard.com (Laurent Pinchart)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v3 4/7] iommu: provide helper function to configure an IOMMU for an of master
Date: Tue, 14 Oct 2014 16:12:59 +0300 [thread overview]
Message-ID: <6158503.EYJT9z30tm@avalon> (raw)
In-Reply-To: <20140922171352.GF7936@arm.com>
Hi Will,
On Monday 22 September 2014 18:13:52 Will Deacon wrote:
> On Thu, Sep 18, 2014 at 12:13:13PM +0100, Laurent Pinchart wrote:
> > Hi Will,
>
> Hi Laurent,
>
> > Thank you for the patch.
>
> Sorry for the delay in replying, I was at Connect last week and the email
> has backed up.
No worries.
> > On Friday 12 September 2014 17:34:52 Will Deacon wrote:
> >> The generic IOMMU device-tree bindings can be used to add arbitrary OF
> >> masters to an IOMMU with a compliant binding.
> >>
> >> This patch introduces of_iommu_configure, which does exactly that. A
> >> list of iommu_dma_mapping structures are created for each device, which
> >> represent the set of IOMMU instances through which the device can
> >> master. The list is protected by a kref count and freed when no users
> >> remain. It is expected that DMA-mapping code will take a reference if it
> >> wishes to make use of the IOMMU information.
>
> [...]
>
> >> +struct iommu_dma_mapping *of_iommu_configure(struct device *dev)
> >> +{
> >> + struct of_phandle_args iommu_spec;
> >> + struct iommu_dma_mapping *mapping;
> >> + struct device_node *np;
> >> + struct iommu_data *iommu = NULL;
> >> + int idx = 0;
> >> +
> >> + /*
> >> + * We don't currently walk up the tree looking for a parent IOMMU.
> >> + * See the `Notes:' section of
> >> + * Documentation/devicetree/bindings/iommu/iommu.txt
> >> + */
> >> + while (!of_parse_phandle_with_args(dev->of_node, "iommus",
> >> + "#iommu-cells", idx,
> >> + &iommu_spec)) {
> >> + struct iommu_data *data;
> >> +
> >> + np = iommu_spec.np;
> >> + data = of_iommu_get_data(np);
> >> +
> >> + if (!data || !data->ops || !data->ops->of_xlate)
> >> + goto err_put_node;
> >> +
> >> + if (!iommu) {
> >> + iommu = data;
> >> + } else if (iommu != data) {
> >> + /* We don't currently support multi-IOMMU masters */
> >> + pr_warn("Rejecting device %s with multiple IOMMU
instances\n",
> >> + dev_name(dev));
> >> + goto err_put_node;
> >> + }
> >> +
> >> + if (!data->ops->of_xlate(dev, &iommu_spec))
> >> + goto err_put_node;
> >> +
> >> + of_node_put(np);
> >> + idx++;
> >> + }
> >> +
> >> + if (!iommu)
> >> + return NULL;
> >> +
> >> + mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
> >> + if (!mapping)
> >> + return NULL;
> >> +
> >> + kref_init(&mapping->kref);
> >> + INIT_LIST_HEAD(&mapping->node);
> >
> > I might be missing something, but that doesn't seem to match the commit
> > message. This creates a single iommu_dma_mapping per device, where is the
> > list supposed to be populated ?
>
> Right. I currently only populate the first node in the list, and the loop
> above barfs if we find multiple IOMMUs. I was hoping you'd add support for
> that later on, as you mentioned the need for this so I guess you can test it
> too?
I can, I was just puzzled by the mismatch between the code and commit message.
As your patch series doesn't provide a complete end-to-end implementation it's
not always easy to understand how you envision that implementation to work,
and thus difficult to implement the required modifications to the IOMMU
driver.
> >> +void of_iommu_deconfigure(struct kref *kref)
> >> +{
> >> + struct iommu_dma_mapping *mapping, *curr, *next;
> >> +
> >> + mapping = container_of(kref, struct iommu_dma_mapping, kref);
> >> + list_for_each_entry_safe(curr, next, &mapping->node, node) {
> >> + list_del(&curr->node);
> >> + kfree(curr);
> >> + }
> >
> > Don't you need to also kfree(mapping) here ?
>
> Yup, thanks.
>
> >> +}
> >> +
> >
> > Do you expect other users of of_iommu_deconfigure() than kref_put() ? If
> > not, how about exposing an of_iommu_put(struct iommu_dma_mapping *) that
> > would call kref_put() internally, and hiding of_iommu_deconfigure() ?
>
> That's a good idea, I'll do that.
>
> >> void __init of_iommu_init(void)
> >> {
> >> struct device_node *np;
> >> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> >> index 1e944e77d38d..e60e52d82db9 100644
> >> --- a/include/linux/dma-mapping.h
> >> +++ b/include/linux/dma-mapping.h
> >> @@ -62,6 +62,14 @@ struct dma_map_ops {
> >> int is_phys;
> >> };
> >>
> >> +struct iommu_data;
> >> +
> >> +struct iommu_dma_mapping {
> >> + struct iommu_data *iommu;
> >> + struct list_head node;
> >> + struct kref kref;
> >> +};
> >
> > Could you please document the structure with kerneldoc ?
>
> Ok, I'll try!
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2014-10-14 13:12 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-12 16:34 [RFC PATCH v3 0/7] Introduce automatic DMA configuration for IOMMU masters Will Deacon
2014-09-12 16:34 ` [RFC PATCH v3 1/7] iommu: provide early initialisation hook for IOMMU drivers Will Deacon
2014-09-18 14:31 ` Robin Murphy
2014-09-22 17:35 ` Will Deacon
2014-09-12 16:34 ` [RFC PATCH v3 2/7] dma-mapping: replace set_arch_dma_coherent_ops with arch_setup_dma_ops Will Deacon
2014-09-12 16:34 ` [RFC PATCH v3 3/7] iommu: add new iommu_ops callback for adding an OF device Will Deacon
2014-09-15 11:57 ` Marek Szyprowski
2014-09-17 1:39 ` Will Deacon
2014-09-12 16:34 ` [RFC PATCH v3 4/7] iommu: provide helper function to configure an IOMMU for an of master Will Deacon
2014-09-18 11:13 ` Laurent Pinchart
2014-09-22 17:13 ` Will Deacon
2014-10-14 13:12 ` Laurent Pinchart [this message]
2014-09-12 16:34 ` [RFC PATCH v3 5/7] dma-mapping: detect and configure IOMMU in of_dma_configure Will Deacon
2014-09-18 11:17 ` Laurent Pinchart
2014-09-22 9:29 ` Thierry Reding
2014-09-22 17:50 ` Will Deacon
2014-10-14 12:53 ` Laurent Pinchart
2014-10-27 10:51 ` Will Deacon
2014-10-27 11:12 ` Marek Szyprowski
2014-10-27 11:30 ` Laurent Pinchart
2014-10-27 16:02 ` Will Deacon
2014-10-27 16:33 ` jroedel at suse.de
2014-09-22 17:46 ` Will Deacon
2014-09-12 16:34 ` [RFC PATCH v3 6/7] arm: call iommu_init before of_platform_populate Will Deacon
2014-09-22 9:36 ` Thierry Reding
2014-09-22 11:08 ` Arnd Bergmann
2014-09-22 11:40 ` Thierry Reding
2014-09-22 16:03 ` Arnd Bergmann
2014-09-23 7:02 ` Thierry Reding
2014-09-23 7:44 ` Arnd Bergmann
2014-09-23 8:59 ` Thierry Reding
2014-10-14 13:07 ` Laurent Pinchart
2014-10-14 13:20 ` Arnd Bergmann
2014-10-14 13:37 ` Thierry Reding
2014-10-14 15:01 ` Laurent Pinchart
2014-10-14 15:05 ` Thierry Reding
2014-10-14 15:10 ` Laurent Pinchart
2014-09-12 16:34 ` [RFC PATCH v3 7/7] arm: dma-mapping: plumb our iommu mapping ops into arch_setup_dma_ops Will Deacon
2014-09-22 9:19 ` Thierry Reding
2014-09-22 9:22 ` Laurent Pinchart
2014-09-22 17:43 ` Will Deacon
2014-09-23 7:14 ` Thierry Reding
2014-09-24 16:33 ` Will Deacon
2014-09-25 6:40 ` Thierry Reding
2014-09-30 16:00 ` Will Deacon
2014-10-01 8:46 ` Thierry Reding
2014-10-03 15:08 ` Will Deacon
2014-10-06 9:52 ` Thierry Reding
2014-10-06 10:50 ` Laurent Pinchart
2014-10-06 13:05 ` Thierry Reding
2014-09-16 11:40 ` [RFC PATCH v3 0/7] Introduce automatic DMA configuration for IOMMU masters Robin Murphy
2014-09-17 1:19 ` Will Deacon
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=6158503.EYJT9z30tm@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.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