[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/5] xen: device-tree: add accessors for the addr/size-cells of a node's children.
The existing dt_n_{addr,size}_cells functions tell you which sizes will apply to this node, which are the #address/size-cells properties of the node's *parent* (or grandparent, etc). In some cases we need to know what size applies to a nodes children, which can include the #address/size-cells properties of the node itself (or its parent). Refactor the existing function to allow both possibilities. Clean up the grammar of the existing doc comments a bit. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- xen/common/device_tree.c | 35 ++++++++++++++++++++++++++---- xen/include/xen/device_tree.h | 47 ++++++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index f72b2e9..a4e4eb5 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -368,13 +368,17 @@ dt_find_matching_node(struct dt_device_node *from, return NULL; } -int dt_n_addr_cells(const struct dt_device_node *np) +/* If parent is true then start from the parent. */ +static int dt_n_addr_cells_common(const struct dt_device_node *np, bool parent) { const __be32 *ip; do { - if ( np->parent ) + if ( parent && np->parent ) np = np->parent; + else + parent = 1; + ip = dt_get_property(np, "#address-cells", NULL); if ( ip ) return be32_to_cpup(ip); @@ -383,13 +387,26 @@ int dt_n_addr_cells(const struct dt_device_node *np) return DT_ROOT_NODE_ADDR_CELLS_DEFAULT; } -int dt_n_size_cells(const struct dt_device_node *np) +int dt_n_addr_cells(const struct dt_device_node *np) +{ + return dt_n_addr_cells_common(np, true); +} + +int dt_n_addr_cells_children(const struct dt_device_node *np) +{ + return dt_n_addr_cells_common(np, false); +} + +/* If parent is true then start from the parent. */ +static int dt_n_size_cells_common(const struct dt_device_node *np, bool parent) { const __be32 *ip; do { - if ( np->parent ) + if ( parent && np->parent ) np = np->parent; + else + parent = 1; ip = dt_get_property(np, "#size-cells", NULL); if ( ip ) return be32_to_cpup(ip); @@ -398,6 +415,16 @@ int dt_n_size_cells(const struct dt_device_node *np) return DT_ROOT_NODE_SIZE_CELLS_DEFAULT; } +int dt_n_size_cells(const struct dt_device_node *np) +{ + return dt_n_size_cells_common(np, true); +} +int dt_n_size_cells_children(const struct dt_device_node *np) +{ + return dt_n_size_cells_common(np, false); +} + + /* * Default translator (generic bus) */ diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 08db8bc..ac2e876 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -513,24 +513,55 @@ int dt_device_get_raw_irq(const struct dt_device_node *device, int index, int dt_irq_translate(const struct dt_raw_irq *raw, struct dt_irq *out_irq); /** - * dt_n_size_cells - Helper to retrieve the number of cell for the size - * @np: node to get the value + * dt_n_size_cells - Helper to retrieve the number of cells used for + * size properties of a node (e.g. the size part of a reg property). + * + * @np: node to get the value for * - * This function retrieves for a give device-tree node the number of - * cell for the size field. + * This function retrieves for a given device-tree node the number of + * cells used for size properties, which is the #size-cells property of + * the node's parent (or grandparent etc). */ int dt_n_size_cells(const struct dt_device_node *np); /** - * dt_n_addr_cells - Helper to retrieve the number of cell for the address - * @np: node to get the value + * dt_n_size_cells_children - Helper to retrieve the number of cells + * used for size properties of child nodes. + * + * @np: node to get the value for + * + * This function retrieves the #size-cells field which will apply to + * this node's children, which may be specified by this node or its + * parent, grantparent etc. + */ +int dt_n_size_cells_children(const struct dt_device_node *node); + +/** + * dt_n_addr_cells - Helper to retrieve the number of cells for + * address properties of a node (e.g. the adddress part of a reg + * property). + * + * @np: node to get the value for * - * This function retrieves for a give device-tree node the number of - * cell for the address field. + * This function retrieves for a given device-tree node the number of + * cells used for address properties, which is the #address-cells + * property of the node's parent (or grantparent, etc). */ int dt_n_addr_cells(const struct dt_device_node *np); /** + * dt_n_size_cells_children - Helper to retrieve the number of cells + * used for size properties of child nodes. + * + * @np: node to get the value for + * + * This function retrieves the #address-cells field which will apply to + * this node's children, which may be specified by this node or its + * parent, grantparent etc. + */ +int dt_n_addr_cells_children(const struct dt_device_node *np); + +/** * dt_device_is_available - Check if a device is available for use * * @device: Node to check for availability -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |