Patchwork [07/25] dt: add helper for phandle allocation

login
register
mail settings
Submitter Alexander Graf
Date May 30, 2012, 11 a.m.
Message ID <1338375646-15064-8-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/161945/
State New
Headers show

Comments

Alexander Graf - May 30, 2012, 11 a.m.
Phandle references work by having 2 pieces:

  - a "phandle" 1-cell property in the device tree node
  - a reference to the same value in a property we want to point
    to the other node

To generate the 1-cell property, we need an allocation mechanism that
gives us a unique number space. This patch adds an allocator for these
properties.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 device_tree.c |    7 +++++++
 device_tree.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)
Scott Wood - May 31, 2012, 10:28 p.m.
On 05/30/2012 06:00 AM, Alexander Graf wrote:
> Phandle references work by having 2 pieces:
> 
>   - a "phandle" 1-cell property in the device tree node
>   - a reference to the same value in a property we want to point
>     to the other node
> 
> To generate the 1-cell property, we need an allocation mechanism that
> gives us a unique number space. This patch adds an allocator for these
> properties.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  device_tree.c |    7 +++++++
>  device_tree.h |    1 +
>  2 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/device_tree.c b/device_tree.c
> index d4f1f0a..317bdd0 100644
> --- a/device_tree.c
> +++ b/device_tree.c
> @@ -220,6 +220,13 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,
>      return qemu_devtree_setprop_cell(fdt, node_path, property, phandle);
>  }
>  
> +uint32_t qemu_devtree_alloc_phandle(void *fdt)
> +{
> +    static int phandle = 0x8000;
> +
> +    return phandle++;
> +}

An external configuration tool may want to use dumpdtb/dtb to merge in
nodes from other sources (e.g. the host device tree), which may have
unchangeable phandles that conflict with these.

It would be nice if the starting point could be overridden on the
command line.  This can be a TODO for later, of course.

-Scott

Patch

diff --git a/device_tree.c b/device_tree.c
index d4f1f0a..317bdd0 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -220,6 +220,13 @@  int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,
     return qemu_devtree_setprop_cell(fdt, node_path, property, phandle);
 }
 
+uint32_t qemu_devtree_alloc_phandle(void *fdt)
+{
+    static int phandle = 0x8000;
+
+    return phandle++;
+}
+
 int qemu_devtree_nop_node(void *fdt, const char *node_path)
 {
     int r;
diff --git a/device_tree.h b/device_tree.h
index 5464dc7..f37a4da 100644
--- a/device_tree.h
+++ b/device_tree.h
@@ -35,6 +35,7 @@  int qemu_devtree_setprop_string(void *fdt, const char *node_path,
 int qemu_devtree_setprop_phandle(void *fdt, const char *node_path,
                                  const char *property, const char *string);
 uint32_t qemu_devtree_get_phandle(void *fdt, const char *path);
+uint32_t qemu_devtree_alloc_phandle(void *fdt);
 int qemu_devtree_nop_node(void *fdt, const char *node_path);
 int qemu_devtree_add_subnode(void *fdt, const char *name);