Skip to content

Commit b68ac8d

Browse files
rmurphy-armrobherring
authored andcommitted
of: Factor out #{addr,size}-cells parsing
In some cases such as PCI host controllers, we may have a "parent bus" which is an OF leaf node, but still need to correctly parse ranges from the point of view of that bus. For that, factor out variants of the "#addr-cells" and "#size-cells" parsers which do not assume they have a device node and thus immediately traverse upwards before reading the relevant property. Signed-off-by: Robin Murphy <robin.murphy@arm.com> [robh: don't make of_bus_n_{addr,size}_cells() public] Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Tested-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent c60bf3e commit b68ac8d

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎drivers/of/address.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/slab.h>
1515
#include <linux/string.h>
1616

17+
#include "of_private.h"
18+
1719
/* Max address size we deal with */
1820
#define OF_MAX_ADDR_CELLS 4
1921
#define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)

‎drivers/of/base.c‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,46 @@ static bool __of_node_is_type(const struct device_node *np, const char *type)
8686
return np && match && type && !strcmp(match, type);
8787
}
8888

89-
int of_n_addr_cells(struct device_node *np)
89+
int of_bus_n_addr_cells(struct device_node *np)
9090
{
9191
u32 cells;
9292

93-
do {
94-
if (np->parent)
95-
np = np->parent;
93+
for (; np; np = np->parent)
9694
if (!of_property_read_u32(np, "#address-cells", &cells))
9795
return cells;
98-
} while (np->parent);
96+
9997
/* No #address-cells property for the root node */
10098
return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
10199
}
100+
101+
int of_n_addr_cells(struct device_node *np)
102+
{
103+
if (np->parent)
104+
np = np->parent;
105+
106+
return of_bus_n_addr_cells(np);
107+
}
102108
EXPORT_SYMBOL(of_n_addr_cells);
103109

104-
int of_n_size_cells(struct device_node *np)
110+
int of_bus_n_size_cells(struct device_node *np)
105111
{
106112
u32 cells;
107113

108-
do {
109-
if (np->parent)
110-
np = np->parent;
114+
for (; np; np = np->parent)
111115
if (!of_property_read_u32(np, "#size-cells", &cells))
112116
return cells;
113-
} while (np->parent);
117+
114118
/* No #size-cells property for the root node */
115119
return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
116120
}
121+
122+
int of_n_size_cells(struct device_node *np)
123+
{
124+
if (np->parent)
125+
np = np->parent;
126+
127+
return of_bus_n_size_cells(np);
128+
}
117129
EXPORT_SYMBOL(of_n_size_cells);
118130

119131
#ifdef CONFIG_NUMA

‎drivers/of/of_private.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ extern void __of_sysfs_remove_bin_file(struct device_node *np,
158158
#define for_each_transaction_entry_reverse(_oft, _te) \
159159
list_for_each_entry_reverse(_te, &(_oft)->te_list, node)
160160

161+
extern int of_bus_n_addr_cells(struct device_node *np);
162+
extern int of_bus_n_size_cells(struct device_node *np);
163+
161164
#ifdef CONFIG_OF_ADDRESS
162165
extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
163166
u64 *paddr, u64 *size);

0 commit comments

Comments
 (0)