1 From ece28a7e105cedb5a9ebd2553aa41d965fb83b64 Mon Sep 17 00:00:00 2001
2 From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
3 Date: Tue, 28 May 2013 07:58:31 -0300
4 Subject: [PATCH 045/203] bus: mvebu-mbus: Add static window allocation to the
7 This patch adds static window allocation to the device tree binding.
8 Each first-child of the mbus-compatible node, with a suitable 'ranges'
9 property, declaring an address translation, will trigger an address
10 decoding window allocation.
12 Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
13 Tested-by: Andrew Lunn <andrew@lunn.ch>
14 Tested-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
16 drivers/bus/mvebu-mbus.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++-
17 1 file changed, 126 insertions(+), 1 deletion(-)
19 --- a/drivers/bus/mvebu-mbus.c
20 +++ b/drivers/bus/mvebu-mbus.c
21 @@ -902,6 +902,127 @@ int __init mvebu_mbus_init(const char *s
26 + * The window IDs in the ranges DT property have the following format:
27 + * - bits 28 to 31: MBus custom field
28 + * - bits 24 to 27: window target ID
29 + * - bits 16 to 23: window attribute ID
30 + * - bits 0 to 15: unused
32 +#define CUSTOM(id) (((id) & 0xF0000000) >> 24)
33 +#define TARGET(id) (((id) & 0x0F000000) >> 24)
34 +#define ATTR(id) (((id) & 0x00FF0000) >> 16)
36 +static int __init mbus_dt_setup_win(struct mvebu_mbus_state *mbus,
40 + const struct mvebu_mbus_mapping *map = mbus->soc->map;
44 + /* Search for a suitable window in the existing mappings */
45 + for (i = 0; map[i].name; i++)
46 + if (map[i].target == target &&
47 + map[i].attr == (attr & map[i].attrmask))
52 + pr_err("window 0x%x:0x%x is unknown, skipping\n",
57 + if (!mvebu_mbus_window_conflicts(mbus, base, size, target, attr)) {
58 + pr_err("cannot add window '%s', conflicts with another window\n",
63 + if (mvebu_mbus_alloc_window(mbus, base, size, MVEBU_MBUS_NO_REMAP,
65 + pr_err("cannot add window '%s', too many windows\n",
73 +mbus_parse_ranges(struct device_node *node,
74 + int *addr_cells, int *c_addr_cells, int *c_size_cells,
75 + int *cell_count, const __be32 **ranges_start,
76 + const __be32 **ranges_end)
79 + int ranges_len, tuple_len;
81 + /* Allow a node with no 'ranges' property */
82 + *ranges_start = of_get_property(node, "ranges", &ranges_len);
83 + if (*ranges_start == NULL) {
84 + *addr_cells = *c_addr_cells = *c_size_cells = *cell_count = 0;
85 + *ranges_start = *ranges_end = NULL;
88 + *ranges_end = *ranges_start + ranges_len / sizeof(__be32);
90 + *addr_cells = of_n_addr_cells(node);
92 + prop = of_get_property(node, "#address-cells", NULL);
93 + *c_addr_cells = be32_to_cpup(prop);
95 + prop = of_get_property(node, "#size-cells", NULL);
96 + *c_size_cells = be32_to_cpup(prop);
98 + *cell_count = *addr_cells + *c_addr_cells + *c_size_cells;
99 + tuple_len = (*cell_count) * sizeof(__be32);
101 + if (ranges_len % tuple_len) {
102 + pr_warn("malformed ranges entry '%s'\n", node->name);
108 +static int __init mbus_dt_setup(struct mvebu_mbus_state *mbus,
109 + struct device_node *np)
111 + int addr_cells, c_addr_cells, c_size_cells;
112 + int i, ret, cell_count;
113 + const __be32 *r, *ranges_start, *ranges_end;
115 + ret = mbus_parse_ranges(np, &addr_cells, &c_addr_cells,
116 + &c_size_cells, &cell_count,
117 + &ranges_start, &ranges_end);
121 + for (i = 0, r = ranges_start; r < ranges_end; r += cell_count, i++) {
122 + u32 windowid, base, size;
126 + * An entry with a non-zero custom field do not
127 + * correspond to a static window, so skip it.
129 + windowid = of_read_number(r, 1);
130 + if (CUSTOM(windowid))
133 + target = TARGET(windowid);
134 + attr = ATTR(windowid);
136 + base = of_read_number(r + c_addr_cells, addr_cells);
137 + size = of_read_number(r + c_addr_cells + addr_cells,
139 + ret = mbus_dt_setup_win(mbus, base, size, target, attr);
146 int __init mvebu_mbus_dt_init(void)
148 struct resource mbuswins_res, sdramwins_res;
149 @@ -946,6 +1067,10 @@ int __init mvebu_mbus_dt_init(void)
150 resource_size(&mbuswins_res),
152 resource_size(&sdramwins_res));
157 + /* Setup statically declared windows in the DT */
158 + return mbus_dt_setup(&mbus_state, np);