Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 2 | #include <linux/string.h> |
| 3 | #include <linux/kernel.h> |
Stephen Rothwell | f85ff30 | 2007-05-01 16:40:36 +1000 | [diff] [blame] | 4 | #include <linux/of.h> |
Christoph Hellwig | 5a7faef | 2018-08-28 11:25:51 +0200 | [diff] [blame] | 5 | #include <linux/dma-mapping.h> |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 6 | #include <linux/init.h> |
Paul Gortmaker | 066bcac | 2011-07-22 13:18:16 -0400 | [diff] [blame] | 7 | #include <linux/export.h> |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 8 | #include <linux/mod_devicetable.h> |
| 9 | #include <linux/slab.h> |
Stephen Rothwell | 3f23de1 | 2007-05-03 02:38:57 +1000 | [diff] [blame] | 10 | #include <linux/errno.h> |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 11 | #include <linux/irq.h> |
Stephen Rothwell | 3f23de1 | 2007-05-03 02:38:57 +1000 | [diff] [blame] | 12 | #include <linux/of_device.h> |
| 13 | #include <linux/of_platform.h> |
Paul Gortmaker | c2068da | 2011-08-01 13:42:48 -0400 | [diff] [blame] | 14 | #include <asm/spitfire.h> |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 15 | |
Robert Reif | c9f5b7e | 2009-06-04 02:00:02 -0700 | [diff] [blame] | 16 | #include "of_device_common.h" |
| 17 | |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 18 | void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name) |
| 19 | { |
| 20 | unsigned long ret = res->start + offset; |
David S. Miller | 6bda573 | 2006-10-18 23:00:35 -0700 | [diff] [blame] | 21 | struct resource *r; |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 22 | |
David S. Miller | 6bda573 | 2006-10-18 23:00:35 -0700 | [diff] [blame] | 23 | if (res->flags & IORESOURCE_MEM) |
| 24 | r = request_mem_region(ret, size, name); |
| 25 | else |
| 26 | r = request_region(ret, size, name); |
| 27 | if (!r) |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 28 | ret = 0; |
| 29 | |
| 30 | return (void __iomem *) ret; |
| 31 | } |
| 32 | EXPORT_SYMBOL(of_ioremap); |
| 33 | |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 34 | void of_iounmap(struct resource *res, void __iomem *base, unsigned long size) |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 35 | { |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 36 | if (res->flags & IORESOURCE_MEM) |
| 37 | release_mem_region((unsigned long) base, size); |
| 38 | else |
| 39 | release_region((unsigned long) base, size); |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 40 | } |
| 41 | EXPORT_SYMBOL(of_iounmap); |
| 42 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 43 | /* |
| 44 | * PCI bus specific translator |
| 45 | */ |
| 46 | |
| 47 | static int of_bus_pci_match(struct device_node *np) |
| 48 | { |
Rob Herring | 29c990d | 2018-11-16 15:06:58 -0600 | [diff] [blame] | 49 | if (of_node_name_eq(np, "pci")) { |
David S. Miller | a165b42 | 2007-03-29 01:50:16 -0700 | [diff] [blame] | 50 | const char *model = of_get_property(np, "model", NULL); |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 51 | |
| 52 | if (model && !strcmp(model, "SUNW,simba")) |
| 53 | return 0; |
| 54 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 55 | /* Do not do PCI specific frobbing if the |
| 56 | * PCI bridge lacks a ranges property. We |
| 57 | * want to pass it through up to the next |
| 58 | * parent as-is, not with the PCI translate |
| 59 | * method which chops off the top address cell. |
| 60 | */ |
| 61 | if (!of_find_property(np, "ranges", NULL)) |
| 62 | return 0; |
| 63 | |
| 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 68 | } |
| 69 | |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 70 | static int of_bus_simba_match(struct device_node *np) |
| 71 | { |
David S. Miller | a165b42 | 2007-03-29 01:50:16 -0700 | [diff] [blame] | 72 | const char *model = of_get_property(np, "model", NULL); |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 73 | |
| 74 | if (model && !strcmp(model, "SUNW,simba")) |
| 75 | return 1; |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 76 | |
| 77 | /* Treat PCI busses lacking ranges property just like |
| 78 | * simba. |
| 79 | */ |
Rob Herring | 29c990d | 2018-11-16 15:06:58 -0600 | [diff] [blame] | 80 | if (of_node_name_eq(np, "pci")) { |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 81 | if (!of_find_property(np, "ranges", NULL)) |
| 82 | return 1; |
| 83 | } |
| 84 | |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int of_bus_simba_map(u32 *addr, const u32 *range, |
| 89 | int na, int ns, int pna) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 94 | static void of_bus_pci_count_cells(struct device_node *np, |
| 95 | int *addrc, int *sizec) |
| 96 | { |
| 97 | if (addrc) |
| 98 | *addrc = 3; |
| 99 | if (sizec) |
| 100 | *sizec = 2; |
| 101 | } |
| 102 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 103 | static int of_bus_pci_map(u32 *addr, const u32 *range, |
| 104 | int na, int ns, int pna) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 105 | { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 106 | u32 result[OF_MAX_ADDR_CELLS]; |
| 107 | int i; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 108 | |
| 109 | /* Check address type match */ |
David S. Miller | 4230fa3 | 2009-12-09 01:39:09 -0800 | [diff] [blame] | 110 | if (!((addr[0] ^ range[0]) & 0x03000000)) |
| 111 | goto type_match; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 112 | |
David S. Miller | 4230fa3 | 2009-12-09 01:39:09 -0800 | [diff] [blame] | 113 | /* Special exception, we can map a 64-bit address into |
| 114 | * a 32-bit range. |
| 115 | */ |
| 116 | if ((addr[0] & 0x03000000) == 0x03000000 && |
| 117 | (range[0] & 0x03000000) == 0x02000000) |
| 118 | goto type_match; |
| 119 | |
| 120 | return -EINVAL; |
| 121 | |
| 122 | type_match: |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 123 | if (of_out_of_range(addr + 1, range + 1, range + na + pna, |
| 124 | na - 1, ns)) |
| 125 | return -EINVAL; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 126 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 127 | /* Start with the parent range base. */ |
| 128 | memcpy(result, range + na, pna * 4); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 129 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 130 | /* Add in the child address offset, skipping high cell. */ |
| 131 | for (i = 0; i < na - 1; i++) |
| 132 | result[pna - 1 - i] += |
| 133 | (addr[na - 1 - i] - |
| 134 | range[na - 1 - i]); |
| 135 | |
| 136 | memcpy(addr, result, pna * 4); |
| 137 | |
| 138 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 139 | } |
| 140 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 141 | static unsigned long of_bus_pci_get_flags(const u32 *addr, unsigned long flags) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 142 | { |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 143 | u32 w = addr[0]; |
| 144 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 145 | /* For PCI, we override whatever child busses may have used. */ |
| 146 | flags = 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 147 | switch((w >> 24) & 0x03) { |
| 148 | case 0x01: |
| 149 | flags |= IORESOURCE_IO; |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 150 | break; |
| 151 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 152 | case 0x02: /* 32 bits */ |
| 153 | case 0x03: /* 64 bits */ |
| 154 | flags |= IORESOURCE_MEM; |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 155 | break; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 156 | } |
| 157 | if (w & 0x40000000) |
| 158 | flags |= IORESOURCE_PREFETCH; |
| 159 | return flags; |
| 160 | } |
| 161 | |
| 162 | /* |
David S. Miller | 4130a4b | 2006-10-25 22:31:06 -0700 | [diff] [blame] | 163 | * FHC/Central bus specific translator. |
| 164 | * |
| 165 | * This is just needed to hard-code the address and size cell |
| 166 | * counts. 'fhc' and 'central' nodes lack the #address-cells and |
| 167 | * #size-cells properties, and if you walk to the root on such |
| 168 | * Enterprise boxes all you'll get is a #size-cells of 2 which is |
| 169 | * not what we want to use. |
| 170 | */ |
| 171 | static int of_bus_fhc_match(struct device_node *np) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 172 | { |
Rob Herring | 29c990d | 2018-11-16 15:06:58 -0600 | [diff] [blame] | 173 | return of_node_name_eq(np, "fhc") || |
| 174 | of_node_name_eq(np, "central"); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 175 | } |
| 176 | |
David S. Miller | 4130a4b | 2006-10-25 22:31:06 -0700 | [diff] [blame] | 177 | #define of_bus_fhc_count_cells of_bus_sbus_count_cells |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Array of bus specific translators |
| 181 | */ |
| 182 | |
| 183 | static struct of_bus of_busses[] = { |
| 184 | /* PCI */ |
| 185 | { |
| 186 | .name = "pci", |
| 187 | .addr_prop_name = "assigned-addresses", |
| 188 | .match = of_bus_pci_match, |
| 189 | .count_cells = of_bus_pci_count_cells, |
| 190 | .map = of_bus_pci_map, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 191 | .get_flags = of_bus_pci_get_flags, |
| 192 | }, |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 193 | /* SIMBA */ |
| 194 | { |
| 195 | .name = "simba", |
| 196 | .addr_prop_name = "assigned-addresses", |
| 197 | .match = of_bus_simba_match, |
| 198 | .count_cells = of_bus_pci_count_cells, |
| 199 | .map = of_bus_simba_map, |
| 200 | .get_flags = of_bus_pci_get_flags, |
| 201 | }, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 202 | /* SBUS */ |
| 203 | { |
| 204 | .name = "sbus", |
| 205 | .addr_prop_name = "reg", |
| 206 | .match = of_bus_sbus_match, |
| 207 | .count_cells = of_bus_sbus_count_cells, |
David S. Miller | 4130a4b | 2006-10-25 22:31:06 -0700 | [diff] [blame] | 208 | .map = of_bus_default_map, |
| 209 | .get_flags = of_bus_default_get_flags, |
| 210 | }, |
| 211 | /* FHC */ |
| 212 | { |
| 213 | .name = "fhc", |
| 214 | .addr_prop_name = "reg", |
| 215 | .match = of_bus_fhc_match, |
| 216 | .count_cells = of_bus_fhc_count_cells, |
| 217 | .map = of_bus_default_map, |
| 218 | .get_flags = of_bus_default_get_flags, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 219 | }, |
| 220 | /* Default */ |
| 221 | { |
| 222 | .name = "default", |
| 223 | .addr_prop_name = "reg", |
| 224 | .match = NULL, |
| 225 | .count_cells = of_bus_default_count_cells, |
| 226 | .map = of_bus_default_map, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 227 | .get_flags = of_bus_default_get_flags, |
| 228 | }, |
| 229 | }; |
| 230 | |
| 231 | static struct of_bus *of_match_bus(struct device_node *np) |
| 232 | { |
| 233 | int i; |
| 234 | |
| 235 | for (i = 0; i < ARRAY_SIZE(of_busses); i ++) |
| 236 | if (!of_busses[i].match || of_busses[i].match(np)) |
| 237 | return &of_busses[i]; |
| 238 | BUG(); |
| 239 | return NULL; |
| 240 | } |
| 241 | |
| 242 | static int __init build_one_resource(struct device_node *parent, |
| 243 | struct of_bus *bus, |
| 244 | struct of_bus *pbus, |
| 245 | u32 *addr, |
| 246 | int na, int ns, int pna) |
| 247 | { |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 248 | const u32 *ranges; |
David S. Miller | 21cd883 | 2008-09-11 23:53:41 -0700 | [diff] [blame] | 249 | int rone, rlen; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 250 | |
| 251 | ranges = of_get_property(parent, "ranges", &rlen); |
| 252 | if (ranges == NULL || rlen == 0) { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 253 | u32 result[OF_MAX_ADDR_CELLS]; |
| 254 | int i; |
| 255 | |
| 256 | memset(result, 0, pna * 4); |
| 257 | for (i = 0; i < na; i++) |
| 258 | result[pna - 1 - i] = |
| 259 | addr[na - 1 - i]; |
| 260 | |
| 261 | memcpy(addr, result, pna * 4); |
| 262 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* Now walk through the ranges */ |
| 266 | rlen /= 4; |
| 267 | rone = na + pna + ns; |
| 268 | for (; rlen >= rone; rlen -= rone, ranges += rone) { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 269 | if (!bus->map(addr, ranges, na, ns, pna)) |
| 270 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 271 | } |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 272 | |
David S. Miller | 49d23cf | 2007-05-13 22:01:18 -0700 | [diff] [blame] | 273 | /* When we miss an I/O space match on PCI, just pass it up |
| 274 | * to the next PCI bridge and/or controller. |
| 275 | */ |
| 276 | if (!strcmp(bus->name, "pci") && |
| 277 | (addr[0] & 0x03000000) == 0x01000000) |
| 278 | return 0; |
| 279 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 280 | return 1; |
| 281 | } |
| 282 | |
| 283 | static int __init use_1to1_mapping(struct device_node *pp) |
| 284 | { |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 285 | /* If we have a ranges property in the parent, use it. */ |
| 286 | if (of_find_property(pp, "ranges", NULL) != NULL) |
| 287 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 288 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 289 | /* If the parent is the dma node of an ISA bus, pass |
| 290 | * the translation up to the root. |
David S. Miller | 5280267 | 2008-09-03 02:04:41 -0700 | [diff] [blame] | 291 | * |
| 292 | * Some SBUS devices use intermediate nodes to express |
| 293 | * hierarchy within the device itself. These aren't |
| 294 | * real bus nodes, and don't have a 'ranges' property. |
| 295 | * But, we should still pass the translation work up |
| 296 | * to the SBUS itself. |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 297 | */ |
Rob Herring | 29c990d | 2018-11-16 15:06:58 -0600 | [diff] [blame] | 298 | if (of_node_name_eq(pp, "dma") || |
| 299 | of_node_name_eq(pp, "espdma") || |
| 300 | of_node_name_eq(pp, "ledma") || |
| 301 | of_node_name_eq(pp, "lebuffer")) |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 304 | /* Similarly for all PCI bridges, if we get this far |
| 305 | * it lacks a ranges property, and this will include |
| 306 | * cases like Simba. |
| 307 | */ |
Rob Herring | 29c990d | 2018-11-16 15:06:58 -0600 | [diff] [blame] | 308 | if (of_node_name_eq(pp, "pci")) |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 309 | return 0; |
| 310 | |
| 311 | return 1; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 312 | } |
| 313 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 314 | static int of_resource_verbose; |
| 315 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 316 | static void __init build_device_resources(struct platform_device *op, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 317 | struct device *parent) |
| 318 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 319 | struct platform_device *p_op; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 320 | struct of_bus *bus; |
| 321 | int na, ns; |
| 322 | int index, num_reg; |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 323 | const void *preg; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 324 | |
| 325 | if (!parent) |
| 326 | return; |
| 327 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 328 | p_op = to_platform_device(parent); |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 329 | bus = of_match_bus(p_op->dev.of_node); |
| 330 | bus->count_cells(op->dev.of_node, &na, &ns); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 331 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 332 | preg = of_get_property(op->dev.of_node, bus->addr_prop_name, &num_reg); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 333 | if (!preg || num_reg == 0) |
| 334 | return; |
| 335 | |
| 336 | /* Convert to num-cells. */ |
| 337 | num_reg /= 4; |
| 338 | |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 339 | /* Convert to num-entries. */ |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 340 | num_reg /= na + ns; |
| 341 | |
Simon Arlott | e5dd42e | 2007-05-11 13:52:08 -0700 | [diff] [blame] | 342 | /* Prevent overrunning the op->resources[] array. */ |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 343 | if (num_reg > PROMREG_MAX) { |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 344 | printk(KERN_WARNING "%pOF: Too many regs (%d), " |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 345 | "limiting to %d.\n", |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 346 | op->dev.of_node, num_reg, PROMREG_MAX); |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 347 | num_reg = PROMREG_MAX; |
| 348 | } |
| 349 | |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 350 | op->resource = op->archdata.resource; |
| 351 | op->num_resources = num_reg; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 352 | for (index = 0; index < num_reg; index++) { |
| 353 | struct resource *r = &op->resource[index]; |
| 354 | u32 addr[OF_MAX_ADDR_CELLS]; |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 355 | const u32 *reg = (preg + (index * ((na + ns) * 4))); |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 356 | struct device_node *dp = op->dev.of_node; |
| 357 | struct device_node *pp = p_op->dev.of_node; |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 358 | struct of_bus *pbus, *dbus; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 359 | u64 size, result = OF_BAD_ADDR; |
| 360 | unsigned long flags; |
| 361 | int dna, dns; |
| 362 | int pna, pns; |
| 363 | |
| 364 | size = of_read_addr(reg + na, ns); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 365 | memcpy(addr, reg, na * 4); |
| 366 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 367 | flags = bus->get_flags(addr, 0); |
| 368 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 369 | if (use_1to1_mapping(pp)) { |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 370 | result = of_read_addr(addr, na); |
| 371 | goto build_res; |
| 372 | } |
| 373 | |
| 374 | dna = na; |
| 375 | dns = ns; |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 376 | dbus = bus; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 377 | |
| 378 | while (1) { |
| 379 | dp = pp; |
| 380 | pp = dp->parent; |
| 381 | if (!pp) { |
| 382 | result = of_read_addr(addr, dna); |
| 383 | break; |
| 384 | } |
| 385 | |
| 386 | pbus = of_match_bus(pp); |
| 387 | pbus->count_cells(dp, &pna, &pns); |
| 388 | |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 389 | if (build_one_resource(dp, dbus, pbus, addr, |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 390 | dna, dns, pna)) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 391 | break; |
| 392 | |
David S. Miller | e3c71a3 | 2008-08-28 21:02:58 -0700 | [diff] [blame] | 393 | flags = pbus->get_flags(addr, flags); |
| 394 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 395 | dna = pna; |
| 396 | dns = pns; |
David S. Miller | b85cdd4 | 2007-02-28 23:20:12 -0800 | [diff] [blame] | 397 | dbus = pbus; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | build_res: |
| 401 | memset(r, 0, sizeof(*r)); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 402 | |
| 403 | if (of_resource_verbose) |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 404 | printk("%pOF reg[%d] -> %llx\n", |
| 405 | op->dev.of_node, index, |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 406 | result); |
| 407 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 408 | if (result != OF_BAD_ADDR) { |
David S. Miller | 1815aed | 2006-06-29 19:58:28 -0700 | [diff] [blame] | 409 | if (tlb_type == hypervisor) |
| 410 | result &= 0x0fffffffffffffffUL; |
| 411 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 412 | r->start = result; |
| 413 | r->end = result + size - 1; |
| 414 | r->flags = flags; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 415 | } |
Rob Herring | 86ef771 | 2018-11-16 15:07:01 -0600 | [diff] [blame] | 416 | r->name = op->dev.of_node->full_name; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 420 | static struct device_node * __init |
| 421 | apply_interrupt_map(struct device_node *dp, struct device_node *pp, |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 422 | const u32 *imap, int imlen, const u32 *imask, |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 423 | unsigned int *irq_p) |
| 424 | { |
| 425 | struct device_node *cp; |
| 426 | unsigned int irq = *irq_p; |
| 427 | struct of_bus *bus; |
| 428 | phandle handle; |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 429 | const u32 *reg; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 430 | int na, num_reg, i; |
| 431 | |
| 432 | bus = of_match_bus(pp); |
| 433 | bus->count_cells(dp, &na, NULL); |
| 434 | |
| 435 | reg = of_get_property(dp, "reg", &num_reg); |
| 436 | if (!reg || !num_reg) |
| 437 | return NULL; |
| 438 | |
| 439 | imlen /= ((na + 3) * 4); |
| 440 | handle = 0; |
| 441 | for (i = 0; i < imlen; i++) { |
| 442 | int j; |
| 443 | |
| 444 | for (j = 0; j < na; j++) { |
| 445 | if ((reg[j] & imask[j]) != imap[j]) |
| 446 | goto next; |
| 447 | } |
| 448 | if (imap[na] == irq) { |
| 449 | handle = imap[na + 1]; |
| 450 | irq = imap[na + 2]; |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | next: |
| 455 | imap += (na + 3); |
| 456 | } |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 457 | if (i == imlen) { |
| 458 | /* Psycho and Sabre PCI controllers can have 'interrupt-map' |
| 459 | * properties that do not include the on-board device |
| 460 | * interrupts. Instead, the device's 'interrupts' property |
| 461 | * is already a fully specified INO value. |
| 462 | * |
| 463 | * Handle this by deciding that, if we didn't get a |
| 464 | * match in the parent's 'interrupt-map', and the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 465 | * parent is an IRQ translator, then use the parent as |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 466 | * our IRQ controller. |
| 467 | */ |
| 468 | if (pp->irq_trans) |
| 469 | return pp; |
| 470 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 471 | return NULL; |
David S. Miller | 46ba6d7 | 2006-07-16 22:10:44 -0700 | [diff] [blame] | 472 | } |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 473 | |
| 474 | *irq_p = irq; |
| 475 | cp = of_find_node_by_phandle(handle); |
| 476 | |
| 477 | return cp; |
| 478 | } |
| 479 | |
| 480 | static unsigned int __init pci_irq_swizzle(struct device_node *dp, |
| 481 | struct device_node *pp, |
| 482 | unsigned int irq) |
| 483 | { |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 484 | const struct linux_prom_pci_registers *regs; |
David S. Miller | bb4c18c | 2007-02-26 14:55:06 -0800 | [diff] [blame] | 485 | unsigned int bus, devfn, slot, ret; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 486 | |
| 487 | if (irq < 1 || irq > 4) |
| 488 | return irq; |
| 489 | |
| 490 | regs = of_get_property(dp, "reg", NULL); |
| 491 | if (!regs) |
| 492 | return irq; |
| 493 | |
David S. Miller | bb4c18c | 2007-02-26 14:55:06 -0800 | [diff] [blame] | 494 | bus = (regs->phys_hi >> 16) & 0xff; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 495 | devfn = (regs->phys_hi >> 8) & 0xff; |
| 496 | slot = (devfn >> 3) & 0x1f; |
| 497 | |
David S. Miller | bb4c18c | 2007-02-26 14:55:06 -0800 | [diff] [blame] | 498 | if (pp->irq_trans) { |
| 499 | /* Derived from Table 8-3, U2P User's Manual. This branch |
| 500 | * is handling a PCI controller that lacks a proper set of |
| 501 | * interrupt-map and interrupt-map-mask properties. The |
| 502 | * Ultra-E450 is one example. |
| 503 | * |
| 504 | * The bit layout is BSSLL, where: |
| 505 | * B: 0 on bus A, 1 on bus B |
| 506 | * D: 2-bit slot number, derived from PCI device number as |
| 507 | * (dev - 1) for bus A, or (dev - 2) for bus B |
| 508 | * L: 2-bit line number |
David S. Miller | bb4c18c | 2007-02-26 14:55:06 -0800 | [diff] [blame] | 509 | */ |
| 510 | if (bus & 0x80) { |
| 511 | /* PBM-A */ |
| 512 | bus = 0x00; |
| 513 | slot = (slot - 1) << 2; |
| 514 | } else { |
| 515 | /* PBM-B */ |
| 516 | bus = 0x10; |
| 517 | slot = (slot - 2) << 2; |
| 518 | } |
| 519 | irq -= 1; |
| 520 | |
| 521 | ret = (bus | slot | irq); |
| 522 | } else { |
| 523 | /* Going through a PCI-PCI bridge that lacks a set of |
| 524 | * interrupt-map and interrupt-map-mask properties. |
| 525 | */ |
| 526 | ret = ((irq - 1 + (slot & 3)) & 3) + 1; |
| 527 | } |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 528 | |
| 529 | return ret; |
| 530 | } |
| 531 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 532 | static int of_irq_verbose; |
| 533 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 534 | static unsigned int __init build_one_device_irq(struct platform_device *op, |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 535 | struct device *parent, |
| 536 | unsigned int irq) |
| 537 | { |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 538 | struct device_node *dp = op->dev.of_node; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 539 | struct device_node *pp, *ip; |
| 540 | unsigned int orig_irq = irq; |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 541 | int nid; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 542 | |
| 543 | if (irq == 0xffffffff) |
| 544 | return irq; |
| 545 | |
| 546 | if (dp->irq_trans) { |
| 547 | irq = dp->irq_trans->irq_build(dp, irq, |
| 548 | dp->irq_trans->data); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 549 | |
| 550 | if (of_irq_verbose) |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 551 | printk("%pOF: direct translate %x --> %x\n", |
| 552 | dp, orig_irq, irq); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 553 | |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 554 | goto out; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* Something more complicated. Walk up to the root, applying |
| 558 | * interrupt-map or bus specific translations, until we hit |
| 559 | * an IRQ translator. |
| 560 | * |
| 561 | * If we hit a bus type or situation we cannot handle, we |
| 562 | * stop and assume that the original IRQ number was in a |
| 563 | * format which has special meaning to it's immediate parent. |
| 564 | */ |
| 565 | pp = dp->parent; |
| 566 | ip = NULL; |
| 567 | while (pp) { |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 568 | const void *imap, *imsk; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 569 | int imlen; |
| 570 | |
| 571 | imap = of_get_property(pp, "interrupt-map", &imlen); |
| 572 | imsk = of_get_property(pp, "interrupt-map-mask", NULL); |
| 573 | if (imap && imsk) { |
| 574 | struct device_node *iret; |
| 575 | int this_orig_irq = irq; |
| 576 | |
| 577 | iret = apply_interrupt_map(dp, pp, |
| 578 | imap, imlen, imsk, |
| 579 | &irq); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 580 | |
| 581 | if (of_irq_verbose) |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 582 | printk("%pOF: Apply [%pOF:%x] imap --> [%pOF:%x]\n", |
| 583 | op->dev.of_node, |
| 584 | pp, this_orig_irq, iret, irq); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 585 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 586 | if (!iret) |
| 587 | break; |
| 588 | |
| 589 | if (iret->irq_trans) { |
| 590 | ip = iret; |
| 591 | break; |
| 592 | } |
| 593 | } else { |
Rob Herring | 29c990d | 2018-11-16 15:06:58 -0600 | [diff] [blame] | 594 | if (of_node_name_eq(pp, "pci")) { |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 595 | unsigned int this_orig_irq = irq; |
| 596 | |
| 597 | irq = pci_irq_swizzle(dp, pp, irq); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 598 | if (of_irq_verbose) |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 599 | printk("%pOF: PCI swizzle [%pOF] " |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 600 | "%x --> %x\n", |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 601 | op->dev.of_node, |
| 602 | pp, this_orig_irq, |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 603 | irq); |
| 604 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | if (pp->irq_trans) { |
| 608 | ip = pp; |
| 609 | break; |
| 610 | } |
| 611 | } |
| 612 | dp = pp; |
| 613 | pp = pp->parent; |
| 614 | } |
| 615 | if (!ip) |
| 616 | return orig_irq; |
| 617 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 618 | irq = ip->irq_trans->irq_build(op->dev.of_node, irq, |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 619 | ip->irq_trans->data); |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 620 | if (of_irq_verbose) |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 621 | printk("%pOF: Apply IRQ trans [%pOF] %x --> %x\n", |
| 622 | op->dev.of_node, ip, orig_irq, irq); |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 623 | |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 624 | out: |
| 625 | nid = of_node_to_nid(dp); |
| 626 | if (nid != -1) { |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 627 | cpumask_t numa_mask; |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 628 | |
KOSAKI Motohiro | fb1fece | 2011-05-16 13:38:07 -0700 | [diff] [blame] | 629 | cpumask_copy(&numa_mask, cpumask_of_node(nid)); |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 630 | irq_set_affinity(irq, &numa_mask); |
David S. Miller | c1b1a5f1 | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 631 | } |
| 632 | |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 633 | return irq; |
| 634 | } |
| 635 | |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 636 | static struct platform_device * __init scan_one_device(struct device_node *dp, |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 637 | struct device *parent) |
| 638 | { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 639 | struct platform_device *op = kzalloc(sizeof(*op), GFP_KERNEL); |
Stephen Rothwell | 6a23acf | 2007-04-23 15:53:27 -0700 | [diff] [blame] | 640 | const unsigned int *irq; |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 641 | struct dev_archdata *sd; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 642 | int len, i; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 643 | |
| 644 | if (!op) |
| 645 | return NULL; |
| 646 | |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 647 | sd = &op->dev.archdata; |
David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 648 | sd->op = op; |
| 649 | |
Grant Likely | d706c1b | 2010-04-13 16:12:28 -0700 | [diff] [blame] | 650 | op->dev.of_node = dp; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 651 | |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 652 | irq = of_get_property(dp, "interrupts", &len); |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 653 | if (irq) { |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 654 | op->archdata.num_irqs = len / 4; |
Robert Reif | 92d9091 | 2008-12-26 15:39:11 -0800 | [diff] [blame] | 655 | |
| 656 | /* Prevent overrunning the op->irqs[] array. */ |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 657 | if (op->archdata.num_irqs > PROMINTR_MAX) { |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 658 | printk(KERN_WARNING "%pOF: Too many irqs (%d), " |
Robert Reif | 92d9091 | 2008-12-26 15:39:11 -0800 | [diff] [blame] | 659 | "limiting to %d.\n", |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 660 | dp, op->archdata.num_irqs, PROMINTR_MAX); |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 661 | op->archdata.num_irqs = PROMINTR_MAX; |
Robert Reif | 92d9091 | 2008-12-26 15:39:11 -0800 | [diff] [blame] | 662 | } |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 663 | memcpy(op->archdata.irqs, irq, op->archdata.num_irqs * 4); |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 664 | } else { |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 665 | op->archdata.num_irqs = 0; |
David S. Miller | 2b1e597 | 2006-06-29 15:07:37 -0700 | [diff] [blame] | 666 | } |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 667 | |
| 668 | build_device_resources(op, parent); |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 669 | for (i = 0; i < op->archdata.num_irqs; i++) |
| 670 | op->archdata.irqs[i] = build_one_device_irq(op, parent, op->archdata.irqs[i]); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 671 | |
| 672 | op->dev.parent = parent; |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 673 | op->dev.bus = &platform_bus_type; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 674 | if (!parent) |
Greg Kroah-Hartman | 2222c31 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 675 | dev_set_name(&op->dev, "root"); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 676 | else |
Grant Likely | 6016a36 | 2010-01-28 14:06:53 -0700 | [diff] [blame] | 677 | dev_set_name(&op->dev, "%08x", dp->phandle); |
Christoph Hellwig | 5a7faef | 2018-08-28 11:25:51 +0200 | [diff] [blame] | 678 | op->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 679 | op->dev.dma_mask = &op->dev.coherent_dma_mask; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 680 | |
| 681 | if (of_device_register(op)) { |
Rob Herring | a412c85 | 2018-11-16 15:06:54 -0600 | [diff] [blame] | 682 | printk("%pOF: Could not register of device.\n", dp); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 683 | kfree(op); |
| 684 | op = NULL; |
| 685 | } |
| 686 | |
| 687 | return op; |
| 688 | } |
| 689 | |
| 690 | static void __init scan_tree(struct device_node *dp, struct device *parent) |
| 691 | { |
| 692 | while (dp) { |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 693 | struct platform_device *op = scan_one_device(dp, parent); |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 694 | |
| 695 | if (op) |
| 696 | scan_tree(dp->child, &op->dev); |
| 697 | |
| 698 | dp = dp->sibling; |
| 699 | } |
| 700 | } |
| 701 | |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 702 | static int __init scan_of_devices(void) |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 703 | { |
| 704 | struct device_node *root = of_find_node_by_path("/"); |
Grant Likely | cd4cd73 | 2010-07-22 16:04:30 -0600 | [diff] [blame] | 705 | struct platform_device *parent; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 706 | |
| 707 | parent = scan_one_device(root, NULL); |
| 708 | if (!parent) |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 709 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 710 | |
| 711 | scan_tree(root->child, &parent->dev); |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 712 | return 0; |
David S. Miller | cf44bbc | 2006-06-29 14:34:50 -0700 | [diff] [blame] | 713 | } |
Grant Likely | eca3930 | 2010-06-08 07:48:21 -0600 | [diff] [blame] | 714 | postcore_initcall(scan_of_devices); |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame] | 715 | |
David S. Miller | a83f982 | 2006-07-12 23:19:31 -0700 | [diff] [blame] | 716 | static int __init of_debug(char *str) |
| 717 | { |
| 718 | int val = 0; |
| 719 | |
| 720 | get_option(&str, &val); |
| 721 | if (val & 1) |
| 722 | of_resource_verbose = 1; |
| 723 | if (val & 2) |
| 724 | of_irq_verbose = 1; |
| 725 | return 1; |
| 726 | } |
| 727 | |
| 728 | __setup("of_debug=", of_debug); |