Skip to content

Commit

Permalink
dt: Add helper function for last_phandle updates
Browse files Browse the repository at this point in the history
Add helper functions for "last_phandle" access/update and
modify functions to use helper functions.

Acked-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Madhavan Srinivasan authored and stewartsmith committed Jun 27, 2017
1 parent 7e64996 commit 3ae55cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/device.c
Expand Up @@ -57,7 +57,7 @@ static struct dt_node *new_node(const char *name)
list_head_init(&node->properties);
list_head_init(&node->children);
/* FIXME: locking? */
node->phandle = ++last_phandle;
node->phandle = new_phandle();
return node;
}

Expand Down Expand Up @@ -469,7 +469,7 @@ struct dt_property *dt_add_property(struct dt_node *node,
assert(size == 4);
node->phandle = *(const u32 *)val;
if (node->phandle >= last_phandle)
last_phandle = node->phandle;
set_last_phandle(node->phandle);
return NULL;
}

Expand Down
8 changes: 4 additions & 4 deletions core/fdt.c
Expand Up @@ -191,11 +191,11 @@ void *create_dtb(const struct dt_node *root, bool exclusive)
{
void *fdt = NULL;
size_t len = DEVICE_TREE_MAX_SIZE;
uint32_t old_last_phandle = last_phandle;
uint32_t old_last_phandle = get_last_phandle();
int ret;

do {
last_phandle = old_last_phandle;
set_last_phandle(old_last_phandle);
fdt_error = 0;
fdt = malloc(len);
if (!fdt) {
Expand Down Expand Up @@ -244,10 +244,10 @@ static int64_t opal_get_device_tree(uint32_t phandle,
return OPAL_PARAMETER;

fdt_error = 0;
old_last_phandle = last_phandle;
old_last_phandle = get_last_phandle();
ret = __create_dtb(fdt, len, root, true);
if (ret) {
last_phandle = old_last_phandle;
set_last_phandle(old_last_phandle);
if (ret == -FDT_ERR_NOSPACE)
return OPAL_NO_MEM;

Expand Down
16 changes: 16 additions & 0 deletions include/device.h
Expand Up @@ -61,6 +61,22 @@ struct dt_node *dt_new_root(const char *name);
/* Graft a root node into this tree. */
bool dt_attach_root(struct dt_node *parent, struct dt_node *root);

/* Wrappers for last_phandle operations */
static inline u32 get_last_phandle(void)
{
return last_phandle;
}

static inline void set_last_phandle(u32 phandle)
{
last_phandle = phandle;
}

static inline u32 new_phandle(void)
{
return ++last_phandle;
}

/* Add a child node. */
struct dt_node *dt_new(struct dt_node *parent, const char *name);
struct dt_node *dt_new_addr(struct dt_node *parent, const char *name,
Expand Down

0 comments on commit 3ae55cc

Please sign in to comment.