pci-ip27.c 5.6 KB

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