pci-ip27.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2003 Christoph Hellwig (hch@lst.de)
  7. * Copyright (C) 1999, 2000, 04 Ralf Baechle (ralf@linux-mips.org)
  8. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/export.h>
  12. #include <linux/pci.h>
  13. #include <linux/smp.h>
  14. #include <asm/sn/arch.h>
  15. #include <asm/pci/bridge.h>
  16. #include <asm/paccess.h>
  17. #include <asm/sn/intr.h>
  18. #include <asm/sn/sn0/hub.h>
  19. /*
  20. * Max #PCI busses we can handle; ie, max #PCI bridges.
  21. */
  22. #define MAX_PCI_BUSSES 40
  23. /*
  24. * Max #PCI devices (like scsi controllers) we handle on a bus.
  25. */
  26. #define MAX_DEVICES_PER_PCIBUS 8
  27. /*
  28. * XXX: No kmalloc available when we do our crosstalk scan,
  29. * we should try to move it later in the boot process.
  30. */
  31. static struct bridge_controller bridges[MAX_PCI_BUSSES];
  32. /*
  33. * Translate from irq to software PCI bus number and PCI slot.
  34. */
  35. struct bridge_controller *irq_to_bridge[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
  36. int irq_to_slot[MAX_PCI_BUSSES * MAX_DEVICES_PER_PCIBUS];
  37. extern struct pci_ops bridge_pci_ops;
  38. int bridge_probe(nasid_t nasid, int widget_id, int masterwid)
  39. {
  40. unsigned long offset = NODE_OFFSET(nasid);
  41. struct bridge_controller *bc;
  42. static int num_bridges = 0;
  43. bridge_t *bridge;
  44. int slot;
  45. pci_set_flags(PCI_PROBE_ONLY);
  46. printk("a bridge\n");
  47. /* XXX: kludge alert.. */
  48. if (!num_bridges)
  49. ioport_resource.end = ~0UL;
  50. bc = &bridges[num_bridges];
  51. bc->pc.pci_ops = &bridge_pci_ops;
  52. bc->pc.mem_resource = &bc->mem;
  53. bc->pc.io_resource = &bc->io;
  54. bc->pc.index = num_bridges;
  55. bc->mem.name = "Bridge PCI MEM";
  56. bc->pc.mem_offset = offset;
  57. bc->mem.start = 0;
  58. bc->mem.end = ~0UL;
  59. bc->mem.flags = IORESOURCE_MEM;
  60. bc->io.name = "Bridge IO MEM";
  61. bc->pc.io_offset = offset;
  62. bc->io.start = 0UL;
  63. bc->io.end = ~0UL;
  64. bc->io.flags = IORESOURCE_IO;
  65. bc->irq_cpu = smp_processor_id();
  66. bc->widget_id = widget_id;
  67. bc->nasid = nasid;
  68. bc->baddr = (u64)masterwid << 60 | PCI64_ATTR_BAR;
  69. /*
  70. * point to this bridge
  71. */
  72. bridge = (bridge_t *) RAW_NODE_SWIN_BASE(nasid, widget_id);
  73. /*
  74. * Clear all pending interrupts.
  75. */
  76. bridge->b_int_rst_stat = BRIDGE_IRR_ALL_CLR;
  77. /*
  78. * Until otherwise set up, assume all interrupts are from slot 0
  79. */
  80. bridge->b_int_device = 0x0;
  81. /*
  82. * swap pio's to pci mem and io space (big windows)
  83. */
  84. bridge->b_wid_control |= BRIDGE_CTRL_IO_SWAP |
  85. BRIDGE_CTRL_MEM_SWAP;
  86. #ifdef CONFIG_PAGE_SIZE_4KB
  87. bridge->b_wid_control &= ~BRIDGE_CTRL_PAGE_SIZE;
  88. #else /* 16kB or larger */
  89. bridge->b_wid_control |= BRIDGE_CTRL_PAGE_SIZE;
  90. #endif
  91. /*
  92. * Hmm... IRIX sets additional bits in the address which
  93. * are documented as reserved in the bridge docs.
  94. */
  95. bridge->b_wid_int_upper = 0x8000 | (masterwid << 16);
  96. bridge->b_wid_int_lower = 0x01800090; /* PI_INT_PEND_MOD off*/
  97. bridge->b_dir_map = (masterwid << 20); /* DMA */
  98. bridge->b_int_enable = 0;
  99. for (slot = 0; slot < 8; slot ++) {
  100. bridge->b_device[slot].reg |= BRIDGE_DEV_SWAP_DIR;
  101. bc->pci_int[slot] = -1;
  102. }
  103. bridge->b_wid_tflush; /* wait until Bridge PIO complete */
  104. bc->base = bridge;
  105. register_pci_controller(&bc->pc);
  106. num_bridges++;
  107. return 0;
  108. }
  109. /*
  110. * All observed requests have pin == 1. We could have a global here, that
  111. * gets incremented and returned every time - unfortunately, pci_map_irq
  112. * may be called on the same device over and over, and need to return the
  113. * same value. On O2000, pin can be 0 or 1, and PCI slots can be [0..7].
  114. *
  115. * A given PCI device, in general, should be able to intr any of the cpus
  116. * on any one of the hubs connected to its xbow.
  117. */
  118. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  119. {
  120. return 0;
  121. }
  122. static inline struct pci_dev *bridge_root_dev(struct pci_dev *dev)
  123. {
  124. while (dev->bus->parent) {
  125. /* Move up the chain of bridges. */
  126. dev = dev->bus->self;
  127. }
  128. return dev;
  129. }
  130. /* Do platform specific device initialization at pci_enable_device() time */
  131. int pcibios_plat_dev_init(struct pci_dev *dev)
  132. {
  133. struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus);
  134. struct pci_dev *rdev = bridge_root_dev(dev);
  135. int slot = PCI_SLOT(rdev->devfn);
  136. int irq;
  137. irq = bc->pci_int[slot];
  138. if (irq == -1) {
  139. irq = request_bridge_irq(bc);
  140. if (irq < 0)
  141. return irq;
  142. bc->pci_int[slot] = irq;
  143. }
  144. irq_to_bridge[irq] = bc;
  145. irq_to_slot[irq] = slot;
  146. dev->irq = irq;
  147. return 0;
  148. }
  149. /*
  150. * Device might live on a subordinate PCI bus. XXX Walk up the chain of buses
  151. * to find the slot number in sense of the bridge device register.
  152. * XXX This also means multiple devices might rely on conflicting bridge
  153. * settings.
  154. */
  155. static inline void pci_disable_swapping(struct pci_dev *dev)
  156. {
  157. struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus);
  158. bridge_t *bridge = bc->base;
  159. int slot = PCI_SLOT(dev->devfn);
  160. /* Turn off byte swapping */
  161. bridge->b_device[slot].reg &= ~BRIDGE_DEV_SWAP_DIR;
  162. bridge->b_widget.w_tflush; /* Flush */
  163. }
  164. static inline void pci_enable_swapping(struct pci_dev *dev)
  165. {
  166. struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus);
  167. bridge_t *bridge = bc->base;
  168. int slot = PCI_SLOT(dev->devfn);
  169. /* Turn on byte swapping */
  170. bridge->b_device[slot].reg |= BRIDGE_DEV_SWAP_DIR;
  171. bridge->b_widget.w_tflush; /* Flush */
  172. }
  173. static void pci_fixup_ioc3(struct pci_dev *d)
  174. {
  175. pci_disable_swapping(d);
  176. }
  177. #ifdef CONFIG_NUMA
  178. int pcibus_to_node(struct pci_bus *bus)
  179. {
  180. struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
  181. return bc->nasid;
  182. }
  183. EXPORT_SYMBOL(pcibus_to_node);
  184. #endif /* CONFIG_NUMA */
  185. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3,
  186. pci_fixup_ioc3);