Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: ebus.c,v 1.64 2001/11/08 04:41:33 davem Exp $ |
| 2 | * ebus.c: PCI to EBus bridge device. |
| 3 | * |
| 4 | * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) |
| 5 | * Copyright (C) 1999 David S. Miller (davem@redhat.com) |
| 6 | */ |
| 7 | |
| 8 | #include <linux/config.h> |
| 9 | #include <linux/module.h> |
| 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 | #include <linux/interrupt.h> |
| 16 | #include <linux/delay.h> |
| 17 | |
| 18 | #include <asm/system.h> |
| 19 | #include <asm/page.h> |
| 20 | #include <asm/pbm.h> |
| 21 | #include <asm/ebus.h> |
| 22 | #include <asm/oplib.h> |
| 23 | #include <asm/bpp.h> |
| 24 | #include <asm/irq.h> |
| 25 | |
| 26 | /* EBUS dma library. */ |
| 27 | |
| 28 | #define EBDMA_CSR 0x00UL /* Control/Status */ |
| 29 | #define EBDMA_ADDR 0x04UL /* DMA Address */ |
| 30 | #define EBDMA_COUNT 0x08UL /* DMA Count */ |
| 31 | |
| 32 | #define EBDMA_CSR_INT_PEND 0x00000001 |
| 33 | #define EBDMA_CSR_ERR_PEND 0x00000002 |
| 34 | #define EBDMA_CSR_DRAIN 0x00000004 |
| 35 | #define EBDMA_CSR_INT_EN 0x00000010 |
| 36 | #define EBDMA_CSR_RESET 0x00000080 |
| 37 | #define EBDMA_CSR_WRITE 0x00000100 |
| 38 | #define EBDMA_CSR_EN_DMA 0x00000200 |
| 39 | #define EBDMA_CSR_CYC_PEND 0x00000400 |
| 40 | #define EBDMA_CSR_DIAG_RD_DONE 0x00000800 |
| 41 | #define EBDMA_CSR_DIAG_WR_DONE 0x00001000 |
| 42 | #define EBDMA_CSR_EN_CNT 0x00002000 |
| 43 | #define EBDMA_CSR_TC 0x00004000 |
| 44 | #define EBDMA_CSR_DIS_CSR_DRN 0x00010000 |
| 45 | #define EBDMA_CSR_BURST_SZ_MASK 0x000c0000 |
| 46 | #define EBDMA_CSR_BURST_SZ_1 0x00080000 |
| 47 | #define EBDMA_CSR_BURST_SZ_4 0x00000000 |
| 48 | #define EBDMA_CSR_BURST_SZ_8 0x00040000 |
| 49 | #define EBDMA_CSR_BURST_SZ_16 0x000c0000 |
| 50 | #define EBDMA_CSR_DIAG_EN 0x00100000 |
| 51 | #define EBDMA_CSR_DIS_ERR_PEND 0x00400000 |
| 52 | #define EBDMA_CSR_TCI_DIS 0x00800000 |
| 53 | #define EBDMA_CSR_EN_NEXT 0x01000000 |
| 54 | #define EBDMA_CSR_DMA_ON 0x02000000 |
| 55 | #define EBDMA_CSR_A_LOADED 0x04000000 |
| 56 | #define EBDMA_CSR_NA_LOADED 0x08000000 |
| 57 | #define EBDMA_CSR_DEV_ID_MASK 0xf0000000 |
| 58 | |
| 59 | #define EBUS_DMA_RESET_TIMEOUT 10000 |
| 60 | |
| 61 | static void __ebus_dma_reset(struct ebus_dma_info *p, int no_drain) |
| 62 | { |
| 63 | int i; |
| 64 | u32 val = 0; |
| 65 | |
| 66 | writel(EBDMA_CSR_RESET, p->regs + EBDMA_CSR); |
| 67 | udelay(1); |
| 68 | |
| 69 | if (no_drain) |
| 70 | return; |
| 71 | |
| 72 | for (i = EBUS_DMA_RESET_TIMEOUT; i > 0; i--) { |
| 73 | val = readl(p->regs + EBDMA_CSR); |
| 74 | |
| 75 | if (!(val & (EBDMA_CSR_DRAIN | EBDMA_CSR_CYC_PEND))) |
| 76 | break; |
| 77 | udelay(10); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | static irqreturn_t ebus_dma_irq(int irq, void *dev_id, struct pt_regs *regs) |
| 82 | { |
| 83 | struct ebus_dma_info *p = dev_id; |
| 84 | unsigned long flags; |
| 85 | u32 csr = 0; |
| 86 | |
| 87 | spin_lock_irqsave(&p->lock, flags); |
| 88 | csr = readl(p->regs + EBDMA_CSR); |
| 89 | writel(csr, p->regs + EBDMA_CSR); |
| 90 | spin_unlock_irqrestore(&p->lock, flags); |
| 91 | |
| 92 | if (csr & EBDMA_CSR_ERR_PEND) { |
| 93 | printk(KERN_CRIT "ebus_dma(%s): DMA error!\n", p->name); |
| 94 | p->callback(p, EBUS_DMA_EVENT_ERROR, p->client_cookie); |
| 95 | return IRQ_HANDLED; |
| 96 | } else if (csr & EBDMA_CSR_INT_PEND) { |
| 97 | p->callback(p, |
| 98 | (csr & EBDMA_CSR_TC) ? |
| 99 | EBUS_DMA_EVENT_DMA : EBUS_DMA_EVENT_DEVICE, |
| 100 | p->client_cookie); |
| 101 | return IRQ_HANDLED; |
| 102 | } |
| 103 | |
| 104 | return IRQ_NONE; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | int ebus_dma_register(struct ebus_dma_info *p) |
| 109 | { |
| 110 | u32 csr; |
| 111 | |
| 112 | if (!p->regs) |
| 113 | return -EINVAL; |
| 114 | if (p->flags & ~(EBUS_DMA_FLAG_USE_EBDMA_HANDLER | |
| 115 | EBUS_DMA_FLAG_TCI_DISABLE)) |
| 116 | return -EINVAL; |
| 117 | if ((p->flags & EBUS_DMA_FLAG_USE_EBDMA_HANDLER) && !p->callback) |
| 118 | return -EINVAL; |
| 119 | if (!strlen(p->name)) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | __ebus_dma_reset(p, 1); |
| 123 | |
| 124 | csr = EBDMA_CSR_BURST_SZ_16 | EBDMA_CSR_EN_CNT; |
| 125 | |
| 126 | if (p->flags & EBUS_DMA_FLAG_TCI_DISABLE) |
| 127 | csr |= EBDMA_CSR_TCI_DIS; |
| 128 | |
| 129 | writel(csr, p->regs + EBDMA_CSR); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | EXPORT_SYMBOL(ebus_dma_register); |
| 134 | |
| 135 | int ebus_dma_irq_enable(struct ebus_dma_info *p, int on) |
| 136 | { |
| 137 | unsigned long flags; |
| 138 | u32 csr; |
| 139 | |
| 140 | if (on) { |
| 141 | if (p->flags & EBUS_DMA_FLAG_USE_EBDMA_HANDLER) { |
| 142 | if (request_irq(p->irq, ebus_dma_irq, SA_SHIRQ, p->name, p)) |
| 143 | return -EBUSY; |
| 144 | } |
| 145 | |
| 146 | spin_lock_irqsave(&p->lock, flags); |
| 147 | csr = readl(p->regs + EBDMA_CSR); |
| 148 | csr |= EBDMA_CSR_INT_EN; |
| 149 | writel(csr, p->regs + EBDMA_CSR); |
| 150 | spin_unlock_irqrestore(&p->lock, flags); |
| 151 | } else { |
| 152 | spin_lock_irqsave(&p->lock, flags); |
| 153 | csr = readl(p->regs + EBDMA_CSR); |
| 154 | csr &= ~EBDMA_CSR_INT_EN; |
| 155 | writel(csr, p->regs + EBDMA_CSR); |
| 156 | spin_unlock_irqrestore(&p->lock, flags); |
| 157 | |
| 158 | if (p->flags & EBUS_DMA_FLAG_USE_EBDMA_HANDLER) { |
| 159 | free_irq(p->irq, p); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | EXPORT_SYMBOL(ebus_dma_irq_enable); |
| 166 | |
| 167 | void ebus_dma_unregister(struct ebus_dma_info *p) |
| 168 | { |
| 169 | unsigned long flags; |
| 170 | u32 csr; |
| 171 | int irq_on = 0; |
| 172 | |
| 173 | spin_lock_irqsave(&p->lock, flags); |
| 174 | csr = readl(p->regs + EBDMA_CSR); |
| 175 | if (csr & EBDMA_CSR_INT_EN) { |
| 176 | csr &= ~EBDMA_CSR_INT_EN; |
| 177 | writel(csr, p->regs + EBDMA_CSR); |
| 178 | irq_on = 1; |
| 179 | } |
| 180 | spin_unlock_irqrestore(&p->lock, flags); |
| 181 | |
| 182 | if (irq_on) |
| 183 | free_irq(p->irq, p); |
| 184 | } |
| 185 | EXPORT_SYMBOL(ebus_dma_unregister); |
| 186 | |
| 187 | int ebus_dma_request(struct ebus_dma_info *p, dma_addr_t bus_addr, size_t len) |
| 188 | { |
| 189 | unsigned long flags; |
| 190 | u32 csr; |
| 191 | int err; |
| 192 | |
| 193 | if (len >= (1 << 24)) |
| 194 | return -EINVAL; |
| 195 | |
| 196 | spin_lock_irqsave(&p->lock, flags); |
| 197 | csr = readl(p->regs + EBDMA_CSR); |
| 198 | err = -EINVAL; |
| 199 | if (!(csr & EBDMA_CSR_EN_DMA)) |
| 200 | goto out; |
| 201 | err = -EBUSY; |
| 202 | if (csr & EBDMA_CSR_NA_LOADED) |
| 203 | goto out; |
| 204 | |
| 205 | writel(len, p->regs + EBDMA_COUNT); |
| 206 | writel(bus_addr, p->regs + EBDMA_ADDR); |
| 207 | err = 0; |
| 208 | |
| 209 | out: |
| 210 | spin_unlock_irqrestore(&p->lock, flags); |
| 211 | |
| 212 | return err; |
| 213 | } |
| 214 | EXPORT_SYMBOL(ebus_dma_request); |
| 215 | |
| 216 | void ebus_dma_prepare(struct ebus_dma_info *p, int write) |
| 217 | { |
| 218 | unsigned long flags; |
| 219 | u32 csr; |
| 220 | |
| 221 | spin_lock_irqsave(&p->lock, flags); |
| 222 | __ebus_dma_reset(p, 0); |
| 223 | |
| 224 | csr = (EBDMA_CSR_INT_EN | |
| 225 | EBDMA_CSR_EN_CNT | |
| 226 | EBDMA_CSR_BURST_SZ_16 | |
| 227 | EBDMA_CSR_EN_NEXT); |
| 228 | |
| 229 | if (write) |
| 230 | csr |= EBDMA_CSR_WRITE; |
| 231 | if (p->flags & EBUS_DMA_FLAG_TCI_DISABLE) |
| 232 | csr |= EBDMA_CSR_TCI_DIS; |
| 233 | |
| 234 | writel(csr, p->regs + EBDMA_CSR); |
| 235 | |
| 236 | spin_unlock_irqrestore(&p->lock, flags); |
| 237 | } |
| 238 | EXPORT_SYMBOL(ebus_dma_prepare); |
| 239 | |
| 240 | unsigned int ebus_dma_residue(struct ebus_dma_info *p) |
| 241 | { |
| 242 | return readl(p->regs + EBDMA_COUNT); |
| 243 | } |
| 244 | EXPORT_SYMBOL(ebus_dma_residue); |
| 245 | |
| 246 | unsigned int ebus_dma_addr(struct ebus_dma_info *p) |
| 247 | { |
| 248 | return readl(p->regs + EBDMA_ADDR); |
| 249 | } |
| 250 | EXPORT_SYMBOL(ebus_dma_addr); |
| 251 | |
| 252 | void ebus_dma_enable(struct ebus_dma_info *p, int on) |
| 253 | { |
| 254 | unsigned long flags; |
| 255 | u32 orig_csr, csr; |
| 256 | |
| 257 | spin_lock_irqsave(&p->lock, flags); |
| 258 | orig_csr = csr = readl(p->regs + EBDMA_CSR); |
| 259 | if (on) |
| 260 | csr |= EBDMA_CSR_EN_DMA; |
| 261 | else |
| 262 | csr &= ~EBDMA_CSR_EN_DMA; |
| 263 | if ((orig_csr & EBDMA_CSR_EN_DMA) != |
| 264 | (csr & EBDMA_CSR_EN_DMA)) |
| 265 | writel(csr, p->regs + EBDMA_CSR); |
| 266 | spin_unlock_irqrestore(&p->lock, flags); |
| 267 | } |
| 268 | EXPORT_SYMBOL(ebus_dma_enable); |
| 269 | |
| 270 | struct linux_ebus *ebus_chain = NULL; |
| 271 | |
| 272 | #ifdef CONFIG_SUN_AUXIO |
| 273 | extern void auxio_probe(void); |
| 274 | #endif |
| 275 | |
| 276 | static inline void *ebus_alloc(size_t size) |
| 277 | { |
| 278 | void *mem; |
| 279 | |
Eric Sesterhenn | 9132983 | 2006-03-06 13:48:40 -0800 | [diff] [blame] | 280 | mem = kzalloc(size, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | if (!mem) |
| 282 | panic("ebus_alloc: out of memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | return mem; |
| 284 | } |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | int __init ebus_intmap_match(struct linux_ebus *ebus, |
| 287 | struct linux_prom_registers *reg, |
| 288 | int *interrupt) |
| 289 | { |
David S. Miller | 9c10a58 | 2006-06-22 19:31:11 -0700 | [diff] [blame] | 290 | struct linux_prom_ebus_intmap *imap; |
| 291 | struct linux_prom_ebus_intmask *imask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | unsigned int hi, lo, irq; |
David S. Miller | 9c10a58 | 2006-06-22 19:31:11 -0700 | [diff] [blame] | 293 | int i, len, n_imap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
David S. Miller | 9c10a58 | 2006-06-22 19:31:11 -0700 | [diff] [blame] | 295 | imap = of_get_property(ebus->prom_node, "interrupt-map", &len); |
| 296 | if (!imap) |
| 297 | return 0; |
| 298 | n_imap = len / sizeof(imap[0]); |
| 299 | |
| 300 | imask = of_get_property(ebus->prom_node, "interrupt-map-mask", NULL); |
| 301 | if (!imask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | |
David S. Miller | 9c10a58 | 2006-06-22 19:31:11 -0700 | [diff] [blame] | 304 | hi = reg->which_io & imask->phys_hi; |
| 305 | lo = reg->phys_addr & imask->phys_lo; |
| 306 | irq = *interrupt & imask->interrupt; |
| 307 | for (i = 0; i < n_imap; i++) { |
| 308 | if ((imap[i].phys_hi == hi) && |
| 309 | (imap[i].phys_lo == lo) && |
| 310 | (imap[i].interrupt == irq)) { |
| 311 | *interrupt = imap[i].cinterrupt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | } |
| 315 | return -1; |
| 316 | } |
| 317 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 318 | void __init fill_ebus_child(struct device_node *dp, |
| 319 | struct linux_prom_registers *preg, |
| 320 | struct linux_ebus_child *dev, |
| 321 | int non_standard_regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 323 | int *regs; |
| 324 | int *irqs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | int i, len; |
| 326 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 327 | dev->prom_node = dp; |
| 328 | printk(" (%s)", dp->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 330 | regs = of_get_property(dp, "reg", &len); |
| 331 | if (!regs) |
| 332 | dev->num_addrs = 0; |
| 333 | else |
| 334 | dev->num_addrs = len / sizeof(regs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | if (non_standard_regs) { |
| 337 | /* This is to handle reg properties which are not |
| 338 | * in the parent relative format. One example are |
| 339 | * children of the i2c device on CompactPCI systems. |
| 340 | * |
| 341 | * So, for such devices we just record the property |
| 342 | * raw in the child resources. |
| 343 | */ |
| 344 | for (i = 0; i < dev->num_addrs; i++) |
| 345 | dev->resource[i].start = regs[i]; |
| 346 | } else { |
| 347 | for (i = 0; i < dev->num_addrs; i++) { |
| 348 | int rnum = regs[i]; |
| 349 | if (rnum >= dev->parent->num_addrs) { |
| 350 | prom_printf("UGH: property for %s was %d, need < %d\n", |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 351 | dp->name, len, dev->parent->num_addrs); |
| 352 | prom_halt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | dev->resource[i].start = dev->parent->resource[i].start; |
| 355 | dev->resource[i].end = dev->parent->resource[i].end; |
| 356 | dev->resource[i].flags = IORESOURCE_MEM; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 357 | dev->resource[i].name = dp->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
| 361 | for (i = 0; i < PROMINTR_MAX; i++) |
| 362 | dev->irqs[i] = PCI_IRQ_NONE; |
| 363 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 364 | irqs = of_get_property(dp, "interrupts", &len); |
| 365 | if (!irqs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | dev->num_irqs = 0; |
| 367 | /* |
| 368 | * Oh, well, some PROMs don't export interrupts |
| 369 | * property to children of EBus devices... |
| 370 | * |
| 371 | * Be smart about PS/2 keyboard and mouse. |
| 372 | */ |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 373 | if (!strcmp(dev->parent->prom_node->name, "8042")) { |
| 374 | if (!strcmp(dev->prom_node->name, "kb_ps2")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | dev->num_irqs = 1; |
| 376 | dev->irqs[0] = dev->parent->irqs[0]; |
| 377 | } else { |
| 378 | dev->num_irqs = 1; |
| 379 | dev->irqs[0] = dev->parent->irqs[1]; |
| 380 | } |
| 381 | } |
| 382 | } else { |
| 383 | dev->num_irqs = len / sizeof(irqs[0]); |
| 384 | for (i = 0; i < dev->num_irqs; i++) { |
| 385 | struct pci_pbm_info *pbm = dev->bus->parent; |
| 386 | struct pci_controller_info *p = pbm->parent; |
| 387 | |
| 388 | if (ebus_intmap_match(dev->bus, preg, &irqs[i]) != -1) { |
| 389 | dev->irqs[i] = p->irq_build(pbm, |
| 390 | dev->bus->self, |
| 391 | irqs[i]); |
| 392 | } else { |
| 393 | /* If we get a bogus interrupt property, just |
| 394 | * record the raw value instead of punting. |
| 395 | */ |
| 396 | dev->irqs[i] = irqs[i]; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | static int __init child_regs_nonstandard(struct linux_ebus_device *dev) |
| 403 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 404 | if (!strcmp(dev->prom_node->name, "i2c") || |
| 405 | !strcmp(dev->prom_node->name, "SUNW,lombus")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | return 1; |
| 407 | return 0; |
| 408 | } |
| 409 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 410 | void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 412 | struct linux_prom_registers *regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | struct linux_ebus_child *child; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 414 | int *irqs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | int i, n, len; |
| 416 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 417 | dev->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 419 | printk(" [%s", dp->name); |
| 420 | |
| 421 | regs = of_get_property(dp, "reg", &len); |
| 422 | if (!regs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | dev->num_addrs = 0; |
| 424 | goto probe_interrupts; |
| 425 | } |
| 426 | |
| 427 | if (len % sizeof(struct linux_prom_registers)) { |
| 428 | prom_printf("UGH: proplen for %s was %d, need multiple of %d\n", |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 429 | dev->prom_node->name, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | (int)sizeof(struct linux_prom_registers)); |
| 431 | prom_halt(); |
| 432 | } |
| 433 | dev->num_addrs = len / sizeof(struct linux_prom_registers); |
| 434 | |
| 435 | for (i = 0; i < dev->num_addrs; i++) { |
| 436 | /* XXX Learn how to interpret ebus ranges... -DaveM */ |
| 437 | if (regs[i].which_io >= 0x10) |
| 438 | n = (regs[i].which_io - 0x10) >> 2; |
| 439 | else |
| 440 | n = regs[i].which_io; |
| 441 | |
| 442 | dev->resource[i].start = dev->bus->self->resource[n].start; |
| 443 | dev->resource[i].start += (unsigned long)regs[i].phys_addr; |
| 444 | dev->resource[i].end = |
| 445 | (dev->resource[i].start + (unsigned long)regs[i].reg_size - 1UL); |
| 446 | dev->resource[i].flags = IORESOURCE_MEM; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 447 | dev->resource[i].name = dev->prom_node->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | request_resource(&dev->bus->self->resource[n], |
| 449 | &dev->resource[i]); |
| 450 | } |
| 451 | |
| 452 | probe_interrupts: |
| 453 | for (i = 0; i < PROMINTR_MAX; i++) |
| 454 | dev->irqs[i] = PCI_IRQ_NONE; |
| 455 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 456 | irqs = of_get_property(dp, "interrupts", &len); |
| 457 | if (!irqs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | dev->num_irqs = 0; |
| 459 | } else { |
| 460 | dev->num_irqs = len / sizeof(irqs[0]); |
| 461 | for (i = 0; i < dev->num_irqs; i++) { |
| 462 | struct pci_pbm_info *pbm = dev->bus->parent; |
| 463 | struct pci_controller_info *p = pbm->parent; |
| 464 | |
| 465 | if (ebus_intmap_match(dev->bus, ®s[0], &irqs[i]) != -1) { |
| 466 | dev->irqs[i] = p->irq_build(pbm, |
| 467 | dev->bus->self, |
| 468 | irqs[i]); |
| 469 | } else { |
| 470 | /* If we get a bogus interrupt property, just |
| 471 | * record the raw value instead of punting. |
| 472 | */ |
| 473 | dev->irqs[i] = irqs[i]; |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame^] | 478 | dev->ofdev.node = dp; |
| 479 | dev->ofdev.dev.parent = &dev->bus->ofdev.dev; |
| 480 | dev->ofdev.dev.bus = &ebus_bus_type; |
| 481 | strcpy(dev->ofdev.dev.bus_id, dp->path_component_name); |
| 482 | |
| 483 | /* Register with core */ |
| 484 | if (of_device_register(&dev->ofdev) != 0) |
| 485 | printk(KERN_DEBUG "ebus: device registration error for %s!\n", |
| 486 | dev->ofdev.dev.bus_id); |
| 487 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 488 | dp = dp->child; |
| 489 | if (dp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | printk(" ->"); |
| 491 | dev->children = ebus_alloc(sizeof(struct linux_ebus_child)); |
| 492 | |
| 493 | child = dev->children; |
| 494 | child->next = NULL; |
| 495 | child->parent = dev; |
| 496 | child->bus = dev->bus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 497 | fill_ebus_child(dp, regs, child, |
| 498 | child_regs_nonstandard(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 500 | while ((dp = dp->sibling) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | child->next = ebus_alloc(sizeof(struct linux_ebus_child)); |
| 502 | |
| 503 | child = child->next; |
| 504 | child->next = NULL; |
| 505 | child->parent = dev; |
| 506 | child->bus = dev->bus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 507 | fill_ebus_child(dp, regs, child, |
| 508 | child_regs_nonstandard(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | printk("]"); |
| 512 | } |
| 513 | |
| 514 | static struct pci_dev *find_next_ebus(struct pci_dev *start, int *is_rio_p) |
| 515 | { |
| 516 | struct pci_dev *pdev = start; |
| 517 | |
Jiri Slaby | d08fa1a | 2005-11-06 23:39:35 -0800 | [diff] [blame] | 518 | while ((pdev = pci_get_device(PCI_VENDOR_ID_SUN, PCI_ANY_ID, pdev))) |
| 519 | if (pdev->device == PCI_DEVICE_ID_SUN_EBUS || |
| 520 | pdev->device == PCI_DEVICE_ID_SUN_RIO_EBUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Jiri Slaby | d08fa1a | 2005-11-06 23:39:35 -0800 | [diff] [blame] | 523 | *is_rio_p = !!(pdev && (pdev->device == PCI_DEVICE_ID_SUN_RIO_EBUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | return pdev; |
| 526 | } |
| 527 | |
| 528 | void __init ebus_init(void) |
| 529 | { |
| 530 | struct pci_pbm_info *pbm; |
| 531 | struct linux_ebus_device *dev; |
| 532 | struct linux_ebus *ebus; |
| 533 | struct pci_dev *pdev; |
| 534 | struct pcidev_cookie *cookie; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 535 | struct device_node *dp; |
| 536 | int is_rio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | int num_ebus = 0; |
| 538 | |
| 539 | pdev = find_next_ebus(NULL, &is_rio); |
| 540 | if (!pdev) { |
| 541 | printk("ebus: No EBus's found.\n"); |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | cookie = pdev->sysdata; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 546 | dp = cookie->prom_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | ebus_chain = ebus = ebus_alloc(sizeof(struct linux_ebus)); |
| 549 | ebus->next = NULL; |
| 550 | ebus->is_rio = is_rio; |
| 551 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 552 | while (dp) { |
| 553 | struct device_node *child; |
| 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | /* SUNW,pci-qfe uses four empty ebuses on it. |
| 556 | I think we should not consider them here, |
| 557 | as they have half of the properties this |
| 558 | code expects and once we do PCI hot-plug, |
| 559 | we'd have to tweak with the ebus_chain |
| 560 | in the runtime after initialization. -jj */ |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 561 | if (!dp->child) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | pdev = find_next_ebus(pdev, &is_rio); |
| 563 | if (!pdev) { |
| 564 | if (ebus == ebus_chain) { |
| 565 | ebus_chain = NULL; |
| 566 | printk("ebus: No EBus's found.\n"); |
| 567 | return; |
| 568 | } |
| 569 | break; |
| 570 | } |
| 571 | ebus->is_rio = is_rio; |
| 572 | cookie = pdev->sysdata; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 573 | dp = cookie->prom_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | continue; |
| 575 | } |
| 576 | printk("ebus%d:", num_ebus); |
| 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | ebus->index = num_ebus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 579 | ebus->prom_node = dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | ebus->self = pdev; |
| 581 | ebus->parent = pbm = cookie->pbm; |
| 582 | |
David S. Miller | a2bd4fd | 2006-06-23 01:44:10 -0700 | [diff] [blame^] | 583 | ebus->ofdev.node = dp; |
| 584 | ebus->ofdev.dev.parent = &pdev->dev; |
| 585 | ebus->ofdev.dev.bus = &ebus_bus_type; |
| 586 | strcpy(ebus->ofdev.dev.bus_id, dp->path_component_name); |
| 587 | |
| 588 | /* Register with core */ |
| 589 | if (of_device_register(&ebus->ofdev) != 0) |
| 590 | printk(KERN_DEBUG "ebus: device registration error for %s!\n", |
| 591 | ebus->ofdev.dev.bus_id); |
| 592 | |
| 593 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 594 | child = dp->child; |
| 595 | if (!child) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | goto next_ebus; |
| 597 | |
| 598 | ebus->devices = ebus_alloc(sizeof(struct linux_ebus_device)); |
| 599 | |
| 600 | dev = ebus->devices; |
| 601 | dev->next = NULL; |
| 602 | dev->children = NULL; |
| 603 | dev->bus = ebus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 604 | fill_ebus_device(child, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 606 | while ((child = child->sibling) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | dev->next = ebus_alloc(sizeof(struct linux_ebus_device)); |
| 608 | |
| 609 | dev = dev->next; |
| 610 | dev->next = NULL; |
| 611 | dev->children = NULL; |
| 612 | dev->bus = ebus; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 613 | fill_ebus_device(child, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | next_ebus: |
| 617 | printk("\n"); |
| 618 | |
| 619 | pdev = find_next_ebus(pdev, &is_rio); |
| 620 | if (!pdev) |
| 621 | break; |
| 622 | |
| 623 | cookie = pdev->sysdata; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 624 | dp = cookie->prom_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | ebus->next = ebus_alloc(sizeof(struct linux_ebus)); |
| 627 | ebus = ebus->next; |
| 628 | ebus->next = NULL; |
| 629 | ebus->is_rio = is_rio; |
| 630 | ++num_ebus; |
| 631 | } |
Jiri Slaby | d08fa1a | 2005-11-06 23:39:35 -0800 | [diff] [blame] | 632 | pci_dev_put(pdev); /* XXX for the case, when ebusnd is 0, is it OK? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | #ifdef CONFIG_SUN_AUXIO |
| 635 | auxio_probe(); |
| 636 | #endif |
| 637 | } |