Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | /* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org) * Copyright (C) 1999, 2000 Silicon Graphics, Inc. */ #include <linux/init.h> #include <linux/kernel.h> #include <linux/pci.h> #include <asm/sn/arch.h> #include <asm/pci/bridge.h> #include <asm/paccess.h> #include <asm/sn/sn0/ip27.h> #include <asm/sn/sn0/hub.h> /* * Max #PCI busses we can handle; ie, max #PCI bridges. */ #define MAX_PCI_BUSSES 20 /* * Max #PCI devices (like scsi controllers) we handle on a bus. */ #define MAX_DEVICES_PER_PCIBUS 8 /* * No locking needed until PCI initialization is done parallely. */ int irqstore[MAX_PCI_BUSSES][MAX_DEVICES_PER_PCIBUS]; int lastirq = BASE_PCI_IRQ; /* * Translate from irq to software PCI bus number and PCI slot. */ int irq_to_bus[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS]; int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS]; /* * The Bridge ASIC supports both type 0 and type 1 access. Type 1 is * not really documented, so right now I can't write code which uses it. * Therefore we use type 0 accesses for now even though they won't work * correcly for PCI-to-PCI bridges. */ #define CF0_READ_PCI_CFG(dev,where,value,bm,mask) \ do { \ bridge_t *bridge; \ int slot = PCI_SLOT(dev->devfn); \ int fn = PCI_FUNC(dev->devfn); \ volatile u32 *addr; \ u32 cf, __bit; \ unsigned int bus_id = (unsigned) dev->bus->number; \ \ bridge = (bridge_t *) NODE_SWIN_BASE(bus_to_nid[bus_id], \ bus_to_wid[bus_id]); \ \ /*if (dev->bus->number) */ \ /* return PCIBIOS_DEVICE_NOT_FOUND; */ \ \ __bit = (((where) & (bm)) << 3); \ addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2]; \ if (get_dbe(cf, addr)) \ return PCIBIOS_DEVICE_NOT_FOUND; \ *value = (cf >> __bit) & (mask); \ return PCIBIOS_SUCCESSFUL; \ } while (0) static int pci_conf0_read_config_byte(struct pci_dev *dev, int where, u8 *value) { CF0_READ_PCI_CFG(dev,where,value,3,0xff); } static int pci_conf0_read_config_word(struct pci_dev *dev, int where, u16 *value) { CF0_READ_PCI_CFG(dev,where,value,2,0xffff); } static int pci_conf0_read_config_dword(struct pci_dev *dev, int where, u32 *value) { CF0_READ_PCI_CFG(dev,where,value,0,0xffffffff); } #define CF0_WRITE_PCI_CFG(dev,where,value,bm,mask) \ do { \ bridge_t *bridge; \ int slot = PCI_SLOT(dev->devfn); \ int fn = PCI_FUNC(dev->devfn); \ volatile u32 *addr; \ u32 cf, __bit; \ unsigned int bus_id = (unsigned) dev->bus->number; \ \ bridge = (bridge_t *) NODE_SWIN_BASE(bus_to_nid[bus_id], \ bus_to_wid[bus_id]); \ \ /* if (dev->bus->number) */ \ /* return PCIBIOS_DEVICE_NOT_FOUND; */ \ \ if (dev->vendor == PCI_VENDOR_ID_SGI \ && dev->device == PCI_DEVICE_ID_SGI_IOC3) \ return PCIBIOS_SUCCESSFUL; \ \ __bit = (((where) & (bm)) << 3); \ addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2]; \ if (get_dbe(cf, addr)) \ return PCIBIOS_DEVICE_NOT_FOUND; \ cf &= (~mask); \ cf |= (value); \ put_dbe(cf, addr); \ return PCIBIOS_SUCCESSFUL; \ } while (0) static int pci_conf0_write_config_byte(struct pci_dev *dev, int where, u8 value) { CF0_WRITE_PCI_CFG(dev,where,value,3,0xff); } static int pci_conf0_write_config_word(struct pci_dev *dev, int where, u16 value) { CF0_WRITE_PCI_CFG(dev,where,value,2,0xffff); } static int pci_conf0_write_config_dword(struct pci_dev *dev, int where, u32 value) { CF0_WRITE_PCI_CFG(dev,where,value,0,0xffffffff); } static struct pci_ops bridge_pci_ops = { pci_conf0_read_config_byte, pci_conf0_read_config_word, pci_conf0_read_config_dword, pci_conf0_write_config_byte, pci_conf0_write_config_word, pci_conf0_write_config_dword }; void __init pcibios_init(void) { struct pci_ops *ops = &bridge_pci_ops; int i; ioport_resource.end = ~0UL; for (i=0; i<num_bridges; i++) { printk("PCI: Probing PCI hardware on host bus %2d.\n", i); pci_scan_bus(i, ops, NULL); } } static inline u8 bridge_swizzle(u8 pin, u8 slot) { return (((pin-1) + slot) % 4) + 1; } static u8 __init pci_swizzle(struct pci_dev *dev, u8 *pinp) { u8 pin = *pinp; while (dev->bus->self) { /* Move up the chain of bridges. */ pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn)); dev = dev->bus->self; } *pinp = pin; return PCI_SLOT(dev->devfn); } /* * All observed requests have pin == 1. We could have a global here, that * gets incremented and returned every time - unfortunately, pci_map_irq * may be called on the same device over and over, and need to return the * same value. On o2000, pin can be 0 or 1, and PCI slots can be [0..7]. * * A given PCI device, in general, should be able to intr any of the cpus * on any one of the hubs connected to its xbow. */ static int __init pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin) { if ((dev->bus->number >= MAX_PCI_BUSSES) || (pin != 1) || \ (slot >= MAX_DEVICES_PER_PCIBUS)) { printk("Increase supported PCI busses %d,%d,%d\n", \ dev->bus->number, slot, pin); while(1); } /* * Already assigned? Then return previously assigned value ... */ if (irqstore[dev->bus->number][slot]) return(irqstore[dev->bus->number][slot]); else { irq_to_bus[lastirq] = dev->bus->number; irq_to_slot[lastirq] = slot; irqstore[dev->bus->number][slot] = lastirq; lastirq++; return (lastirq - 1); } } void __init pcibios_update_irq(struct pci_dev *dev, int irq) { pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); } void __init pcibios_update_resource(struct pci_dev *dev, struct resource *root, struct resource *res, int resource) { unsigned long where, size; u32 reg; where = PCI_BASE_ADDRESS_0 + (resource * 4); size = res->end - res->start; pci_read_config_dword(dev, where, ®); reg = (reg & size) | (((u32)(res->start - root->start)) & ~size); pci_write_config_dword(dev, where, reg); } void __init pcibios_fixup_bus(struct pci_bus *b) { pci_fixup_irqs(pci_swizzle, pci_map_irq); } void __init pcibios_fixup_pbus_ranges(struct pci_bus * bus, struct pbus_set_ranges_data * ranges) { ranges->io_start -= bus->resource[0]->start; ranges->io_end -= bus->resource[0]->start; ranges->mem_start -= bus->resource[1]->start; ranges->mem_end -= bus->resource[1]->start; } int __init pcibios_enable_device(struct pci_dev *dev) { /* Not needed, since we enable all devices at startup. */ return 0; } void __init pcibios_align_resource(void *data, struct resource *res, unsigned long size) { } char * __init pcibios_setup(char *str) { /* Nothing to do for now. */ return str; } static void __init pci_disable_swapping(struct pci_dev *dev) { unsigned int bus_id = (unsigned) dev->bus->number; bridge_t *bridge = (bridge_t *) NODE_SWIN_BASE(bus_to_nid[bus_id], bus_to_wid[bus_id]); int slot = PCI_SLOT(dev->devfn); bridgereg_t devreg; devreg = bridge->b_device[slot].reg; devreg &= ~BRIDGE_DEV_SWAP_DIR; /* turn off byte swapping */ bridge->b_device[slot].reg = devreg; bridge->b_widget.w_tflush; /* Flush */ } static void __init pci_enable_swapping(struct pci_dev *dev) { unsigned int bus_id = (unsigned) dev->bus->number; bridge_t *bridge = (bridge_t *) NODE_SWIN_BASE(bus_to_nid[bus_id], bus_to_wid[bus_id]); int slot = PCI_SLOT(dev->devfn); bridgereg_t devreg; devreg = bridge->b_device[slot].reg; devreg |= BRIDGE_DEV_SWAP_DIR; /* turn on byte swapping */ bridge->b_device[slot].reg = devreg; bridge->b_widget.w_tflush; /* Flush */ } static void __init pci_fixup_ioc3(struct pci_dev *d) { unsigned int bus_id = (unsigned) d->bus->number; int i; /* IOC3 only decodes 0x20 bytes of the config space, so we end up with tons of bogus information in the pci_dev. On Origins the INTA, INTB and INTC pins are all wired together as if it'd only use INTA. */ printk("PCI: Fixing base addresses for IOC3 device %s\n", d->slot_name); d->resource[0].start |= NODE_OFFSET(bus_to_nid[bus_id]); d->resource[0].end |= NODE_OFFSET(bus_to_nid[bus_id]); for (i = 1; i <= PCI_ROM_RESOURCE; i++) { d->resource[i].start = 0UL; d->resource[i].end = 0UL; d->resource[i].flags = 0UL; } pci_disable_swapping(d); /* * The serial driver will try to probe for serial ports * later on. MENET boards dbe out unrecoverably on sio space * access to the 4th ioc3. (The first 3 iocs work okay, they * have kbd/ms ports; all have ethernet ports). Catch this * case now and disable the serial driver from looking at * these ioc3s. Identify MENET cards by seeing if an ioc3 is * at slot 3. */ d->subsystem_vendor = 0xFF00; if (PCI_SLOT(d->devfn) == 3) { struct list_head *p; list_for_each(p, &d->bus->devices) { list_entry(p, struct pci_dev, bus_list)->subsystem_vendor = 0; } } } static void __init pci_fixup_isp1020(struct pci_dev *d) { unsigned short command; d->resource[0].start |= ((unsigned long)(bus_to_nid[d->bus->number])<<32); printk("PCI: Fixing isp1020 in [bus:slot.fn] %s\n", d->slot_name); /* Configure device to allow bus mastering, i/o and memory mapping. * Older qlogicisp driver expects to have the IO space enable * bit set. Things stop working if we program the controllers as not * having PCI_COMMAND_MEMORY, so we have to fudge the mem_flags. */ pci_set_master(d); pci_read_config_word(d, PCI_COMMAND, &command); command |= PCI_COMMAND_MEMORY; command |= PCI_COMMAND_IO; pci_write_config_word(d, PCI_COMMAND, command); d->resource[1].flags |= 1; pci_enable_swapping(d); } static void __init pci_fixup_isp2x00(struct pci_dev *d) { unsigned int bus_id = (unsigned) d->bus->number; bridge_t *bridge = (bridge_t *) NODE_SWIN_BASE(bus_to_nid[bus_id], bus_to_wid[bus_id]); bridgereg_t devreg; int i; int slot = PCI_SLOT(d->devfn); unsigned int start; unsigned short command; printk("PCI: Fixing isp2x00 in [bus:slot.fn] %s\n", d->slot_name); /* set the resource struct for this device */ start = (u32) (u64)bridge; /* yes, we want to lose the upper 32 bits here */ start |= BRIDGE_DEVIO(slot); d->resource[0].start = start; d->resource[0].end = d->resource[0].start + 0xff; d->resource[0].flags = IORESOURCE_IO; d->resource[1].start = start; d->resource[1].end = d->resource[0].start + 0xfff; d->resource[1].flags = IORESOURCE_MEM; /* * set the bridge device(x) reg for this device */ devreg = bridge->b_device[slot].reg; /* point device(x) to it appropriate small window */ devreg &= ~BRIDGE_DEV_OFF_MASK; devreg |= (start >> 20) & BRIDGE_DEV_OFF_MASK; bridge->b_device[slot].reg = devreg; pci_enable_swapping(d); /* set card's base addr reg */ //pci_conf0_write_config_dword(d, PCI_BASE_ADDRESS_0, 0x500001); //pci_conf0_write_config_dword(d, PCI_BASE_ADDRESS_1, 0x8b00000); //pci_conf0_write_config_dword(d, PCI_ROM_ADDRESS, 0x8b20000); /* I got these from booting irix on system...*/ pci_conf0_write_config_dword(d, PCI_BASE_ADDRESS_0, 0x200001); //pci_conf0_write_config_dword(d, PCI_BASE_ADDRESS_1, 0xf800000); pci_conf0_write_config_dword(d, PCI_ROM_ADDRESS, 0x10200000); pci_conf0_write_config_dword(d, PCI_BASE_ADDRESS_1, start); //pci_conf0_write_config_dword(d, PCI_ROM_ADDRESS, (start | 0x20000)); /* set cache line size */ pci_conf0_write_config_dword(d, PCI_CACHE_LINE_SIZE, 0xf080); /* set pci bus timeout */ bridge->b_bus_timeout |= BRIDGE_BUS_PCI_RETRY_HLD(0x3); bridge->b_wid_tflush; printk("PCI: bridge bus timeout= 0x%x \n", bridge->b_bus_timeout); /* set host error field */ bridge->b_int_host_err = 0x44; bridge->b_wid_tflush; bridge->b_wid_tflush; /* wait until Bridge PIO complete */ for (i=0; i<8; i++) printk("PCI: device(%d)= 0x%x\n",i,bridge->b_device[i].reg); /* configure device to allow bus mastering, i/o and memory mapping */ pci_set_master(d); pci_read_config_word(d, PCI_COMMAND, &command); command |= PCI_COMMAND_MEMORY; command |= PCI_COMMAND_IO; pci_write_config_word(d, PCI_COMMAND, command); /*d->resource[1].flags |= 1;*/ } struct pci_fixup pcibios_fixups[] = { { PCI_FIXUP_HEADER, PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, pci_fixup_ioc3 }, { PCI_FIXUP_HEADER, PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020, pci_fixup_isp1020 }, { PCI_FIXUP_HEADER, PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100, pci_fixup_isp2x00 }, { PCI_FIXUP_HEADER, PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200, pci_fixup_isp2x00 }, { 0 } }; |