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