| Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * ebus.c: PCI to EBus bridge device. | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 1997  Eddie C. Dost  (ecd@skynet.be) | 
|  | 5 | * | 
|  | 6 | * Adopted for sparc by V. Roganov and G. Raiko. | 
|  | 7 | * Fixes for different platforms by Pete Zaitcev. | 
|  | 8 | */ | 
|  | 9 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/kernel.h> | 
|  | 11 | #include <linux/types.h> | 
|  | 12 | #include <linux/init.h> | 
|  | 13 | #include <linux/slab.h> | 
|  | 14 | #include <linux/string.h> | 
|  | 15 |  | 
|  | 16 | #include <asm/system.h> | 
|  | 17 | #include <asm/page.h> | 
|  | 18 | #include <asm/pbm.h> | 
|  | 19 | #include <asm/ebus.h> | 
|  | 20 | #include <asm/io.h> | 
|  | 21 | #include <asm/oplib.h> | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 22 | #include <asm/prom.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/bpp.h> | 
|  | 24 |  | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 25 | struct linux_ebus *ebus_chain = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | /* We are together with pcic.c under CONFIG_PCI. */ | 
| Stephen Rothwell | ee5ac9d | 2007-04-26 00:03:53 -0700 | [diff] [blame] | 28 | extern unsigned int pcic_pin_to_irq(unsigned int, const char *name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 |  | 
|  | 30 | /* | 
|  | 31 | * IRQ Blacklist | 
|  | 32 | * Here we list PROMs and systems that are known to supply crap as IRQ numbers. | 
|  | 33 | */ | 
|  | 34 | struct ebus_device_irq { | 
|  | 35 | char *name; | 
|  | 36 | unsigned int pin; | 
|  | 37 | }; | 
|  | 38 |  | 
|  | 39 | struct ebus_system_entry { | 
|  | 40 | char *esname; | 
|  | 41 | struct ebus_device_irq *ipt; | 
|  | 42 | }; | 
|  | 43 |  | 
|  | 44 | static struct ebus_device_irq je1_1[] = { | 
|  | 45 | { "8042",		 3 }, | 
|  | 46 | { "SUNW,CS4231",	 0 }, | 
|  | 47 | { "parallel",		 0 }, | 
|  | 48 | { "se",			 2 }, | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 49 | { NULL, 0 } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; | 
|  | 51 |  | 
|  | 52 | /* | 
|  | 53 | * Gleb's JE1 supplied reasonable pin numbers, but mine did not (OBP 2.32). | 
|  | 54 | * Blacklist the sucker... Note that Gleb's system will work. | 
|  | 55 | */ | 
|  | 56 | static struct ebus_system_entry ebus_blacklist[] = { | 
|  | 57 | { "SUNW,JavaEngine1", je1_1 }, | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 58 | { NULL, NULL } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; | 
|  | 60 |  | 
|  | 61 | static struct ebus_device_irq *ebus_blackp = NULL; | 
|  | 62 |  | 
|  | 63 | /* | 
|  | 64 | */ | 
|  | 65 | static inline unsigned long ebus_alloc(size_t size) | 
|  | 66 | { | 
|  | 67 | return (unsigned long)kmalloc(size, GFP_ATOMIC); | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | /* | 
|  | 71 | */ | 
| Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 72 | static int __init ebus_blacklist_irq(const char *name) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { | 
|  | 74 | struct ebus_device_irq *dp; | 
|  | 75 |  | 
|  | 76 | if ((dp = ebus_blackp) != NULL) { | 
|  | 77 | for (; dp->name != NULL; dp++) { | 
|  | 78 | if (strcmp(name, dp->name) == 0) { | 
|  | 79 | return pcic_pin_to_irq(dp->pin, name); | 
|  | 80 | } | 
|  | 81 | } | 
|  | 82 | } | 
|  | 83 | return 0; | 
|  | 84 | } | 
|  | 85 |  | 
| Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 86 | static void __init fill_ebus_child(struct device_node *dp, | 
|  | 87 | struct linux_ebus_child *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { | 
| Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 89 | const int *regs; | 
|  | 90 | const int *irqs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | int i, len; | 
|  | 92 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 93 | dev->prom_node = dp; | 
|  | 94 | regs = of_get_property(dp, "reg", &len); | 
|  | 95 | if (!regs) | 
|  | 96 | len = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | dev->num_addrs = len / sizeof(regs[0]); | 
|  | 98 |  | 
|  | 99 | for (i = 0; i < dev->num_addrs; i++) { | 
|  | 100 | if (regs[i] >= dev->parent->num_addrs) { | 
|  | 101 | prom_printf("UGH: property for %s was %d, need < %d\n", | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 102 | dev->prom_node->name, len, | 
|  | 103 | dev->parent->num_addrs); | 
| Harvey Harrison | 74074de | 2008-03-03 11:41:51 -0800 | [diff] [blame] | 104 | panic(__func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 106 |  | 
|  | 107 | /* XXX resource */ | 
|  | 108 | dev->resource[i].start = | 
|  | 109 | dev->parent->resource[regs[i]].start; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } | 
|  | 111 |  | 
|  | 112 | for (i = 0; i < PROMINTR_MAX; i++) | 
|  | 113 | dev->irqs[i] = PCI_IRQ_NONE; | 
|  | 114 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 115 | if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_node->name)) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | dev->num_irqs = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } else { | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 118 | irqs = of_get_property(dp, "interrupts", &len); | 
|  | 119 | if (!irqs) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | dev->num_irqs = 0; | 
|  | 121 | dev->irqs[0] = 0; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 122 | if (dev->parent->num_irqs != 0) { | 
|  | 123 | dev->num_irqs = 1; | 
|  | 124 | dev->irqs[0] = dev->parent->irqs[0]; | 
|  | 125 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } else { | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 127 | dev->num_irqs = len / sizeof(irqs[0]); | 
|  | 128 | if (irqs[0] == 0 || irqs[0] >= 8) { | 
|  | 129 | /* | 
|  | 130 | * XXX Zero is a valid pin number... | 
|  | 131 | * This works as long as Ebus is not wired | 
|  | 132 | * to INTA#. | 
|  | 133 | */ | 
|  | 134 | printk("EBUS: %s got bad irq %d from PROM\n", | 
|  | 135 | dev->prom_node->name, irqs[0]); | 
|  | 136 | dev->num_irqs = 0; | 
|  | 137 | dev->irqs[0] = 0; | 
|  | 138 | } else { | 
|  | 139 | dev->irqs[0] = | 
|  | 140 | pcic_pin_to_irq(irqs[0], | 
|  | 141 | dev->prom_node->name); | 
|  | 142 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } | 
|  | 144 | } | 
|  | 145 | } | 
|  | 146 |  | 
| Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 147 | static void __init fill_ebus_device(struct device_node *dp, | 
|  | 148 | struct linux_ebus_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { | 
| Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 150 | const struct linux_prom_registers *regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | struct linux_ebus_child *child; | 
| David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 152 | struct dev_archdata *sd; | 
| Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 153 | const int *irqs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | int i, n, len; | 
|  | 155 | unsigned long baseaddr; | 
|  | 156 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 157 | dev->prom_node = dp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 159 | regs = of_get_property(dp, "reg", &len); | 
| David S. Miller | 9c908f9 | 2007-09-27 13:09:28 -0700 | [diff] [blame] | 160 | if (!regs) | 
|  | 161 | len = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | if (len % sizeof(struct linux_prom_registers)) { | 
|  | 163 | prom_printf("UGH: proplen for %s was %d, need multiple of %d\n", | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 164 | dev->prom_node->name, len, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | (int)sizeof(struct linux_prom_registers)); | 
| Harvey Harrison | 74074de | 2008-03-03 11:41:51 -0800 | [diff] [blame] | 166 | panic(__func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } | 
|  | 168 | dev->num_addrs = len / sizeof(struct linux_prom_registers); | 
|  | 169 |  | 
|  | 170 | for (i = 0; i < dev->num_addrs; i++) { | 
|  | 171 | /* | 
|  | 172 | * XXX Collect JE-1 PROM | 
|  | 173 | * | 
|  | 174 | * Example - JS-E with 3.11: | 
|  | 175 | *  /ebus | 
|  | 176 | *      regs | 
|  | 177 | *        0x00000000, 0x0, 0x00000000, 0x0, 0x00000000, | 
|  | 178 | *        0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000, | 
|  | 179 | *        0x82000014, 0x0, 0x38800000, 0x0, 0x00800000, | 
|  | 180 | *      ranges | 
|  | 181 | *        0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000, | 
|  | 182 | *        0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000, | 
|  | 183 | *  /ebus/8042 | 
|  | 184 | *      regs | 
|  | 185 | *        0x00000001, 0x00300060, 0x00000008, | 
|  | 186 | *        0x00000001, 0x00300060, 0x00000008, | 
|  | 187 | */ | 
|  | 188 | n = regs[i].which_io; | 
|  | 189 | if (n >= 4) { | 
|  | 190 | /* XXX This is copied from old JE-1 by Gleb. */ | 
|  | 191 | n = (regs[i].which_io - 0x10) >> 2; | 
|  | 192 | } else { | 
|  | 193 | ; | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | /* | 
|  | 197 | * XXX Now as we have regions, why don't we make an on-demand allocation... | 
|  | 198 | */ | 
|  | 199 | dev->resource[i].start = 0; | 
|  | 200 | if ((baseaddr = dev->bus->self->resource[n].start + | 
|  | 201 | regs[i].phys_addr) != 0) { | 
|  | 202 | /* dev->resource[i].name = dev->prom_name; */ | 
|  | 203 | if ((baseaddr = (unsigned long) ioremap(baseaddr, | 
|  | 204 | regs[i].reg_size)) == 0) { | 
|  | 205 | panic("ebus: unable to remap dev %s", | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 206 | dev->prom_node->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } | 
|  | 208 | } | 
|  | 209 | dev->resource[i].start = baseaddr;	/* XXX Unaligned */ | 
|  | 210 | } | 
|  | 211 |  | 
|  | 212 | for (i = 0; i < PROMINTR_MAX; i++) | 
|  | 213 | dev->irqs[i] = PCI_IRQ_NONE; | 
|  | 214 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 215 | if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_node->name)) != 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | dev->num_irqs = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } else { | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 218 | irqs = of_get_property(dp, "interrupts", &len); | 
|  | 219 | if (!irqs) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | dev->num_irqs = 0; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 221 | if ((dev->irqs[0] = dev->bus->self->irq) != 0) { | 
|  | 222 | dev->num_irqs = 1; | 
|  | 223 | /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */ | 
|  | 224 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } else { | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 226 | dev->num_irqs = 1;  /* dev->num_irqs = len / sizeof(irqs[0]); */ | 
|  | 227 | if (irqs[0] == 0 || irqs[0] >= 8) { | 
|  | 228 | /* See above for the parent. XXX */ | 
|  | 229 | printk("EBUS: %s got bad irq %d from PROM\n", | 
|  | 230 | dev->prom_node->name, irqs[0]); | 
|  | 231 | dev->num_irqs = 0; | 
|  | 232 | dev->irqs[0] = 0; | 
|  | 233 | } else { | 
|  | 234 | dev->irqs[0] = | 
|  | 235 | pcic_pin_to_irq(irqs[0], | 
|  | 236 | dev->prom_node->name); | 
|  | 237 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } | 
|  | 239 | } | 
|  | 240 |  | 
| David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 241 | sd = &dev->ofdev.dev.archdata; | 
|  | 242 | sd->prom_node = dp; | 
|  | 243 | sd->op = &dev->ofdev; | 
| Robert Reif | 3ac4c94 | 2007-08-10 15:52:06 -0700 | [diff] [blame] | 244 | sd->iommu = dev->bus->ofdev.dev.parent->archdata.iommu; | 
| David S. Miller | 3d6e470 | 2007-07-18 22:03:25 -0700 | [diff] [blame] | 245 |  | 
| David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 246 | dev->ofdev.node = dp; | 
|  | 247 | dev->ofdev.dev.parent = &dev->bus->ofdev.dev; | 
|  | 248 | dev->ofdev.dev.bus = &ebus_bus_type; | 
| David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 249 | sprintf(dev->ofdev.dev.bus_id, "ebus[%08x]", dp->node); | 
| David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 250 |  | 
|  | 251 | /* Register with core */ | 
|  | 252 | if (of_device_register(&dev->ofdev) != 0) | 
|  | 253 | printk(KERN_DEBUG "ebus: device registration error for %s!\n", | 
| David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 254 | dp->path_component_name); | 
| David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 255 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 256 | if ((dp = dp->child) != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | dev->children = (struct linux_ebus_child *) | 
|  | 258 | ebus_alloc(sizeof(struct linux_ebus_child)); | 
|  | 259 |  | 
|  | 260 | child = dev->children; | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 261 | child->next = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | child->parent = dev; | 
|  | 263 | child->bus = dev->bus; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 264 | fill_ebus_child(dp, child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 266 | while ((dp = dp->sibling) != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | child->next = (struct linux_ebus_child *) | 
|  | 268 | ebus_alloc(sizeof(struct linux_ebus_child)); | 
|  | 269 |  | 
|  | 270 | child = child->next; | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 271 | child->next = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | child->parent = dev; | 
|  | 273 | child->bus = dev->bus; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 274 | fill_ebus_child(dp, child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } | 
|  | 276 | } | 
|  | 277 | } | 
|  | 278 |  | 
|  | 279 | void __init ebus_init(void) | 
|  | 280 | { | 
| Stephen Rothwell | 8271f04 | 2007-03-29 00:47:23 -0700 | [diff] [blame] | 281 | const struct linux_prom_pci_registers *regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | struct linux_pbm_info *pbm; | 
|  | 283 | struct linux_ebus_device *dev; | 
|  | 284 | struct linux_ebus *ebus; | 
|  | 285 | struct ebus_system_entry *sp; | 
|  | 286 | struct pci_dev *pdev; | 
|  | 287 | struct pcidev_cookie *cookie; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 288 | struct device_node *dp; | 
| Al Viro | cc9bd99 | 2006-09-23 01:18:41 +0100 | [diff] [blame] | 289 | struct resource *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | unsigned short pci_command; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 291 | int len, reg, nreg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | int num_ebus = 0; | 
|  | 293 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 294 | dp = of_find_node_by_path("/"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | for (sp = ebus_blacklist; sp->esname != NULL; sp++) { | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 296 | if (strcmp(dp->name, sp->esname) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | ebus_blackp = sp->ipt; | 
|  | 298 | break; | 
|  | 299 | } | 
|  | 300 | } | 
|  | 301 |  | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 302 | pdev = pci_get_device(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_EBUS, NULL); | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 303 | if (!pdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 305 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | cookie = pdev->sysdata; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 307 | dp = cookie->prom_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 |  | 
|  | 309 | ebus_chain = ebus = (struct linux_ebus *) | 
|  | 310 | ebus_alloc(sizeof(struct linux_ebus)); | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 311 | ebus->next = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 313 | while (dp) { | 
|  | 314 | struct device_node *nd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 316 | ebus->prom_node = dp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | ebus->self = pdev; | 
|  | 318 | ebus->parent = pbm = cookie->pbm; | 
|  | 319 |  | 
|  | 320 | /* Enable BUS Master. */ | 
|  | 321 | pci_read_config_word(pdev, PCI_COMMAND, &pci_command); | 
|  | 322 | pci_command |= PCI_COMMAND_MASTER; | 
|  | 323 | pci_write_config_word(pdev, PCI_COMMAND, pci_command); | 
|  | 324 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 325 | regs = of_get_property(dp, "reg", &len); | 
|  | 326 | if (!regs) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | prom_printf("%s: can't find reg property\n", | 
| Harvey Harrison | 74074de | 2008-03-03 11:41:51 -0800 | [diff] [blame] | 328 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | prom_halt(); | 
|  | 330 | } | 
|  | 331 | nreg = len / sizeof(struct linux_prom_pci_registers); | 
|  | 332 |  | 
| Al Viro | cc9bd99 | 2006-09-23 01:18:41 +0100 | [diff] [blame] | 333 | p = &ebus->self->resource[0]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | for (reg = 0; reg < nreg; reg++) { | 
|  | 335 | if (!(regs[reg].which_io & 0x03000000)) | 
|  | 336 | continue; | 
|  | 337 |  | 
| Al Viro | cc9bd99 | 2006-09-23 01:18:41 +0100 | [diff] [blame] | 338 | (p++)->start = regs[reg].phys_lo; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } | 
|  | 340 |  | 
| David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 341 | ebus->ofdev.node = dp; | 
|  | 342 | ebus->ofdev.dev.parent = &pdev->dev; | 
|  | 343 | ebus->ofdev.dev.bus = &ebus_bus_type; | 
| David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 344 | sprintf(ebus->ofdev.dev.bus_id, "ebus%d", num_ebus); | 
| David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 345 |  | 
|  | 346 | /* Register with core */ | 
|  | 347 | if (of_device_register(&ebus->ofdev) != 0) | 
|  | 348 | printk(KERN_DEBUG "ebus: device registration error for %s!\n", | 
| David S. Miller | f5ef9d1 | 2006-10-27 01:03:31 -0700 | [diff] [blame] | 349 | dp->path_component_name); | 
| David S. Miller | fd53143 | 2006-06-23 15:55:17 -0700 | [diff] [blame] | 350 |  | 
|  | 351 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 352 | nd = dp->child; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (!nd) | 
|  | 354 | goto next_ebus; | 
|  | 355 |  | 
|  | 356 | ebus->devices = (struct linux_ebus_device *) | 
|  | 357 | ebus_alloc(sizeof(struct linux_ebus_device)); | 
|  | 358 |  | 
|  | 359 | dev = ebus->devices; | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 360 | dev->next = NULL; | 
|  | 361 | dev->children = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | dev->bus = ebus; | 
|  | 363 | fill_ebus_device(nd, dev); | 
|  | 364 |  | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 365 | while ((nd = nd->sibling) != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | dev->next = (struct linux_ebus_device *) | 
|  | 367 | ebus_alloc(sizeof(struct linux_ebus_device)); | 
|  | 368 |  | 
|  | 369 | dev = dev->next; | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 370 | dev->next = NULL; | 
|  | 371 | dev->children = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | dev->bus = ebus; | 
|  | 373 | fill_ebus_device(nd, dev); | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | next_ebus: | 
|  | 377 | pdev = pci_get_device(PCI_VENDOR_ID_SUN, | 
|  | 378 | PCI_DEVICE_ID_SUN_EBUS, pdev); | 
|  | 379 | if (!pdev) | 
|  | 380 | break; | 
|  | 381 |  | 
|  | 382 | cookie = pdev->sysdata; | 
| David S. Miller | 942a6bd | 2006-06-23 15:53:31 -0700 | [diff] [blame] | 383 | dp = cookie->prom_node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 |  | 
|  | 385 | ebus->next = (struct linux_ebus *) | 
|  | 386 | ebus_alloc(sizeof(struct linux_ebus)); | 
|  | 387 | ebus = ebus->next; | 
| Al Viro | e4fe342 | 2005-12-04 18:48:45 -0500 | [diff] [blame] | 388 | ebus->next = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | ++num_ebus; | 
|  | 390 | } | 
|  | 391 | if (pdev) | 
|  | 392 | pci_dev_put(pdev); | 
|  | 393 | } |