From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Peter Crosthwaite <peter.crosthwaite@petalogix.com>,
David Gibson <david@gibson.dropbear.id.au>,
Alexander Graf <agraf@suse.de>,
patches@linaro.org
Subject: [Qemu-devel] [PATCH 1/2] device_tree: Add qemu_devtree_setprop_sized_cells() utility function
Date: Mon, 24 Jun 2013 11:22:55 +0100 [thread overview]
Message-ID: <1372069376-30640-2-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1372069376-30640-1-git-send-email-peter.maydell@linaro.org>
We already have a qemu_devtree_setprop_cells() which sets a dtb
property to an array of cells whose values are specified by varargs.
However for the fairly common case of setting a property to a list
of addresses or of address,size pairs the number of cells used by
each element in the list depends on the parent's #address-cells
and #size-cells properties. To make this easier we provide an analogous
qemu_devtree_setprop_sized_cells() function which allows the number
of cells used by each element to be specified.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
device_tree.c | 48 ++++++++++++++++++++++++++++++++++++++++++
include/sysemu/device_tree.h | 29 +++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/device_tree.c b/device_tree.c
index 69be9da..15a081c 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -319,3 +319,51 @@ void qemu_devtree_dumpdtb(void *fdt, int size)
}
}
+
+int qemu_devtree_setprop_sized_cells(void *fdt, const char *node_path,
+ const char *property, ...)
+{
+ uint32_t *propcells;
+ uint32_t propsize = 0;
+ va_list ap;
+ uint32_t ncells;
+ uint64_t value;
+ int i, argnum;
+
+ va_start(ap, property);
+ for (;;) {
+ ncells = va_arg(ap, uint32_t);
+ if (!ncells) {
+ break;
+ }
+ assert(ncells < 3);
+ propsize += ncells;
+ value = va_arg(ap, uint64_t);
+ }
+ va_end(ap);
+
+ propcells = g_new0(uint32_t, propsize);
+
+ i = 0;
+ va_start(ap, property);
+ for (argnum = 1; ; argnum++) {
+ uint32_t hival;
+
+ ncells = va_arg(ap, uint32_t);
+ if (!ncells) {
+ break;
+ }
+ value = va_arg(ap, uint64_t);
+ hival = cpu_to_be32(value >> 32);
+ if (ncells > 1) {
+ propcells[i++] = hival;
+ } else if (hival != 0) {
+ return argnum;
+ }
+ propcells[i++] = cpu_to_be32(value);
+ }
+ va_end(ap);
+
+ return qemu_devtree_setprop(fdt, node_path, property, propcells,
+ propsize * sizeof(uint32_t));
+}
diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index f0b3f35..d7691f9 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -51,4 +51,33 @@ int qemu_devtree_add_subnode(void *fdt, const char *name);
void qemu_devtree_dumpdtb(void *fdt, int size);
+/**
+ * qemu_devtree_setprop_sized_cells:
+ * @fdt: device tree blob
+ * @node_path: node to set property on
+ * @property: property to set
+ * @...: 0-terminated list of uint32_t number-of-cells, uint64_t value pairs
+ *
+ * Set the specified property on the specified node in the device tree
+ * to be an array of cells. The values of the cells are specified via
+ * the varargs list, which alternates between "number of cells used by
+ * this value" and "value" (terminated when number-of-cells is zero).
+ * number-of-cells must be either 1 or 2 (other values will assert()).
+ *
+ * This function is useful because device tree nodes often have cell arrays
+ * which are either lists of addresses or lists of address,size tuples, but
+ * the number of cells used for each element vary depending on the
+ * #address-cells and #size-cells properties of their parent node.
+ * If you know all your cell elements are one cell wide you can use the
+ * simpler qemu_devtree_setprop_cells().
+ *
+ * Return value: 0 on success, <0 if setting the property failed,
+ * n (for n>0) if value n wouldn't fit in the required number of cells.
+ * (This slightly odd convention is for the benefit of callers who might
+ * wish to print different error messages depending on which value
+ * was too large to fit, since values might be user-specified.)
+ */
+int qemu_devtree_setprop_sized_cells(void *fdt, const char *node_path,
+ const char *property, ...);
+
#endif /* __DEVICE_TREE_H__ */
--
1.7.9.5
next prev parent reply other threads:[~2013-06-24 10:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-24 10:22 [Qemu-devel] [PATCH 0/2] device_tree: add qemu_devtree_setprop_sized_cells() Peter Maydell
2013-06-24 10:22 ` Peter Maydell [this message]
2013-06-24 10:56 ` [Qemu-devel] [PATCH 1/2] device_tree: Add qemu_devtree_setprop_sized_cells() utility function Alexander Graf
2013-06-24 11:02 ` Peter Maydell
2013-06-25 23:38 ` David Gibson
2013-06-26 8:49 ` Peter Maydell
2013-06-26 10:31 ` Alexander Graf
2013-06-26 10:50 ` Peter Maydell
2013-06-26 11:42 ` Alexander Graf
2013-06-26 12:38 ` Peter Crosthwaite
2013-06-26 12:44 ` Alexander Graf
2013-06-27 0:17 ` David Gibson
2013-06-27 0:27 ` Anthony Liguori
2013-06-26 13:13 ` Peter Maydell
2013-06-26 13:31 ` Peter Maydell
2013-06-27 0:15 ` David Gibson
2013-06-27 0:10 ` David Gibson
2013-06-24 10:22 ` [Qemu-devel] [PATCH 2/2] arm/boot: Use qemu_devtree_setprop_sized_cells() Peter Maydell
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=1372069376-30640-2-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=agraf@suse.de \
--cc=david@gibson.dropbear.id.au \
--cc=patches@linaro.org \
--cc=peter.crosthwaite@petalogix.com \
--cc=qemu-devel@nongnu.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).