bcm27xx: update patches from RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0439-of-Factor-out-addr-size-cells-parsing.patch
1 From 839aeedc908eb729b9014e7d1d38e109778a52d2 Mon Sep 17 00:00:00 2001
2 From: Robin Murphy <robin.murphy@arm.com>
3 Date: Tue, 2 Jul 2019 18:42:39 +0100
4 Subject: [PATCH] of: Factor out #{addr,size}-cells parsing
5
6 In some cases such as PCI host controllers, we may have a "parent bus"
7 which is an OF leaf node, but still need to correctly parse ranges from
8 the point of view of that bus. For that, factor out variants of the
9 "#addr-cells" and "#size-cells" parsers which do not assume they have a
10 device node and thus immediately traverse upwards before reading the
11 relevant property.
12
13 Signed-off-by: Robin Murphy <robin.murphy@arm.com>
14 [robh: don't make of_bus_n_{addr,size}_cells() public]
15 Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
16 Tested-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
17 Reviewed-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
18 Signed-off-by: Rob Herring <robh@kernel.org>
19
20 (cherry picked from commit b68ac8dc22ebbf003e26e44bf4dd3030c076df5a)
21 ---
22 drivers/of/address.c | 2 ++
23 drivers/of/base.c | 32 ++++++++++++++++++++++----------
24 drivers/of/of_private.h | 14 ++++++++++++++
25 3 files changed, 38 insertions(+), 10 deletions(-)
26
27 --- a/drivers/of/address.c
28 +++ b/drivers/of/address.c
29 @@ -14,6 +14,8 @@
30 #include <linux/slab.h>
31 #include <linux/string.h>
32
33 +#include "of_private.h"
34 +
35 /* Max address size we deal with */
36 #define OF_MAX_ADDR_CELLS 4
37 #define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
38 --- a/drivers/of/base.c
39 +++ b/drivers/of/base.c
40 @@ -86,34 +86,46 @@ static bool __of_node_is_type(const stru
41 return np && match && type && !strcmp(match, type);
42 }
43
44 -int of_n_addr_cells(struct device_node *np)
45 +int of_bus_n_addr_cells(struct device_node *np)
46 {
47 u32 cells;
48
49 - do {
50 - if (np->parent)
51 - np = np->parent;
52 + for (; np; np = np->parent)
53 if (!of_property_read_u32(np, "#address-cells", &cells))
54 return cells;
55 - } while (np->parent);
56 +
57 /* No #address-cells property for the root node */
58 return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
59 }
60 +
61 +int of_n_addr_cells(struct device_node *np)
62 +{
63 + if (np->parent)
64 + np = np->parent;
65 +
66 + return of_bus_n_addr_cells(np);
67 +}
68 EXPORT_SYMBOL(of_n_addr_cells);
69
70 -int of_n_size_cells(struct device_node *np)
71 +int of_bus_n_size_cells(struct device_node *np)
72 {
73 u32 cells;
74
75 - do {
76 - if (np->parent)
77 - np = np->parent;
78 + for (; np; np = np->parent)
79 if (!of_property_read_u32(np, "#size-cells", &cells))
80 return cells;
81 - } while (np->parent);
82 +
83 /* No #size-cells property for the root node */
84 return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
85 }
86 +
87 +int of_n_size_cells(struct device_node *np)
88 +{
89 + if (np->parent)
90 + np = np->parent;
91 +
92 + return of_bus_n_size_cells(np);
93 +}
94 EXPORT_SYMBOL(of_n_size_cells);
95
96 #ifdef CONFIG_NUMA
97 --- a/drivers/of/of_private.h
98 +++ b/drivers/of/of_private.h
99 @@ -158,4 +158,18 @@ extern void __of_sysfs_remove_bin_file(s
100 #define for_each_transaction_entry_reverse(_oft, _te) \
101 list_for_each_entry_reverse(_te, &(_oft)->te_list, node)
102
103 +extern int of_bus_n_addr_cells(struct device_node *np);
104 +extern int of_bus_n_size_cells(struct device_node *np);
105 +
106 +#ifdef CONFIG_OF_ADDRESS
107 +extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
108 + u64 *paddr, u64 *size);
109 +#else
110 +static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
111 + u64 *paddr, u64 *size)
112 +{
113 + return -ENODEV;
114 +}
115 +#endif
116 +
117 #endif /* _LINUX_OF_PRIVATE_H */