diff options
| author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-06-25 06:44:44 -0400 |
|---|---|---|
| committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-06-25 06:44:44 -0400 |
| commit | 76a9f26c9e40e9c0ed5dc8f0cedd74e733f0088d (patch) | |
| tree | 8e2db4ba9263e92d264ef469c7dac28078f63874 /arch/sparc | |
| parent | 9bf2aa129a107a0e9e2a5318d35aca731ae7e666 (diff) | |
| parent | dfd8317d3340f03bc06eba6b58f0ec0861da4a13 (diff) | |
Merge branch 'master' of /home/trondmy/kernel/linux-2.6/
Diffstat (limited to 'arch/sparc')
| -rw-r--r-- | arch/sparc/kernel/Makefile | 2 | ||||
| -rw-r--r-- | arch/sparc/kernel/ebus.c | 185 | ||||
| -rw-r--r-- | arch/sparc/kernel/ioport.c | 131 | ||||
| -rw-r--r-- | arch/sparc/kernel/of_device.c | 268 | ||||
| -rw-r--r-- | arch/sparc/kernel/pcic.c | 3 | ||||
| -rw-r--r-- | arch/sparc/kernel/prom.c | 474 | ||||
| -rw-r--r-- | arch/sparc/mm/init.c | 2 |
7 files changed, 982 insertions, 83 deletions
diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile index 1b83e21841b5..6616ee05c313 100644 --- a/arch/sparc/kernel/Makefile +++ b/arch/sparc/kernel/Makefile | |||
| @@ -12,7 +12,7 @@ obj-y := entry.o wof.o wuf.o etrap.o rtrap.o traps.o $(IRQ_OBJS) \ | |||
| 12 | sys_sparc.o sunos_asm.o systbls.o \ | 12 | sys_sparc.o sunos_asm.o systbls.o \ |
| 13 | time.o windows.o cpu.o devices.o sclow.o \ | 13 | time.o windows.o cpu.o devices.o sclow.o \ |
| 14 | tadpole.o tick14.o ptrace.o sys_solaris.o \ | 14 | tadpole.o tick14.o ptrace.o sys_solaris.o \ |
| 15 | unaligned.o muldiv.o semaphore.o | 15 | unaligned.o muldiv.o semaphore.o prom.o of_device.o |
| 16 | 16 | ||
| 17 | obj-$(CONFIG_PCI) += pcic.o | 17 | obj-$(CONFIG_PCI) += pcic.o |
| 18 | obj-$(CONFIG_SUN4) += sun4setup.o | 18 | obj-$(CONFIG_SUN4) += sun4setup.o |
diff --git a/arch/sparc/kernel/ebus.c b/arch/sparc/kernel/ebus.c index 5c3529ceb5d6..a7a4892956c8 100644 --- a/arch/sparc/kernel/ebus.c +++ b/arch/sparc/kernel/ebus.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <asm/ebus.h> | 20 | #include <asm/ebus.h> |
| 21 | #include <asm/io.h> | 21 | #include <asm/io.h> |
| 22 | #include <asm/oplib.h> | 22 | #include <asm/oplib.h> |
| 23 | #include <asm/prom.h> | ||
| 23 | #include <asm/bpp.h> | 24 | #include <asm/bpp.h> |
| 24 | 25 | ||
| 25 | struct linux_ebus *ebus_chain = NULL; | 26 | struct linux_ebus *ebus_chain = NULL; |
| @@ -83,79 +84,81 @@ int __init ebus_blacklist_irq(char *name) | |||
| 83 | return 0; | 84 | return 0; |
| 84 | } | 85 | } |
| 85 | 86 | ||
| 86 | void __init fill_ebus_child(int node, struct linux_prom_registers *preg, | 87 | void __init fill_ebus_child(struct device_node *dp, |
| 87 | struct linux_ebus_child *dev) | 88 | struct linux_ebus_child *dev) |
| 88 | { | 89 | { |
| 89 | int regs[PROMREG_MAX]; | 90 | int *regs; |
| 90 | int irqs[PROMREG_MAX]; | 91 | int *irqs; |
| 91 | char lbuf[128]; | ||
| 92 | int i, len; | 92 | int i, len; |
| 93 | 93 | ||
| 94 | dev->prom_node = node; | 94 | dev->prom_node = dp; |
| 95 | prom_getstring(node, "name", lbuf, sizeof(lbuf)); | 95 | regs = of_get_property(dp, "reg", &len); |
| 96 | strcpy(dev->prom_name, lbuf); | 96 | if (!regs) |
| 97 | 97 | len = 0; | |
| 98 | len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs)); | ||
| 99 | if (len == -1) len = 0; | ||
| 100 | dev->num_addrs = len / sizeof(regs[0]); | 98 | dev->num_addrs = len / sizeof(regs[0]); |
| 101 | 99 | ||
| 102 | for (i = 0; i < dev->num_addrs; i++) { | 100 | for (i = 0; i < dev->num_addrs; i++) { |
| 103 | if (regs[i] >= dev->parent->num_addrs) { | 101 | if (regs[i] >= dev->parent->num_addrs) { |
| 104 | prom_printf("UGH: property for %s was %d, need < %d\n", | 102 | prom_printf("UGH: property for %s was %d, need < %d\n", |
| 105 | dev->prom_name, len, dev->parent->num_addrs); | 103 | dev->prom_node->name, len, |
| 104 | dev->parent->num_addrs); | ||
| 106 | panic(__FUNCTION__); | 105 | panic(__FUNCTION__); |
| 107 | } | 106 | } |
| 108 | dev->resource[i].start = dev->parent->resource[regs[i]].start; /* XXX resource */ | 107 | |
| 108 | /* XXX resource */ | ||
| 109 | dev->resource[i].start = | ||
| 110 | dev->parent->resource[regs[i]].start; | ||
| 109 | } | 111 | } |
| 110 | 112 | ||
| 111 | for (i = 0; i < PROMINTR_MAX; i++) | 113 | for (i = 0; i < PROMINTR_MAX; i++) |
| 112 | dev->irqs[i] = PCI_IRQ_NONE; | 114 | dev->irqs[i] = PCI_IRQ_NONE; |
| 113 | 115 | ||
| 114 | if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_name)) != 0) { | 116 | if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_node->name)) != 0) { |
| 115 | dev->num_irqs = 1; | 117 | dev->num_irqs = 1; |
| 116 | } else if ((len = prom_getproperty(node, "interrupts", | ||
| 117 | (char *)&irqs, sizeof(irqs))) == -1 || len == 0) { | ||
| 118 | dev->num_irqs = 0; | ||
| 119 | dev->irqs[0] = 0; | ||
| 120 | if (dev->parent->num_irqs != 0) { | ||
| 121 | dev->num_irqs = 1; | ||
| 122 | dev->irqs[0] = dev->parent->irqs[0]; | ||
| 123 | /* P3 */ /* printk("EBUS: dev %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */ | ||
| 124 | } | ||
| 125 | } else { | 118 | } else { |
| 126 | dev->num_irqs = len / sizeof(irqs[0]); | 119 | irqs = of_get_property(dp, "interrupts", &len); |
| 127 | if (irqs[0] == 0 || irqs[0] >= 8) { | 120 | if (!irqs) { |
| 128 | /* | ||
| 129 | * XXX Zero is a valid pin number... | ||
| 130 | * This works as long as Ebus is not wired to INTA#. | ||
| 131 | */ | ||
| 132 | printk("EBUS: %s got bad irq %d from PROM\n", | ||
| 133 | dev->prom_name, irqs[0]); | ||
| 134 | dev->num_irqs = 0; | 121 | dev->num_irqs = 0; |
| 135 | dev->irqs[0] = 0; | 122 | dev->irqs[0] = 0; |
| 123 | if (dev->parent->num_irqs != 0) { | ||
| 124 | dev->num_irqs = 1; | ||
| 125 | dev->irqs[0] = dev->parent->irqs[0]; | ||
| 126 | } | ||
| 136 | } else { | 127 | } else { |
| 137 | dev->irqs[0] = pcic_pin_to_irq(irqs[0], dev->prom_name); | 128 | dev->num_irqs = len / sizeof(irqs[0]); |
| 129 | if (irqs[0] == 0 || irqs[0] >= 8) { | ||
| 130 | /* | ||
| 131 | * XXX Zero is a valid pin number... | ||
| 132 | * This works as long as Ebus is not wired | ||
| 133 | * to INTA#. | ||
| 134 | */ | ||
| 135 | printk("EBUS: %s got bad irq %d from PROM\n", | ||
| 136 | dev->prom_node->name, irqs[0]); | ||
| 137 | dev->num_irqs = 0; | ||
| 138 | dev->irqs[0] = 0; | ||
| 139 | } else { | ||
| 140 | dev->irqs[0] = | ||
| 141 | pcic_pin_to_irq(irqs[0], | ||
| 142 | dev->prom_node->name); | ||
| 143 | } | ||
| 138 | } | 144 | } |
| 139 | } | 145 | } |
| 140 | } | 146 | } |
| 141 | 147 | ||
| 142 | void __init fill_ebus_device(int node, struct linux_ebus_device *dev) | 148 | void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_device *dev) |
| 143 | { | 149 | { |
| 144 | struct linux_prom_registers regs[PROMREG_MAX]; | 150 | struct linux_prom_registers *regs; |
| 145 | struct linux_ebus_child *child; | 151 | struct linux_ebus_child *child; |
| 146 | int irqs[PROMINTR_MAX]; | 152 | int *irqs; |
| 147 | char lbuf[128]; | ||
| 148 | int i, n, len; | 153 | int i, n, len; |
| 149 | unsigned long baseaddr; | 154 | unsigned long baseaddr; |
| 150 | 155 | ||
| 151 | dev->prom_node = node; | 156 | dev->prom_node = dp; |
| 152 | prom_getstring(node, "name", lbuf, sizeof(lbuf)); | ||
| 153 | strcpy(dev->prom_name, lbuf); | ||
| 154 | 157 | ||
| 155 | len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs)); | 158 | regs = of_get_property(dp, "reg", &len); |
| 156 | if (len % sizeof(struct linux_prom_registers)) { | 159 | if (len % sizeof(struct linux_prom_registers)) { |
| 157 | prom_printf("UGH: proplen for %s was %d, need multiple of %d\n", | 160 | prom_printf("UGH: proplen for %s was %d, need multiple of %d\n", |
| 158 | dev->prom_name, len, | 161 | dev->prom_node->name, len, |
| 159 | (int)sizeof(struct linux_prom_registers)); | 162 | (int)sizeof(struct linux_prom_registers)); |
| 160 | panic(__FUNCTION__); | 163 | panic(__FUNCTION__); |
| 161 | } | 164 | } |
| @@ -197,7 +200,7 @@ void __init fill_ebus_device(int node, struct linux_ebus_device *dev) | |||
| 197 | if ((baseaddr = (unsigned long) ioremap(baseaddr, | 200 | if ((baseaddr = (unsigned long) ioremap(baseaddr, |
| 198 | regs[i].reg_size)) == 0) { | 201 | regs[i].reg_size)) == 0) { |
| 199 | panic("ebus: unable to remap dev %s", | 202 | panic("ebus: unable to remap dev %s", |
| 200 | dev->prom_name); | 203 | dev->prom_node->name); |
| 201 | } | 204 | } |
| 202 | } | 205 | } |
| 203 | dev->resource[i].start = baseaddr; /* XXX Unaligned */ | 206 | dev->resource[i].start = baseaddr; /* XXX Unaligned */ |
| @@ -206,29 +209,43 @@ void __init fill_ebus_device(int node, struct linux_ebus_device *dev) | |||
| 206 | for (i = 0; i < PROMINTR_MAX; i++) | 209 | for (i = 0; i < PROMINTR_MAX; i++) |
| 207 | dev->irqs[i] = PCI_IRQ_NONE; | 210 | dev->irqs[i] = PCI_IRQ_NONE; |
| 208 | 211 | ||
| 209 | if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_name)) != 0) { | 212 | if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_node->name)) != 0) { |
| 210 | dev->num_irqs = 1; | 213 | dev->num_irqs = 1; |
| 211 | } else if ((len = prom_getproperty(node, "interrupts", | ||
| 212 | (char *)&irqs, sizeof(irqs))) == -1 || len == 0) { | ||
| 213 | dev->num_irqs = 0; | ||
| 214 | if ((dev->irqs[0] = dev->bus->self->irq) != 0) { | ||
| 215 | dev->num_irqs = 1; | ||
| 216 | /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */ | ||
| 217 | } | ||
| 218 | } else { | 214 | } else { |
| 219 | dev->num_irqs = 1; /* dev->num_irqs = len / sizeof(irqs[0]); */ | 215 | irqs = of_get_property(dp, "interrupts", &len); |
| 220 | if (irqs[0] == 0 || irqs[0] >= 8) { | 216 | if (!irqs) { |
| 221 | /* See above for the parent. XXX */ | ||
| 222 | printk("EBUS: %s got bad irq %d from PROM\n", | ||
| 223 | dev->prom_name, irqs[0]); | ||
| 224 | dev->num_irqs = 0; | 217 | dev->num_irqs = 0; |
| 225 | dev->irqs[0] = 0; | 218 | if ((dev->irqs[0] = dev->bus->self->irq) != 0) { |
| 219 | dev->num_irqs = 1; | ||
| 220 | /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */ | ||
| 221 | } | ||
| 226 | } else { | 222 | } else { |
| 227 | dev->irqs[0] = pcic_pin_to_irq(irqs[0], dev->prom_name); | 223 | dev->num_irqs = 1; /* dev->num_irqs = len / sizeof(irqs[0]); */ |
| 224 | if (irqs[0] == 0 || irqs[0] >= 8) { | ||
| 225 | /* See above for the parent. XXX */ | ||
| 226 | printk("EBUS: %s got bad irq %d from PROM\n", | ||
| 227 | dev->prom_node->name, irqs[0]); | ||
| 228 | dev->num_irqs = 0; | ||
| 229 | dev->irqs[0] = 0; | ||
| 230 | } else { | ||
| 231 | dev->irqs[0] = | ||
| 232 | pcic_pin_to_irq(irqs[0], | ||
| 233 | dev->prom_node->name); | ||
| 234 | } | ||
| 228 | } | 235 | } |
| 229 | } | 236 | } |
| 230 | 237 | ||
| 231 | if ((node = prom_getchild(node))) { | 238 | dev->ofdev.node = dp; |
| 239 | dev->ofdev.dev.parent = &dev->bus->ofdev.dev; | ||
| 240 | dev->ofdev.dev.bus = &ebus_bus_type; | ||
| 241 | strcpy(dev->ofdev.dev.bus_id, dp->path_component_name); | ||
| 242 | |||
| 243 | /* Register with core */ | ||
| 244 | if (of_device_register(&dev->ofdev) != 0) | ||
| 245 | printk(KERN_DEBUG "ebus: device registration error for %s!\n", | ||
| 246 | dev->ofdev.dev.bus_id); | ||
| 247 | |||
| 248 | if ((dp = dp->child) != NULL) { | ||
| 232 | dev->children = (struct linux_ebus_child *) | 249 | dev->children = (struct linux_ebus_child *) |
| 233 | ebus_alloc(sizeof(struct linux_ebus_child)); | 250 | ebus_alloc(sizeof(struct linux_ebus_child)); |
| 234 | 251 | ||
| @@ -236,9 +253,9 @@ void __init fill_ebus_device(int node, struct linux_ebus_device *dev) | |||
| 236 | child->next = NULL; | 253 | child->next = NULL; |
| 237 | child->parent = dev; | 254 | child->parent = dev; |
| 238 | child->bus = dev->bus; | 255 | child->bus = dev->bus; |
| 239 | fill_ebus_child(node, ®s[0], child); | 256 | fill_ebus_child(dp, child); |
| 240 | 257 | ||
| 241 | while ((node = prom_getsibling(node)) != 0) { | 258 | while ((dp = dp->sibling) != NULL) { |
| 242 | child->next = (struct linux_ebus_child *) | 259 | child->next = (struct linux_ebus_child *) |
| 243 | ebus_alloc(sizeof(struct linux_ebus_child)); | 260 | ebus_alloc(sizeof(struct linux_ebus_child)); |
| 244 | 261 | ||
| @@ -246,51 +263,49 @@ void __init fill_ebus_device(int node, struct linux_ebus_device *dev) | |||
| 246 | child->next = NULL; | 263 | child->next = NULL; |
| 247 | child->parent = dev; | 264 | child->parent = dev; |
| 248 | child->bus = dev->bus; | 265 | child->bus = dev->bus; |
| 249 | fill_ebus_child(node, ®s[0], child); | 266 | fill_ebus_child(dp, child); |
| 250 | } | 267 | } |
| 251 | } | 268 | } |
| 252 | } | 269 | } |
| 253 | 270 | ||
| 254 | void __init ebus_init(void) | 271 | void __init ebus_init(void) |
| 255 | { | 272 | { |
| 256 | struct linux_prom_pci_registers regs[PROMREG_MAX]; | 273 | struct linux_prom_pci_registers *regs; |
| 257 | struct linux_pbm_info *pbm; | 274 | struct linux_pbm_info *pbm; |
| 258 | struct linux_ebus_device *dev; | 275 | struct linux_ebus_device *dev; |
| 259 | struct linux_ebus *ebus; | 276 | struct linux_ebus *ebus; |
| 260 | struct ebus_system_entry *sp; | 277 | struct ebus_system_entry *sp; |
| 261 | struct pci_dev *pdev; | 278 | struct pci_dev *pdev; |
| 262 | struct pcidev_cookie *cookie; | 279 | struct pcidev_cookie *cookie; |
| 263 | char lbuf[128]; | 280 | struct device_node *dp; |
| 264 | unsigned long addr, *base; | 281 | unsigned long addr, *base; |
| 265 | unsigned short pci_command; | 282 | unsigned short pci_command; |
| 266 | int nd, len, ebusnd; | 283 | int len, reg, nreg; |
| 267 | int reg, nreg; | ||
| 268 | int num_ebus = 0; | 284 | int num_ebus = 0; |
| 269 | 285 | ||
| 270 | prom_getstring(prom_root_node, "name", lbuf, sizeof(lbuf)); | 286 | dp = of_find_node_by_path("/"); |
| 271 | for (sp = ebus_blacklist; sp->esname != NULL; sp++) { | 287 | for (sp = ebus_blacklist; sp->esname != NULL; sp++) { |
| 272 | if (strcmp(lbuf, sp->esname) == 0) { | 288 | if (strcmp(dp->name, sp->esname) == 0) { |
| 273 | ebus_blackp = sp->ipt; | 289 | ebus_blackp = sp->ipt; |
| 274 | break; | 290 | break; |
| 275 | } | 291 | } |
| 276 | } | 292 | } |
| 277 | 293 | ||
| 278 | pdev = pci_get_device(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_EBUS, NULL); | 294 | pdev = pci_get_device(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_EBUS, NULL); |
| 279 | if (!pdev) { | 295 | if (!pdev) |
| 280 | return; | 296 | return; |
| 281 | } | 297 | |
| 282 | cookie = pdev->sysdata; | 298 | cookie = pdev->sysdata; |
| 283 | ebusnd = cookie->prom_node; | 299 | dp = cookie->prom_node; |
| 284 | 300 | ||
| 285 | ebus_chain = ebus = (struct linux_ebus *) | 301 | ebus_chain = ebus = (struct linux_ebus *) |
| 286 | ebus_alloc(sizeof(struct linux_ebus)); | 302 | ebus_alloc(sizeof(struct linux_ebus)); |
| 287 | ebus->next = NULL; | 303 | ebus->next = NULL; |
| 288 | 304 | ||
| 289 | while (ebusnd) { | 305 | while (dp) { |
| 306 | struct device_node *nd; | ||
| 290 | 307 | ||
| 291 | prom_getstring(ebusnd, "name", lbuf, sizeof(lbuf)); | 308 | ebus->prom_node = dp; |
| 292 | ebus->prom_node = ebusnd; | ||
| 293 | strcpy(ebus->prom_name, lbuf); | ||
| 294 | ebus->self = pdev; | 309 | ebus->self = pdev; |
| 295 | ebus->parent = pbm = cookie->pbm; | 310 | ebus->parent = pbm = cookie->pbm; |
| 296 | 311 | ||
| @@ -299,9 +314,8 @@ void __init ebus_init(void) | |||
| 299 | pci_command |= PCI_COMMAND_MASTER; | 314 | pci_command |= PCI_COMMAND_MASTER; |
| 300 | pci_write_config_word(pdev, PCI_COMMAND, pci_command); | 315 | pci_write_config_word(pdev, PCI_COMMAND, pci_command); |
| 301 | 316 | ||
| 302 | len = prom_getproperty(ebusnd, "reg", (void *)regs, | 317 | regs = of_get_property(dp, "reg", &len); |
| 303 | sizeof(regs)); | 318 | if (!regs) { |
| 304 | if (len == 0 || len == -1) { | ||
| 305 | prom_printf("%s: can't find reg property\n", | 319 | prom_printf("%s: can't find reg property\n", |
| 306 | __FUNCTION__); | 320 | __FUNCTION__); |
| 307 | prom_halt(); | 321 | prom_halt(); |
| @@ -317,7 +331,18 @@ void __init ebus_init(void) | |||
| 317 | *base++ = addr; | 331 | *base++ = addr; |
| 318 | } | 332 | } |
| 319 | 333 | ||
| 320 | nd = prom_getchild(ebusnd); | 334 | ebus->ofdev.node = dp; |
| 335 | ebus->ofdev.dev.parent = &pdev->dev; | ||
| 336 | ebus->ofdev.dev.bus = &ebus_bus_type; | ||
| 337 | strcpy(ebus->ofdev.dev.bus_id, dp->path_component_name); | ||
| 338 | |||
| 339 | /* Register with core */ | ||
| 340 | if (of_device_register(&ebus->ofdev) != 0) | ||
| 341 | printk(KERN_DEBUG "ebus: device registration error for %s!\n", | ||
| 342 | ebus->ofdev.dev.bus_id); | ||
| 343 | |||
| 344 | |||
| 345 | nd = dp->child; | ||
| 321 | if (!nd) | 346 | if (!nd) |
| 322 | goto next_ebus; | 347 | goto next_ebus; |
| 323 | 348 | ||
| @@ -330,7 +355,7 @@ void __init ebus_init(void) | |||
| 330 | dev->bus = ebus; | 355 | dev->bus = ebus; |
| 331 | fill_ebus_device(nd, dev); | 356 | fill_ebus_device(nd, dev); |
| 332 | 357 | ||
| 333 | while ((nd = prom_getsibling(nd)) != 0) { | 358 | while ((nd = nd->sibling) != NULL) { |
| 334 | dev->next = (struct linux_ebus_device *) | 359 | dev->next = (struct linux_ebus_device *) |
| 335 | ebus_alloc(sizeof(struct linux_ebus_device)); | 360 | ebus_alloc(sizeof(struct linux_ebus_device)); |
| 336 | 361 | ||
| @@ -348,7 +373,7 @@ void __init ebus_init(void) | |||
| 348 | break; | 373 | break; |
| 349 | 374 | ||
| 350 | cookie = pdev->sysdata; | 375 | cookie = pdev->sysdata; |
| 351 | ebusnd = cookie->prom_node; | 376 | dp = cookie->prom_node; |
| 352 | 377 | ||
| 353 | ebus->next = (struct linux_ebus *) | 378 | ebus->next = (struct linux_ebus *) |
| 354 | ebus_alloc(sizeof(struct linux_ebus)); | 379 | ebus_alloc(sizeof(struct linux_ebus)); |
diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c index f9ff29734848..ae4c667c906f 100644 --- a/arch/sparc/kernel/ioport.c +++ b/arch/sparc/kernel/ioport.c | |||
| @@ -39,6 +39,8 @@ | |||
| 39 | #include <asm/io.h> | 39 | #include <asm/io.h> |
| 40 | #include <asm/vaddrs.h> | 40 | #include <asm/vaddrs.h> |
| 41 | #include <asm/oplib.h> | 41 | #include <asm/oplib.h> |
| 42 | #include <asm/prom.h> | ||
| 43 | #include <asm/sbus.h> | ||
| 42 | #include <asm/page.h> | 44 | #include <asm/page.h> |
| 43 | #include <asm/pgalloc.h> | 45 | #include <asm/pgalloc.h> |
| 44 | #include <asm/dma.h> | 46 | #include <asm/dma.h> |
| @@ -224,10 +226,54 @@ static void _sparc_free_io(struct resource *res) | |||
| 224 | 226 | ||
| 225 | #ifdef CONFIG_SBUS | 227 | #ifdef CONFIG_SBUS |
| 226 | 228 | ||
| 227 | void sbus_set_sbus64(struct sbus_dev *sdev, int x) { | 229 | void sbus_set_sbus64(struct sbus_dev *sdev, int x) |
| 230 | { | ||
| 228 | printk("sbus_set_sbus64: unsupported\n"); | 231 | printk("sbus_set_sbus64: unsupported\n"); |
| 229 | } | 232 | } |
| 230 | 233 | ||
| 234 | extern unsigned int sun4d_build_irq(struct sbus_dev *sdev, int irq); | ||
| 235 | void __init sbus_fill_device_irq(struct sbus_dev *sdev) | ||
| 236 | { | ||
| 237 | struct linux_prom_irqs irqs[PROMINTR_MAX]; | ||
| 238 | int len; | ||
| 239 | |||
| 240 | len = prom_getproperty(sdev->prom_node, "intr", | ||
| 241 | (char *)irqs, sizeof(irqs)); | ||
| 242 | if (len != -1) { | ||
| 243 | sdev->num_irqs = len / 8; | ||
| 244 | if (sdev->num_irqs == 0) { | ||
| 245 | sdev->irqs[0] = 0; | ||
| 246 | } else if (sparc_cpu_model == sun4d) { | ||
| 247 | for (len = 0; len < sdev->num_irqs; len++) | ||
| 248 | sdev->irqs[len] = | ||
| 249 | sun4d_build_irq(sdev, irqs[len].pri); | ||
| 250 | } else { | ||
| 251 | for (len = 0; len < sdev->num_irqs; len++) | ||
| 252 | sdev->irqs[len] = irqs[len].pri; | ||
| 253 | } | ||
| 254 | } else { | ||
| 255 | int interrupts[PROMINTR_MAX]; | ||
| 256 | |||
| 257 | /* No "intr" node found-- check for "interrupts" node. | ||
| 258 | * This node contains SBus interrupt levels, not IPLs | ||
| 259 | * as in "intr", and no vector values. We convert | ||
| 260 | * SBus interrupt levels to PILs (platform specific). | ||
| 261 | */ | ||
| 262 | len = prom_getproperty(sdev->prom_node, "interrupts", | ||
| 263 | (char *)interrupts, sizeof(interrupts)); | ||
| 264 | if (len == -1) { | ||
| 265 | sdev->irqs[0] = 0; | ||
| 266 | sdev->num_irqs = 0; | ||
| 267 | } else { | ||
| 268 | sdev->num_irqs = len / sizeof(int); | ||
| 269 | for (len = 0; len < sdev->num_irqs; len++) { | ||
| 270 | sdev->irqs[len] = | ||
| 271 | sbint_to_irq(sdev, interrupts[len]); | ||
| 272 | } | ||
| 273 | } | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 231 | /* | 277 | /* |
| 232 | * Allocate a chunk of memory suitable for DMA. | 278 | * Allocate a chunk of memory suitable for DMA. |
| 233 | * Typically devices use them for control blocks. | 279 | * Typically devices use them for control blocks. |
| @@ -414,6 +460,89 @@ void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev, struct scatterlist *sg, | |||
| 414 | { | 460 | { |
| 415 | printk("sbus_dma_sync_sg_for_device: not implemented yet\n"); | 461 | printk("sbus_dma_sync_sg_for_device: not implemented yet\n"); |
| 416 | } | 462 | } |
| 463 | |||
| 464 | /* Support code for sbus_init(). */ | ||
| 465 | /* | ||
| 466 | * XXX This functions appears to be a distorted version of | ||
| 467 | * prom_sbus_ranges_init(), with all sun4d stuff cut away. | ||
| 468 | * Ask DaveM what is going on here, how is sun4d supposed to work... XXX | ||
| 469 | */ | ||
| 470 | /* added back sun4d patch from Thomas Bogendoerfer - should be OK (crn) */ | ||
| 471 | void __init sbus_arch_bus_ranges_init(struct device_node *pn, struct sbus_bus *sbus) | ||
| 472 | { | ||
| 473 | int parent_node = pn->node; | ||
| 474 | |||
| 475 | if (sparc_cpu_model == sun4d) { | ||
| 476 | struct linux_prom_ranges iounit_ranges[PROMREG_MAX]; | ||
| 477 | int num_iounit_ranges, len; | ||
| 478 | |||
| 479 | len = prom_getproperty(parent_node, "ranges", | ||
| 480 | (char *) iounit_ranges, | ||
| 481 | sizeof (iounit_ranges)); | ||
| 482 | if (len != -1) { | ||
| 483 | num_iounit_ranges = | ||
| 484 | (len / sizeof(struct linux_prom_ranges)); | ||
| 485 | prom_adjust_ranges(sbus->sbus_ranges, | ||
| 486 | sbus->num_sbus_ranges, | ||
| 487 | iounit_ranges, num_iounit_ranges); | ||
| 488 | } | ||
| 489 | } | ||
| 490 | } | ||
| 491 | |||
| 492 | void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp) | ||
| 493 | { | ||
| 494 | struct device_node *parent = dp->parent; | ||
| 495 | |||
| 496 | if (sparc_cpu_model != sun4d && | ||
| 497 | parent != NULL && | ||
| 498 | !strcmp(parent->name, "iommu")) { | ||
| 499 | extern void iommu_init(int iommu_node, struct sbus_bus *sbus); | ||
| 500 | |||
| 501 | iommu_init(parent->node, sbus); | ||
| 502 | } | ||
| 503 | |||
| 504 | if (sparc_cpu_model == sun4d) { | ||
| 505 | extern void iounit_init(int sbi_node, int iounit_node, | ||
| 506 | struct sbus_bus *sbus); | ||
| 507 | |||
| 508 | iounit_init(dp->node, parent->node, sbus); | ||
| 509 | } | ||
| 510 | } | ||
| 511 | |||
| 512 | void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp) | ||
| 513 | { | ||
| 514 | if (sparc_cpu_model == sun4d) { | ||
| 515 | struct device_node *parent = dp->parent; | ||
| 516 | |||
| 517 | sbus->devid = of_getintprop_default(parent, "device-id", 0); | ||
| 518 | sbus->board = of_getintprop_default(parent, "board#", 0); | ||
| 519 | } | ||
| 520 | } | ||
| 521 | |||
| 522 | int __init sbus_arch_preinit(void) | ||
| 523 | { | ||
| 524 | extern void register_proc_sparc_ioport(void); | ||
| 525 | |||
| 526 | register_proc_sparc_ioport(); | ||
| 527 | |||
| 528 | #ifdef CONFIG_SUN4 | ||
| 529 | { | ||
| 530 | extern void sun4_dvma_init(void); | ||
| 531 | sun4_dvma_init(); | ||
| 532 | } | ||
| 533 | return 1; | ||
| 534 | #else | ||
| 535 | return 0; | ||
| 536 | #endif | ||
| 537 | } | ||
| 538 | |||
| 539 | void __init sbus_arch_postinit(void) | ||
| 540 | { | ||
| 541 | if (sparc_cpu_model == sun4d) { | ||
| 542 | extern void sun4d_init_sbi_irq(void); | ||
| 543 | sun4d_init_sbi_irq(); | ||
| 544 | } | ||
| 545 | } | ||
| 417 | #endif /* CONFIG_SBUS */ | 546 | #endif /* CONFIG_SBUS */ |
| 418 | 547 | ||
| 419 | #ifdef CONFIG_PCI | 548 | #ifdef CONFIG_PCI |
diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c new file mode 100644 index 000000000000..001b8673b4bd --- /dev/null +++ b/arch/sparc/kernel/of_device.c | |||
| @@ -0,0 +1,268 @@ | |||
| 1 | #include <linux/config.h> | ||
| 2 | #include <linux/string.h> | ||
| 3 | #include <linux/kernel.h> | ||
| 4 | #include <linux/init.h> | ||
| 5 | #include <linux/module.h> | ||
| 6 | #include <linux/mod_devicetable.h> | ||
| 7 | #include <linux/slab.h> | ||
| 8 | |||
| 9 | #include <asm/errno.h> | ||
| 10 | #include <asm/of_device.h> | ||
| 11 | |||
| 12 | /** | ||
| 13 | * of_match_device - Tell if an of_device structure has a matching | ||
| 14 | * of_match structure | ||
| 15 | * @ids: array of of device match structures to search in | ||
| 16 | * @dev: the of device structure to match against | ||
| 17 | * | ||
| 18 | * Used by a driver to check whether an of_device present in the | ||
| 19 | * system is in its list of supported devices. | ||
| 20 | */ | ||
| 21 | const struct of_device_id *of_match_device(const struct of_device_id *matches, | ||
| 22 | const struct of_device *dev) | ||
| 23 | { | ||
| 24 | if (!dev->node) | ||
| 25 | return NULL; | ||
| 26 | while (matches->name[0] || matches->type[0] || matches->compatible[0]) { | ||
| 27 | int match = 1; | ||
| 28 | if (matches->name[0]) | ||
| 29 | match &= dev->node->name | ||
| 30 | && !strcmp(matches->name, dev->node->name); | ||
| 31 | if (matches->type[0]) | ||
| 32 | match &= dev->node->type | ||
| 33 | && !strcmp(matches->type, dev->node->type); | ||
| 34 | if (matches->compatible[0]) | ||
| 35 | match &= of_device_is_compatible(dev->node, | ||
| 36 | matches->compatible); | ||
| 37 | if (match) | ||
| 38 | return matches; | ||
| 39 | matches++; | ||
| 40 | } | ||
| 41 | return NULL; | ||
| 42 | } | ||
| 43 | |||
| 44 | static int of_platform_bus_match(struct device *dev, struct device_driver *drv) | ||
| 45 | { | ||
| 46 | struct of_device * of_dev = to_of_device(dev); | ||
| 47 | struct of_platform_driver * of_drv = to_of_platform_driver(drv); | ||
| 48 | const struct of_device_id * matches = of_drv->match_table; | ||
| 49 | |||
| 50 | if (!matches) | ||
| 51 | return 0; | ||
| 52 | |||
| 53 | return of_match_device(matches, of_dev) != NULL; | ||
| 54 | } | ||
| 55 | |||
| 56 | struct of_device *of_dev_get(struct of_device *dev) | ||
| 57 | { | ||
| 58 | struct device *tmp; | ||
| 59 | |||
| 60 | if (!dev) | ||
| 61 | return NULL; | ||
| 62 | tmp = get_device(&dev->dev); | ||
| 63 | if (tmp) | ||
| 64 | return to_of_device(tmp); | ||
| 65 | else | ||
| 66 | return NULL; | ||
| 67 | } | ||
| 68 | |||
| 69 | void of_dev_put(struct of_device *dev) | ||
| 70 | { | ||
| 71 | if (dev) | ||
| 72 | put_device(&dev->dev); | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | static int of_device_probe(struct device *dev) | ||
| 77 | { | ||
| 78 | int error = -ENODEV; | ||
| 79 | struct of_platform_driver *drv; | ||
| 80 | struct of_device *of_dev; | ||
| 81 | const struct of_device_id *match; | ||
| 82 | |||
| 83 | drv = to_of_platform_driver(dev->driver); | ||
| 84 | of_dev = to_of_device(dev); | ||
| 85 | |||
| 86 | if (!drv->probe) | ||
| 87 | return error; | ||
| 88 | |||
| 89 | of_dev_get(of_dev); | ||
| 90 | |||
| 91 | match = of_match_device(drv->match_table, of_dev); | ||
| 92 | if (match) | ||
| 93 | error = drv->probe(of_dev, match); | ||
| 94 | if (error) | ||
| 95 | of_dev_put(of_dev); | ||
| 96 | |||
| 97 | return error; | ||
| 98 | } | ||
| 99 | |||
| 100 | static int of_device_remove(struct device *dev) | ||
| 101 | { | ||
| 102 | struct of_device * of_dev = to_of_device(dev); | ||
| 103 | struct of_platform_driver * drv = to_of_platform_driver(dev->driver); | ||
| 104 | |||
| 105 | if (dev->driver && drv->remove) | ||
| 106 | drv->remove(of_dev); | ||
| 107 | return 0; | ||
| 108 | } | ||
| 109 | |||
| 110 | static int of_device_suspend(struct device *dev, pm_message_t state) | ||
| 111 | { | ||
| 112 | struct of_device * of_dev = to_of_device(dev); | ||
| 113 | struct of_platform_driver * drv = to_of_platform_driver(dev->driver); | ||
| 114 | int error = 0; | ||
| 115 | |||
| 116 | if (dev->driver && drv->suspend) | ||
| 117 | error = drv->suspend(of_dev, state); | ||
| 118 | return error; | ||
| 119 | } | ||
| 120 | |||
| 121 | static int of_device_resume(struct device * dev) | ||
| 122 | { | ||
| 123 | struct of_device * of_dev = to_of_device(dev); | ||
| 124 | struct of_platform_driver * drv = to_of_platform_driver(dev->driver); | ||
| 125 | int error = 0; | ||
| 126 | |||
| 127 | if (dev->driver && drv->resume) | ||
| 128 | error = drv->resume(of_dev); | ||
| 129 | return error; | ||
| 130 | } | ||
| 131 | |||
| 132 | #ifdef CONFIG_PCI | ||
| 133 | struct bus_type ebus_bus_type = { | ||
| 134 | .name = "ebus", | ||
| 135 | .match = of_platform_bus_match, | ||
| 136 | .probe = of_device_probe, | ||
| 137 | .remove = of_device_remove, | ||
| 138 | .suspend = of_device_suspend, | ||
| 139 | .resume = of_device_resume, | ||
| 140 | }; | ||
| 141 | #endif | ||
| 142 | |||
| 143 | #ifdef CONFIG_SBUS | ||
| 144 | struct bus_type sbus_bus_type = { | ||
| 145 | .name = "sbus", | ||
| 146 | .match = of_platform_bus_match, | ||
| 147 | .probe = of_device_probe, | ||
| 148 | .remove = of_device_remove, | ||
| 149 | .suspend = of_device_suspend, | ||
| 150 | .resume = of_device_resume, | ||
| 151 | }; | ||
| 152 | #endif | ||
| 153 | |||
| 154 | static int __init of_bus_driver_init(void) | ||
| 155 | { | ||
| 156 | int err = 0; | ||
| 157 | |||
| 158 | #ifdef CONFIG_PCI | ||
| 159 | if (!err) | ||
| 160 | err = bus_register(&ebus_bus_type); | ||
| 161 | #endif | ||
| 162 | #ifdef CONFIG_SBUS | ||
| 163 | if (!err) | ||
| 164 | err = bus_register(&sbus_bus_type); | ||
| 165 | #endif | ||
| 166 | return 0; | ||
| 167 | } | ||
| 168 | |||
| 169 | postcore_initcall(of_bus_driver_init); | ||
| 170 | |||
| 171 | int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus) | ||
| 172 | { | ||
| 173 | /* initialize common driver fields */ | ||
| 174 | drv->driver.name = drv->name; | ||
| 175 | drv->driver.bus = bus; | ||
| 176 | |||
| 177 | /* register with core */ | ||
| 178 | return driver_register(&drv->driver); | ||
| 179 | } | ||
| 180 | |||
| 181 | void of_unregister_driver(struct of_platform_driver *drv) | ||
| 182 | { | ||
| 183 | driver_unregister(&drv->driver); | ||
| 184 | } | ||
| 185 | |||
| 186 | |||
| 187 | static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 188 | { | ||
| 189 | struct of_device *ofdev; | ||
| 190 | |||
| 191 | ofdev = to_of_device(dev); | ||
| 192 | return sprintf(buf, "%s", ofdev->node->full_name); | ||
| 193 | } | ||
| 194 | |||
| 195 | static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); | ||
| 196 | |||
| 197 | /** | ||
| 198 | * of_release_dev - free an of device structure when all users of it are finished. | ||
| 199 | * @dev: device that's been disconnected | ||
| 200 | * | ||
| 201 | * Will be called only by the device core when all users of this of device are | ||
| 202 | * done. | ||
| 203 | */ | ||
| 204 | void of_release_dev(struct device *dev) | ||
| 205 | { | ||
| 206 | struct of_device *ofdev; | ||
| 207 | |||
| 208 | ofdev = to_of_device(dev); | ||
| 209 | |||
| 210 | kfree(ofdev); | ||
| 211 | } | ||
| 212 | |||
| 213 | int of_device_register(struct of_device *ofdev) | ||
| 214 | { | ||
| 215 | int rc; | ||
| 216 | |||
| 217 | BUG_ON(ofdev->node == NULL); | ||
| 218 | |||
| 219 | rc = device_register(&ofdev->dev); | ||
| 220 | if (rc) | ||
| 221 | return rc; | ||
| 222 | |||
| 223 | device_create_file(&ofdev->dev, &dev_attr_devspec); | ||
| 224 | |||
| 225 | return 0; | ||
| 226 | } | ||
| 227 | |||
| 228 | void of_device_unregister(struct of_device *ofdev) | ||
| 229 | { | ||
| 230 | device_remove_file(&ofdev->dev, &dev_attr_devspec); | ||
| 231 | device_unregister(&ofdev->dev); | ||
| 232 | } | ||
| 233 | |||
| 234 | struct of_device* of_platform_device_create(struct device_node *np, | ||
| 235 | const char *bus_id, | ||
| 236 | struct device *parent, | ||
| 237 | struct bus_type *bus) | ||
| 238 | { | ||
| 239 | struct of_device *dev; | ||
| 240 | |||
| 241 | dev = kmalloc(sizeof(*dev), GFP_KERNEL); | ||
| 242 | if (!dev) | ||
| 243 | return NULL; | ||
| 244 | memset(dev, 0, sizeof(*dev)); | ||
| 245 | |||
| 246 | dev->dev.parent = parent; | ||
| 247 | dev->dev.bus = bus; | ||
| 248 | dev->dev.release = of_release_dev; | ||
| 249 | |||
| 250 | strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE); | ||
| 251 | |||
| 252 | if (of_device_register(dev) != 0) { | ||
| 253 | kfree(dev); | ||
| 254 | return NULL; | ||
| 255 | } | ||
| 256 | |||
| 257 | return dev; | ||
| 258 | } | ||
| 259 | |||
| 260 | EXPORT_SYMBOL(of_match_device); | ||
| 261 | EXPORT_SYMBOL(of_register_driver); | ||
| 262 | EXPORT_SYMBOL(of_unregister_driver); | ||
| 263 | EXPORT_SYMBOL(of_device_register); | ||
| 264 | EXPORT_SYMBOL(of_device_unregister); | ||
| 265 | EXPORT_SYMBOL(of_dev_get); | ||
| 266 | EXPORT_SYMBOL(of_dev_put); | ||
| 267 | EXPORT_SYMBOL(of_platform_device_create); | ||
| 268 | EXPORT_SYMBOL(of_release_dev); | ||
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c index bcdf5ad0f035..bcfdddd0418a 100644 --- a/arch/sparc/kernel/pcic.c +++ b/arch/sparc/kernel/pcic.c | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | 31 | ||
| 32 | #include <asm/irq.h> | 32 | #include <asm/irq.h> |
| 33 | #include <asm/oplib.h> | 33 | #include <asm/oplib.h> |
| 34 | #include <asm/prom.h> | ||
| 34 | #include <asm/pcic.h> | 35 | #include <asm/pcic.h> |
| 35 | #include <asm/timer.h> | 36 | #include <asm/timer.h> |
| 36 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
| @@ -665,7 +666,7 @@ void __init pcibios_fixup_bus(struct pci_bus *bus) | |||
| 665 | /* cookies */ | 666 | /* cookies */ |
| 666 | pcp = pci_devcookie_alloc(); | 667 | pcp = pci_devcookie_alloc(); |
| 667 | pcp->pbm = &pcic->pbm; | 668 | pcp->pbm = &pcic->pbm; |
| 668 | pcp->prom_node = node; | 669 | pcp->prom_node = of_find_node_by_phandle(node); |
| 669 | dev->sysdata = pcp; | 670 | dev->sysdata = pcp; |
| 670 | 671 | ||
| 671 | /* fixing I/O to look like memory */ | 672 | /* fixing I/O to look like memory */ |
diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c new file mode 100644 index 000000000000..63b2b9bd778e --- /dev/null +++ b/arch/sparc/kernel/prom.c | |||
| @@ -0,0 +1,474 @@ | |||
| 1 | /* | ||
| 2 | * Procedures for creating, accessing and interpreting the device tree. | ||
| 3 | * | ||
| 4 | * Paul Mackerras August 1996. | ||
| 5 | * Copyright (C) 1996-2005 Paul Mackerras. | ||
| 6 | * | ||
| 7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | ||
| 8 | * {engebret|bergner}@us.ibm.com | ||
| 9 | * | ||
| 10 | * Adapted for sparc32 by David S. Miller davem@davemloft.net | ||
| 11 | * | ||
| 12 | * This program is free software; you can redistribute it and/or | ||
| 13 | * modify it under the terms of the GNU General Public License | ||
| 14 | * as published by the Free Software Foundation; either version | ||
| 15 | * 2 of the License, or (at your option) any later version. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <linux/kernel.h> | ||
| 19 | #include <linux/types.h> | ||
| 20 | #include <linux/string.h> | ||
| 21 | #include <linux/mm.h> | ||
| 22 | #include <linux/bootmem.h> | ||
| 23 | #include <linux/module.h> | ||
| 24 | |||
| 25 | #include <asm/prom.h> | ||
| 26 | #include <asm/oplib.h> | ||
| 27 | |||
| 28 | static struct device_node *allnodes; | ||
| 29 | |||
| 30 | int of_device_is_compatible(struct device_node *device, const char *compat) | ||
| 31 | { | ||
| 32 | const char* cp; | ||
| 33 | int cplen, l; | ||
| 34 | |||
| 35 | cp = (char *) of_get_property(device, "compatible", &cplen); | ||
| 36 | if (cp == NULL) | ||
| 37 | return 0; | ||
| 38 | while (cplen > 0) { | ||
| 39 | if (strncmp(cp, compat, strlen(compat)) == 0) | ||
| 40 | return 1; | ||
| 41 | l = strlen(cp) + 1; | ||
| 42 | cp += l; | ||
| 43 | cplen -= l; | ||
| 44 | } | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | EXPORT_SYMBOL(of_device_is_compatible); | ||
| 49 | |||
| 50 | struct device_node *of_get_parent(const struct device_node *node) | ||
| 51 | { | ||
| 52 | struct device_node *np; | ||
| 53 | |||
| 54 | if (!node) | ||
| 55 | return NULL; | ||
| 56 | |||
| 57 | np = node->parent; | ||
| 58 | |||
| 59 | return np; | ||
| 60 | } | ||
| 61 | EXPORT_SYMBOL(of_get_parent); | ||
| 62 | |||
| 63 | struct device_node *of_get_next_child(const struct device_node *node, | ||
| 64 | struct device_node *prev) | ||
| 65 | { | ||
| 66 | struct device_node *next; | ||
| 67 | |||
| 68 | next = prev ? prev->sibling : node->child; | ||
| 69 | for (; next != 0; next = next->sibling) { | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | |||
| 73 | return next; | ||
| 74 | } | ||
| 75 | EXPORT_SYMBOL(of_get_next_child); | ||
| 76 | |||
| 77 | struct device_node *of_find_node_by_path(const char *path) | ||
| 78 | { | ||
| 79 | struct device_node *np = allnodes; | ||
| 80 | |||
| 81 | for (; np != 0; np = np->allnext) { | ||
| 82 | if (np->full_name != 0 && strcmp(np->full_name, path) == 0) | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | |||
| 86 | return np; | ||
| 87 | } | ||
| 88 | EXPORT_SYMBOL(of_find_node_by_path); | ||
| 89 | |||
| 90 | struct device_node *of_find_node_by_phandle(phandle handle) | ||
| 91 | { | ||
| 92 | struct device_node *np; | ||
| 93 | |||
| 94 | for (np = allnodes; np != 0; np = np->allnext) | ||
| 95 | if (np->node == handle) | ||
| 96 | break; | ||
| 97 | |||
| 98 | return np; | ||
| 99 | } | ||
| 100 | EXPORT_SYMBOL(of_find_node_by_phandle); | ||
| 101 | |||
| 102 | struct device_node *of_find_node_by_name(struct device_node *from, | ||
| 103 | const char *name) | ||
| 104 | { | ||
| 105 | struct device_node *np; | ||
| 106 | |||
| 107 | np = from ? from->allnext : allnodes; | ||
| 108 | for (; np != NULL; np = np->allnext) | ||
| 109 | if (np->name != NULL && strcmp(np->name, name) == 0) | ||
| 110 | break; | ||
| 111 | |||
| 112 | return np; | ||
| 113 | } | ||
| 114 | EXPORT_SYMBOL(of_find_node_by_name); | ||
| 115 | |||
| 116 | struct device_node *of_find_node_by_type(struct device_node *from, | ||
| 117 | const char *type) | ||
| 118 | { | ||
| 119 | struct device_node *np; | ||
| 120 | |||
| 121 | np = from ? from->allnext : allnodes; | ||
| 122 | for (; np != 0; np = np->allnext) | ||
| 123 | if (np->type != 0 && strcmp(np->type, type) == 0) | ||
| 124 | break; | ||
| 125 | |||
| 126 | return np; | ||
| 127 | } | ||
| 128 | EXPORT_SYMBOL(of_find_node_by_type); | ||
| 129 | |||
| 130 | struct device_node *of_find_compatible_node(struct device_node *from, | ||
| 131 | const char *type, const char *compatible) | ||
| 132 | { | ||
| 133 | struct device_node *np; | ||
| 134 | |||
| 135 | np = from ? from->allnext : allnodes; | ||
| 136 | for (; np != 0; np = np->allnext) { | ||
| 137 | if (type != NULL | ||
| 138 | && !(np->type != 0 && strcmp(np->type, type) == 0)) | ||
| 139 | continue; | ||
| 140 | if (of_device_is_compatible(np, compatible)) | ||
| 141 | break; | ||
| 142 | } | ||
| 143 | |||
| 144 | return np; | ||
| 145 | } | ||
| 146 | EXPORT_SYMBOL(of_find_compatible_node); | ||
| 147 | |||
| 148 | struct property *of_find_property(struct device_node *np, const char *name, | ||
| 149 | int *lenp) | ||
| 150 | { | ||
| 151 | struct property *pp; | ||
| 152 | |||
| 153 | for (pp = np->properties; pp != 0; pp = pp->next) { | ||
| 154 | if (strcmp(pp->name, name) == 0) { | ||
| 155 | if (lenp != 0) | ||
| 156 | *lenp = pp->length; | ||
| 157 | break; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return pp; | ||
| 161 | } | ||
| 162 | EXPORT_SYMBOL(of_find_property); | ||
| 163 | |||
| 164 | /* | ||
| 165 | * Find a property with a given name for a given node | ||
| 166 | * and return the value. | ||
| 167 | */ | ||
| 168 | void *of_get_property(struct device_node *np, const char *name, int *lenp) | ||
| 169 | { | ||
| 170 | struct property *pp = of_find_property(np,name,lenp); | ||
| 171 | return pp ? pp->value : NULL; | ||
| 172 | } | ||
| 173 | EXPORT_SYMBOL(of_get_property); | ||
| 174 | |||
| 175 | int of_getintprop_default(struct device_node *np, const char *name, int def) | ||
| 176 | { | ||
| 177 | struct property *prop; | ||
| 178 | int len; | ||
| 179 | |||
| 180 | prop = of_find_property(np, name, &len); | ||
| 181 | if (!prop || len != 4) | ||
| 182 | return def; | ||
| 183 | |||
| 184 | return *(int *) prop->value; | ||
| 185 | } | ||
| 186 | EXPORT_SYMBOL(of_getintprop_default); | ||
| 187 | |||
| 188 | static unsigned int prom_early_allocated; | ||
| 189 | |||
| 190 | static void * __init prom_early_alloc(unsigned long size) | ||
| 191 | { | ||
| 192 | void *ret; | ||
| 193 | |||
| 194 | ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL); | ||
| 195 | if (ret != NULL) | ||
| 196 | memset(ret, 0, size); | ||
| 197 | |||
| 198 | prom_early_allocated += size; | ||
| 199 | |||
| 200 | return ret; | ||
| 201 | } | ||
| 202 | |||
| 203 | static int is_root_node(const struct device_node *dp) | ||
| 204 | { | ||
| 205 | if (!dp) | ||
| 206 | return 0; | ||
| 207 | |||
| 208 | return (dp->parent == NULL); | ||
| 209 | } | ||
| 210 | |||
| 211 | /* The following routines deal with the black magic of fully naming a | ||
| 212 | * node. | ||
| 213 | * | ||
| 214 | * Certain well known named nodes are just the simple name string. | ||
| 215 | * | ||
| 216 | * Actual devices have an address specifier appended to the base name | ||
| 217 | * string, like this "foo@addr". The "addr" can be in any number of | ||
| 218 | * formats, and the platform plus the type of the node determine the | ||
| 219 | * format and how it is constructed. | ||
| 220 | * | ||
| 221 | * For children of the ROOT node, the naming convention is fixed and | ||
| 222 | * determined by whether this is a sun4u or sun4v system. | ||
| 223 | * | ||
| 224 | * For children of other nodes, it is bus type specific. So | ||
| 225 | * we walk up the tree until we discover a "device_type" property | ||
| 226 | * we recognize and we go from there. | ||
| 227 | */ | ||
| 228 | static void __init sparc32_path_component(struct device_node *dp, char *tmp_buf) | ||
| 229 | { | ||
| 230 | struct linux_prom_registers *regs; | ||
| 231 | struct property *rprop; | ||
| 232 | |||
| 233 | rprop = of_find_property(dp, "reg", NULL); | ||
| 234 | if (!rprop) | ||
| 235 | return; | ||
| 236 | |||
| 237 | regs = rprop->value; | ||
| 238 | sprintf(tmp_buf, "%s@%x,%x", | ||
| 239 | dp->name, | ||
| 240 | regs->which_io, regs->phys_addr); | ||
| 241 | } | ||
| 242 | |||
| 243 | /* "name@slot,offset" */ | ||
| 244 | static void __init sbus_path_component(struct device_node *dp, char *tmp_buf) | ||
| 245 | { | ||
| 246 | struct linux_prom_registers *regs; | ||
| 247 | struct property *prop; | ||
| 248 | |||
| 249 | prop = of_find_property(dp, "reg", NULL); | ||
| 250 | if (!prop) | ||
| 251 | return; | ||
| 252 | |||
| 253 | regs = prop->value; | ||
| 254 | sprintf(tmp_buf, "%s@%x,%x", | ||
| 255 | dp->name, | ||
| 256 | regs->which_io, | ||
| 257 | regs->phys_addr); | ||
| 258 | } | ||
| 259 | |||
| 260 | /* "name@devnum[,func]" */ | ||
| 261 | static void __init pci_path_component(struct device_node *dp, char *tmp_buf) | ||
| 262 | { | ||
| 263 | struct linux_prom_pci_registers *regs; | ||
| 264 | struct property *prop; | ||
| 265 | unsigned int devfn; | ||
| 266 | |||
| 267 | prop = of_find_property(dp, "reg", NULL); | ||
| 268 | if (!prop) | ||
| 269 | return; | ||
| 270 | |||
| 271 | regs = prop->value; | ||
| 272 | devfn = (regs->phys_hi >> 8) & 0xff; | ||
| 273 | if (devfn & 0x07) { | ||
| 274 | sprintf(tmp_buf, "%s@%x,%x", | ||
| 275 | dp->name, | ||
| 276 | devfn >> 3, | ||
| 277 | devfn & 0x07); | ||
| 278 | } else { | ||
| 279 | sprintf(tmp_buf, "%s@%x", | ||
| 280 | dp->name, | ||
| 281 | devfn >> 3); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | /* "name@addrhi,addrlo" */ | ||
| 286 | static void __init ebus_path_component(struct device_node *dp, char *tmp_buf) | ||
| 287 | { | ||
| 288 | struct linux_prom_registers *regs; | ||
| 289 | struct property *prop; | ||
| 290 | |||
| 291 | prop = of_find_property(dp, "reg", NULL); | ||
| 292 | if (!prop) | ||
| 293 | return; | ||
| 294 | |||
| 295 | regs = prop->value; | ||
| 296 | |||
| 297 | sprintf(tmp_buf, "%s@%x,%x", | ||
| 298 | dp->name, | ||
| 299 | regs->which_io, regs->phys_addr); | ||
| 300 | } | ||
| 301 | |||
| 302 | static void __init __build_path_component(struct device_node *dp, char *tmp_buf) | ||
| 303 | { | ||
| 304 | struct device_node *parent = dp->parent; | ||
| 305 | |||
| 306 | if (parent != NULL) { | ||
| 307 | if (!strcmp(parent->type, "pci") || | ||
| 308 | !strcmp(parent->type, "pciex")) | ||
| 309 | return pci_path_component(dp, tmp_buf); | ||
| 310 | if (!strcmp(parent->type, "sbus")) | ||
| 311 | return sbus_path_component(dp, tmp_buf); | ||
| 312 | if (!strcmp(parent->type, "ebus")) | ||
| 313 | return ebus_path_component(dp, tmp_buf); | ||
| 314 | |||
| 315 | /* "isa" is handled with platform naming */ | ||
| 316 | } | ||
| 317 | |||
| 318 | /* Use platform naming convention. */ | ||
| 319 | return sparc32_path_component(dp, tmp_buf); | ||
| 320 | } | ||
| 321 | |||
| 322 | static char * __init build_path_component(struct device_node *dp) | ||
| 323 | { | ||
| 324 | char tmp_buf[64], *n; | ||
| 325 | |||
| 326 | tmp_buf[0] = '\0'; | ||
| 327 | __build_path_component(dp, tmp_buf); | ||
| 328 | if (tmp_buf[0] == '\0') | ||
| 329 | strcpy(tmp_buf, dp->name); | ||
| 330 | |||
| 331 | n = prom_early_alloc(strlen(tmp_buf) + 1); | ||
| 332 | strcpy(n, tmp_buf); | ||
| 333 | |||
| 334 | return n; | ||
| 335 | } | ||
| 336 | |||
| 337 | static char * __init build_full_name(struct device_node *dp) | ||
| 338 | { | ||
| 339 | int len, ourlen, plen; | ||
| 340 | char *n; | ||
| 341 | |||
| 342 | plen = strlen(dp->parent->full_name); | ||
| 343 | ourlen = strlen(dp->path_component_name); | ||
| 344 | len = ourlen + plen + 2; | ||
| 345 | |||
| 346 | n = prom_early_alloc(len); | ||
| 347 | strcpy(n, dp->parent->full_name); | ||
| 348 | if (!is_root_node(dp->parent)) { | ||
| 349 | strcpy(n + plen, "/"); | ||
| 350 | plen++; | ||
| 351 | } | ||
| 352 | strcpy(n + plen, dp->path_component_name); | ||
| 353 | |||
| 354 | return n; | ||
| 355 | } | ||
| 356 | |||
| 357 | static struct property * __init build_one_prop(phandle node, char *prev) | ||
| 358 | { | ||
| 359 | static struct property *tmp = NULL; | ||
| 360 | struct property *p; | ||
| 361 | int len; | ||
| 362 | |||
| 363 | if (tmp) { | ||
| 364 | p = tmp; | ||
| 365 | memset(p, 0, sizeof(*p) + 32); | ||
| 366 | tmp = NULL; | ||
| 367 | } else | ||
| 368 | p = prom_early_alloc(sizeof(struct property) + 32); | ||
| 369 | |||
| 370 | p->name = (char *) (p + 1); | ||
| 371 | if (prev == NULL) { | ||
| 372 | prom_firstprop(node, p->name); | ||
| 373 | } else { | ||
| 374 | prom_nextprop(node, prev, p->name); | ||
| 375 | } | ||
| 376 | if (strlen(p->name) == 0) { | ||
| 377 | tmp = p; | ||
| 378 | return NULL; | ||
| 379 | } | ||
| 380 | p->length = prom_getproplen(node, p->name); | ||
| 381 | if (p->length <= 0) { | ||
| 382 | p->length = 0; | ||
| 383 | } else { | ||
| 384 | p->value = prom_early_alloc(p->length); | ||
| 385 | len = prom_getproperty(node, p->name, p->value, p->length); | ||
| 386 | } | ||
| 387 | return p; | ||
| 388 | } | ||
| 389 | |||
| 390 | static struct property * __init build_prop_list(phandle node) | ||
| 391 | { | ||
| 392 | struct property *head, *tail; | ||
| 393 | |||
| 394 | head = tail = build_one_prop(node, NULL); | ||
| 395 | while(tail) { | ||
| 396 | tail->next = build_one_prop(node, tail->name); | ||
| 397 | tail = tail->next; | ||
| 398 | } | ||
| 399 | |||
| 400 | return head; | ||
| 401 | } | ||
| 402 | |||
| 403 | static char * __init get_one_property(phandle node, char *name) | ||
| 404 | { | ||
| 405 | char *buf = "<NULL>"; | ||
| 406 | int len; | ||
| 407 | |||
| 408 | len = prom_getproplen(node, name); | ||
| 409 | if (len > 0) { | ||
| 410 | buf = prom_early_alloc(len); | ||
| 411 | len = prom_getproperty(node, name, buf, len); | ||
| 412 | } | ||
| 413 | |||
| 414 | return buf; | ||
| 415 | } | ||
| 416 | |||
| 417 | static struct device_node * __init create_node(phandle node) | ||
| 418 | { | ||
| 419 | struct device_node *dp; | ||
| 420 | |||
| 421 | if (!node) | ||
| 422 | return NULL; | ||
| 423 | |||
| 424 | dp = prom_early_alloc(sizeof(*dp)); | ||
| 425 | |||
| 426 | kref_init(&dp->kref); | ||
| 427 | |||
| 428 | dp->name = get_one_property(node, "name"); | ||
| 429 | dp->type = get_one_property(node, "device_type"); | ||
| 430 | dp->node = node; | ||
| 431 | |||
| 432 | /* Build interrupts later... */ | ||
| 433 | |||
| 434 | dp->properties = build_prop_list(node); | ||
| 435 | |||
| 436 | return dp; | ||
| 437 | } | ||
| 438 | |||
| 439 | static struct device_node * __init build_tree(struct device_node *parent, phandle node, struct device_node ***nextp) | ||
| 440 | { | ||
| 441 | struct device_node *dp; | ||
| 442 | |||
| 443 | dp = create_node(node); | ||
| 444 | if (dp) { | ||
| 445 | *(*nextp) = dp; | ||
| 446 | *nextp = &dp->allnext; | ||
| 447 | |||
| 448 | dp->parent = parent; | ||
| 449 | dp->path_component_name = build_path_component(dp); | ||
| 450 | dp->full_name = build_full_name(dp); | ||
| 451 | |||
| 452 | dp->child = build_tree(dp, prom_getchild(node), nextp); | ||
| 453 | |||
| 454 | dp->sibling = build_tree(parent, prom_getsibling(node), nextp); | ||
| 455 | } | ||
| 456 | |||
| 457 | return dp; | ||
| 458 | } | ||
| 459 | |||
| 460 | void __init prom_build_devicetree(void) | ||
| 461 | { | ||
| 462 | struct device_node **nextp; | ||
| 463 | |||
| 464 | allnodes = create_node(prom_root_node); | ||
| 465 | allnodes->path_component_name = ""; | ||
| 466 | allnodes->full_name = "/"; | ||
| 467 | |||
| 468 | nextp = &allnodes->allnext; | ||
| 469 | allnodes->child = build_tree(allnodes, | ||
| 470 | prom_getchild(allnodes->node), | ||
| 471 | &nextp); | ||
| 472 | printk("PROM: Built device tree with %u bytes of memory.\n", | ||
| 473 | prom_early_allocated); | ||
| 474 | } | ||
diff --git a/arch/sparc/mm/init.c b/arch/sparc/mm/init.c index 898669732466..cfa7d3456634 100644 --- a/arch/sparc/mm/init.c +++ b/arch/sparc/mm/init.c | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <asm/vaddrs.h> | 31 | #include <asm/vaddrs.h> |
| 32 | #include <asm/pgalloc.h> /* bug in asm-generic/tlb.h: check_pgt_cache */ | 32 | #include <asm/pgalloc.h> /* bug in asm-generic/tlb.h: check_pgt_cache */ |
| 33 | #include <asm/tlb.h> | 33 | #include <asm/tlb.h> |
| 34 | #include <asm/prom.h> | ||
| 34 | 35 | ||
| 35 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); | 36 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 36 | 37 | ||
| @@ -349,6 +350,7 @@ void __init paging_init(void) | |||
| 349 | protection_map[14] = PAGE_SHARED; | 350 | protection_map[14] = PAGE_SHARED; |
| 350 | protection_map[15] = PAGE_SHARED; | 351 | protection_map[15] = PAGE_SHARED; |
| 351 | btfixup(); | 352 | btfixup(); |
| 353 | prom_build_devicetree(); | ||
| 352 | device_scan(); | 354 | device_scan(); |
| 353 | } | 355 | } |
| 354 | 356 | ||
