From: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
To: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
Cc: joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org,
thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
jean-philippe.brucker-5wv7dgnIgG8@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Frank Rowand
<frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH v4 3/8] of/irq: Break out msi-map lookup (again)
Date: Thu, 7 Jul 2016 17:51:51 +0100 [thread overview]
Message-ID: <20160707165151.GF20682@arm.com> (raw)
In-Reply-To: <cb0040f52022b049a3515f0b01a81a83381ad7d9.1467388950.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
On Fri, Jul 01, 2016 at 05:50:12PM +0100, Robin Murphy wrote:
> The PCI msi-map code is already doing double-duty translating IDs and
> retrieving MSI parents, which unsurprisingly is the same functionality
> we need for the identically-formatted PCI iommu-map property. Drag the
> core parsing routine up yet another layer into the general OF-PCI code,
> and further generalise it for either kind of lookup in either flavour
> of map property.
>
> CC: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> CC: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Acked-by: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
> ---
>
> v4: No change.
>
> drivers/of/irq.c | 78 ++-----------------------------------
> drivers/of/of_pci.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/of_pci.h | 10 +++++
> 3 files changed, 116 insertions(+), 74 deletions(-)
Whilst this looks good to me, I think we need an Ack from the DT
maintainers.
Rob, could you have a look please?
Thanks,
Will
> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> index 6ec743faabe8..091d45e6d61d 100644
> --- a/drivers/of/irq.c
> +++ b/drivers/of/irq.c
> @@ -24,6 +24,7 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_irq.h>
> +#include <linux/of_pci.h>
> #include <linux/string.h>
> #include <linux/slab.h>
>
> @@ -587,87 +588,16 @@ static u32 __of_msi_map_rid(struct device *dev, struct device_node **np,
> u32 rid_in)
> {
> struct device *parent_dev;
> - struct device_node *msi_controller_node;
> - struct device_node *msi_np = *np;
> - u32 map_mask, masked_rid, rid_base, msi_base, rid_len, phandle;
> - int msi_map_len;
> - bool matched;
> u32 rid_out = rid_in;
> - const __be32 *msi_map = NULL;
>
> /*
> * Walk up the device parent links looking for one with a
> * "msi-map" property.
> */
> - for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent) {
> - if (!parent_dev->of_node)
> - continue;
> -
> - msi_map = of_get_property(parent_dev->of_node,
> - "msi-map", &msi_map_len);
> - if (!msi_map)
> - continue;
> -
> - if (msi_map_len % (4 * sizeof(__be32))) {
> - dev_err(parent_dev, "Error: Bad msi-map length: %d\n",
> - msi_map_len);
> - return rid_out;
> - }
> - /* We have a good parent_dev and msi_map, let's use them. */
> - break;
> - }
> - if (!msi_map)
> - return rid_out;
> -
> - /* The default is to select all bits. */
> - map_mask = 0xffffffff;
> -
> - /*
> - * Can be overridden by "msi-map-mask" property. If
> - * of_property_read_u32() fails, the default is used.
> - */
> - of_property_read_u32(parent_dev->of_node, "msi-map-mask", &map_mask);
> -
> - masked_rid = map_mask & rid_in;
> - matched = false;
> - while (!matched && msi_map_len >= 4 * sizeof(__be32)) {
> - rid_base = be32_to_cpup(msi_map + 0);
> - phandle = be32_to_cpup(msi_map + 1);
> - msi_base = be32_to_cpup(msi_map + 2);
> - rid_len = be32_to_cpup(msi_map + 3);
> -
> - if (rid_base & ~map_mask) {
> - dev_err(parent_dev,
> - "Invalid msi-map translation - msi-map-mask (0x%x) ignores rid-base (0x%x)\n",
> - map_mask, rid_base);
> - return rid_out;
> - }
> -
> - msi_controller_node = of_find_node_by_phandle(phandle);
> -
> - matched = (masked_rid >= rid_base &&
> - masked_rid < rid_base + rid_len);
> - if (msi_np)
> - matched &= msi_np == msi_controller_node;
> -
> - if (matched && !msi_np) {
> - *np = msi_np = msi_controller_node;
> + for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent)
> + if (!of_pci_map_rid(parent_dev->of_node, rid_in, "msi-map",
> + "msi-map-mask", np, &rid_out))
> break;
> - }
> -
> - of_node_put(msi_controller_node);
> - msi_map_len -= 4 * sizeof(__be32);
> - msi_map += 4;
> - }
> - if (!matched)
> - return rid_out;
> -
> - rid_out = masked_rid - rid_base + msi_base;
> - dev_dbg(dev,
> - "msi-map at: %s, using mask %08x, rid-base: %08x, msi-base: %08x, length: %08x, rid: %08x -> %08x\n",
> - dev_name(parent_dev), map_mask, rid_base, msi_base,
> - rid_len, rid_in, rid_out);
> -
> return rid_out;
> }
>
> diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
> index 13f4fed38048..e6465cf7aea9 100644
> --- a/drivers/of/of_pci.c
> +++ b/drivers/of/of_pci.c
> @@ -306,3 +306,105 @@ struct msi_controller *of_pci_find_msi_chip_by_node(struct device_node *of_node)
> EXPORT_SYMBOL_GPL(of_pci_find_msi_chip_by_node);
>
> #endif /* CONFIG_PCI_MSI */
> +
> +/**
> + * of_pci_map_rid - Translate a requester ID through a downstream mapping.
> + * @np: root complex device node.
> + * @rid: PCI requester ID to map.
> + * @map_name: property name of the map to use.
> + * @map_mask_name: optional property name of the mask to use.
> + * @target: optional pointer to a target device node.
> + * @id_out: optional pointer to receive the translated ID.
> + *
> + * Given a PCI requester ID, look up the appropriate implementation-defined
> + * platform ID and/or the target device which receives transactions on that
> + * ID, as per the "iommu-map" and "msi-map" bindings. Either of @target or
> + * @id_out may be NULL if only the other is required. If @target points to
> + * a non-NULL device node pointer, only entries targeting that node will be
> + * matched; if it points to a NULL value, it will receive the device node of
> + * the first matching target phandle, with a reference held.
> + *
> + * Return: 0 on success or a standard error code on failure.
> + */
> +int of_pci_map_rid(struct device_node *np, u32 rid,
> + const char *map_name, const char *map_mask_name,
> + struct device_node **target, u32 *id_out)
> +{
> + u32 map_mask, masked_rid;
> + int map_len;
> + const __be32 *map = NULL;
> +
> + if (!np || !map_name || (!target && !id_out))
> + return -EINVAL;
> +
> + map = of_get_property(np, map_name, &map_len);
> + if (!map) {
> + if (target)
> + return -ENODEV;
> + /* Otherwise, no map implies no translation */
> + *id_out = rid;
> + return 0;
> + }
> +
> + if (!map_len || map_len % (4 * sizeof(*map))) {
> + pr_err("%s: Error: Bad %s length: %d\n", np->full_name,
> + map_name, map_len);
> + return -EINVAL;
> + }
> +
> + /* The default is to select all bits. */
> + map_mask = 0xffffffff;
> +
> + /*
> + * Can be overridden by "{iommu,msi}-map-mask" property.
> + * If of_property_read_u32() fails, the default is used.
> + */
> + if (map_mask_name)
> + of_property_read_u32(np, map_mask_name, &map_mask);
> +
> + masked_rid = map_mask & rid;
> + for ( ; map_len > 0; map_len -= 4 * sizeof(*map), map += 4) {
> + struct device_node *phandle_node;
> + u32 rid_base = be32_to_cpup(map + 0);
> + u32 phandle = be32_to_cpup(map + 1);
> + u32 out_base = be32_to_cpup(map + 2);
> + u32 rid_len = be32_to_cpup(map + 3);
> +
> + if (rid_base & ~map_mask) {
> + pr_err("%s: Invalid %s translation - %s-mask (0x%x) ignores rid-base (0x%x)\n",
> + np->full_name, map_name, map_name,
> + map_mask, rid_base);
> + return -EFAULT;
> + }
> +
> + if (masked_rid < rid_base || masked_rid >= rid_base + rid_len)
> + continue;
> +
> + phandle_node = of_find_node_by_phandle(phandle);
> + if (!phandle_node)
> + return -ENODEV;
> +
> + if (target) {
> + if (*target)
> + of_node_put(phandle_node);
> + else
> + *target = phandle_node;
> +
> + if (*target != phandle_node)
> + continue;
> + }
> +
> + if (id_out)
> + *id_out = masked_rid - rid_base + out_base;
> +
> + pr_debug("%s: %s, using mask %08x, rid-base: %08x, out-base: %08x, length: %08x, rid: %08x -> %08x\n",
> + np->full_name, map_name, map_mask, rid_base, out_base,
> + rid_len, rid, *id_out);
> + return 0;
> + }
> +
> + pr_err("%s: Invalid %s translation - no match for rid 0x%x on %s\n",
> + np->full_name, map_name, rid,
> + target && *target ? (*target)->full_name : "any target");
> + return -EFAULT;
> +}
> diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h
> index b969e9443962..7fd5cfce9140 100644
> --- a/include/linux/of_pci.h
> +++ b/include/linux/of_pci.h
> @@ -17,6 +17,9 @@ int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
> int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
> int of_get_pci_domain_nr(struct device_node *node);
> void of_pci_check_probe_only(void);
> +int of_pci_map_rid(struct device_node *np, u32 rid,
> + const char *map_name, const char *map_mask_name,
> + struct device_node **target, u32 *id_out);
> #else
> static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq)
> {
> @@ -52,6 +55,13 @@ of_get_pci_domain_nr(struct device_node *node)
> return -1;
> }
>
> +static inline int of_pci_map_rid(struct device_node *np, u32 rid,
> + const char *map_name, const char *map_mask_name,
> + struct device_node **target, u32 *id_out)
> +{
> + return -EINVAL;
> +}
> +
> static inline void of_pci_check_probe_only(void) { }
> #endif
>
> --
> 2.8.1.dirty
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-07-07 16:51 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-01 16:50 [PATCH v4 0/8] Generic DT bindings for PCI IOMMUs and ARM SMMUv3 Robin Murphy
[not found] ` <cover.1467388950.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-07-01 16:50 ` [PATCH v4 1/8] arm64: mm: change IOMMU notifier action to attach DMA ops Robin Murphy
[not found] ` <06d430a86f5d7f461308a9278bf25f40fb50d93c.1467388950.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-07-08 14:55 ` Will Deacon
[not found] ` <20160708145521.GD6493-5wv7dgnIgG8@public.gmane.org>
2016-07-08 17:06 ` Catalin Marinas
2016-07-01 16:50 ` [PATCH v4 2/8] Docs: dt: add PCI IOMMU map bindings Robin Murphy
2016-07-01 16:50 ` [PATCH v4 3/8] of/irq: Break out msi-map lookup (again) Robin Murphy
[not found] ` <cb0040f52022b049a3515f0b01a81a83381ad7d9.1467388950.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-07-07 16:51 ` Will Deacon [this message]
2016-07-18 17:54 ` Rob Herring
2016-07-01 16:50 ` [PATCH v4 4/8] iommu/of: Handle iommu-map property for PCI Robin Murphy
2016-07-01 16:50 ` [PATCH v4 5/8] iommu/of: Introduce iommu_fwspec Robin Murphy
[not found] ` <7947dbaa0e0d4ace8eebe8de1fe5810fe05f7734.1467388950.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-07-07 16:56 ` Lorenzo Pieralisi
2016-07-11 11:07 ` Robin Murphy
2016-07-01 16:50 ` [PATCH v4 6/8] iommu/arm-smmu: Implement of_xlate() for SMMUv3 Robin Murphy
[not found] ` <925b054b1e96dc83c0b1dc9607785d0346187366.1467388950.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-07-15 13:55 ` Lorenzo Pieralisi
2016-07-15 18:27 ` Robin Murphy
2016-07-29 14:46 ` Jean-Philippe Brucker
[not found] ` <20160729144655.GA3359-lfHAr0XZR/FyySVAYrpuPyZi+YwRKgec@public.gmane.org>
2016-07-29 18:55 ` Robin Murphy
[not found] ` <1d570682-d815-657e-2119-b706e0034e2c-5wv7dgnIgG8@public.gmane.org>
2016-08-24 15:08 ` Robin Murphy
2016-07-01 16:50 ` [PATCH v4 7/8] iommu/arm-smmu: Support non-PCI devices with SMMUv3 Robin Murphy
2016-07-01 16:50 ` [PATCH v4 8/8] iommu/arm-smmu: Set PRIVCFG in stage 1 STEs Robin Murphy
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=20160707165151.GF20682@arm.com \
--to=will.deacon-5wv7dgnigg8@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=jean-philippe.brucker-5wv7dgnIgG8@public.gmane.org \
--cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=robin.murphy-5wv7dgnIgG8@public.gmane.org \
--cc=thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.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).