From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xen.org
Cc: julien.grall@citrix.com, Ian Campbell <ian.campbell@citrix.com>,
stefano.stabellini@eu.citrix.com
Subject: [PATCH v6 2/6] xen: dt: add dt_for_each_range helper
Date: Fri, 3 Jul 2015 16:56:08 +0100 [thread overview]
Message-ID: <1435938972-18288-2-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1435938959.9447.171.camel@citrix.com>
This function iterates over a node's ranges property and calls a
callback for each region. For now it only supplies the MMIO range (in
terms of CPU addresses, i.e. already translated).
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Reviewed-by: Julien Grall <julien.grall@citrix.com>
---
v6: Treat !0 as an error not < 0 for the callback.
---
xen/common/device_tree.c | 85 +++++++++++++++++++++++++++++++++++++++++
xen/include/xen/device_tree.h | 12 ++++++
2 files changed, 97 insertions(+)
diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 2508d4c..ce2ff66 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -722,6 +722,91 @@ int dt_device_get_address(const struct dt_device_node *dev, unsigned int index,
return 0;
}
+
+int dt_for_each_range(const struct dt_device_node *dev,
+ int (*cb)(const struct dt_device_node *,
+ u64 addr, u64 length,
+ void *),
+ void *data)
+{
+ const struct dt_device_node *parent = NULL;
+ const struct dt_bus *bus, *pbus;
+ const __be32 *ranges;
+ __be32 addr[DT_MAX_ADDR_CELLS];
+ unsigned int rlen;
+ int na, ns, pna, pns, rone;
+
+ bus = dt_match_bus(dev);
+ if ( !bus )
+ return 0; /* device is not a bus */
+
+ parent = dt_get_parent(dev);
+ if ( parent == NULL )
+ return -EINVAL;
+
+ ranges = dt_get_property(dev, "ranges", &rlen);
+ if ( ranges == NULL )
+ {
+ printk(XENLOG_ERR "DT: no ranges; cannot enumerate\n");
+ return -EINVAL;
+ }
+ if ( rlen == 0 ) /* Nothing to do */
+ return 0;
+
+ bus->count_cells(dev, &na, &ns);
+ if ( !DT_CHECK_COUNTS(na, ns) )
+ {
+ printk(XENLOG_ERR "dt_parse: Bad cell count for device %s\n",
+ dev->full_name);
+ return -EINVAL;
+ }
+
+ pbus = dt_match_bus(parent);
+ if ( pbus == NULL )
+ {
+ printk("DT: %s is not a valid bus\n", parent->full_name);
+ return -EINVAL;
+ }
+
+ pbus->count_cells(dev, &pna, &pns);
+ if ( !DT_CHECK_COUNTS(pna, pns) )
+ {
+ printk(XENLOG_ERR "dt_parse: Bad cell count for parent %s\n",
+ dev->full_name);
+ return -EINVAL;
+ }
+
+ /* Now walk through the ranges */
+ rlen /= 4;
+ rone = na + pna + ns;
+
+ dt_dprintk("%s: dev=%s, bus=%s, parent=%s, rlen=%d, rone=%d\n",
+ __func__,
+ dt_node_name(dev), bus->name,
+ dt_node_name(parent), rlen, rone);
+
+ for ( ; rlen >= rone; rlen -= rone, ranges += rone )
+ {
+ u64 a, s;
+ int ret;
+
+ memcpy(addr, ranges + na, 4 * pna);
+
+ a = __dt_translate_address(dev, addr, "ranges");
+ s = dt_read_number(ranges + na + pna, ns);
+
+ ret = cb(dev, a, s, data);
+ if ( ret )
+ {
+ dt_dprintk(" -> callback failed=%d\n", ret);
+ return ret;
+ }
+
+ }
+
+ return 0;
+}
+
/**
* dt_find_node_by_phandle - Find a node given a phandle
* @handle: phandle of the node to find
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 957f96e..46c5ba8 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -554,6 +554,18 @@ int dt_for_each_irq_map(const struct dt_device_node *dev,
void *data);
/**
+ * dt_for_each_range - Iterate over a nodes ranges property
+ * @dev: The node whose interrupt-map property should be iterated over
+ * @cb: Call back to call for each entry
+ * @data: Caller data passed to callback
+ */
+int dt_for_each_range(const struct dt_device_node *dev,
+ int (*cb)(const struct dt_device_node *,
+ u64 addr, u64 length,
+ void *),
+ void *data);
+
+/**
* dt_n_size_cells - Helper to retrieve the number of cell for the size
* @np: node to get the value
*
--
1.7.10.4
next prev parent reply other threads:[~2015-07-03 15:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-03 15:55 [PATCH v6 0/6] xen: arm: Parse PCI DT nodes' ranges and interrupt-map Ian Campbell
2015-07-03 15:56 ` [PATCH v6 1/6] xen: dt: add dt_for_each_irq_map helper Ian Campbell
2015-07-03 15:56 ` Ian Campbell [this message]
2015-07-03 15:56 ` [PATCH v6 3/6] xen: arm: drop redundant extra call to vgic_reserve_virq Ian Campbell
2015-07-03 15:56 ` [PATCH v6 4/6] xen: arm: map child MMIO and IRQs to dom0 for PCI bus DT nodes Ian Campbell
2015-07-06 10:58 ` Julien Grall
2015-07-03 15:56 ` [PATCH v6 5/6] xen: arm: Import of_bus PCI entry from Linux (as a dt_bus entry) Ian Campbell
2015-07-06 10:59 ` Julien Grall
2015-07-03 15:56 ` [PATCH v6 6/6] xen: arm: consolidate mmio and irq mapping to dom0 Ian Campbell
2015-07-06 11:02 ` Julien Grall
2015-07-06 11:04 ` [PATCH v6 0/6] xen: arm: Parse PCI DT nodes' ranges and interrupt-map Julien Grall
2015-07-06 13:56 ` Ian Campbell
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=1435938972-18288-2-git-send-email-ian.campbell@citrix.com \
--to=ian.campbell@citrix.com \
--cc=julien.grall@citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.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).