pcibr_provider.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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) 2001-2004 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <linux/interrupt.h>
  9. #include <linux/types.h>
  10. #include <linux/pci.h>
  11. #include <asm/sn/addrs.h>
  12. #include <asm/sn/geo.h>
  13. #include <asm/sn/pcibr_provider.h>
  14. #include <asm/sn/pcibus_provider_defs.h>
  15. #include <asm/sn/pcidev.h>
  16. #include <asm/sn/sn_sal.h>
  17. #include <asm/sn/sn2/sn_hwperf.h>
  18. #include "xtalk/xwidgetdev.h"
  19. #include "xtalk/hubdev.h"
  20. int
  21. sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp)
  22. {
  23. struct ia64_sal_retval ret_stuff;
  24. u64 busnum;
  25. u64 segment;
  26. ret_stuff.status = 0;
  27. ret_stuff.v0 = 0;
  28. segment = soft->pbi_buscommon.bs_persist_segment;
  29. busnum = soft->pbi_buscommon.bs_persist_busnum;
  30. SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_ENABLE, segment,
  31. busnum, (u64) device, (u64) resp, 0, 0, 0);
  32. return (int)ret_stuff.v0;
  33. }
  34. int
  35. sal_pcibr_slot_disable(struct pcibus_info *soft, int device, int action,
  36. void *resp)
  37. {
  38. struct ia64_sal_retval ret_stuff;
  39. u64 busnum;
  40. u64 segment;
  41. ret_stuff.status = 0;
  42. ret_stuff.v0 = 0;
  43. segment = soft->pbi_buscommon.bs_persist_segment;
  44. busnum = soft->pbi_buscommon.bs_persist_busnum;
  45. SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_DISABLE,
  46. segment, busnum, (u64) device, (u64) action,
  47. (u64) resp, 0, 0);
  48. return (int)ret_stuff.v0;
  49. }
  50. static int sal_pcibr_error_interrupt(struct pcibus_info *soft)
  51. {
  52. struct ia64_sal_retval ret_stuff;
  53. u64 busnum;
  54. int segment;
  55. ret_stuff.status = 0;
  56. ret_stuff.v0 = 0;
  57. segment = soft->pbi_buscommon.bs_persist_segment;
  58. busnum = soft->pbi_buscommon.bs_persist_busnum;
  59. SAL_CALL_NOLOCK(ret_stuff,
  60. (u64) SN_SAL_IOIF_ERROR_INTERRUPT,
  61. (u64) segment, (u64) busnum, 0, 0, 0, 0, 0);
  62. return (int)ret_stuff.v0;
  63. }
  64. u16 sn_ioboard_to_pci_bus(struct pci_bus *pci_bus)
  65. {
  66. s64 rc;
  67. u16 ioboard;
  68. nasid_t nasid = NASID_GET(SN_PCIBUS_BUSSOFT(pci_bus)->bs_base);
  69. rc = ia64_sn_sysctl_ioboard_get(nasid, &ioboard);
  70. if (rc) {
  71. printk(KERN_WARNING "ia64_sn_sysctl_ioboard_get failed: %ld\n",
  72. rc);
  73. return 0;
  74. }
  75. return ioboard;
  76. }
  77. /*
  78. * PCI Bridge Error interrupt handler. Gets invoked whenever a PCI
  79. * bridge sends an error interrupt.
  80. */
  81. static irqreturn_t
  82. pcibr_error_intr_handler(int irq, void *arg)
  83. {
  84. struct pcibus_info *soft = (struct pcibus_info *)arg;
  85. if (sal_pcibr_error_interrupt(soft) < 0) {
  86. panic("pcibr_error_intr_handler(): Fatal Bridge Error");
  87. }
  88. return IRQ_HANDLED;
  89. }
  90. void *
  91. pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
  92. {
  93. int nasid, cnode, j;
  94. cnodeid_t near_cnode;
  95. struct hubdev_info *hubdev_info;
  96. struct pcibus_info *soft;
  97. struct sn_flush_device_kernel *sn_flush_device_kernel;
  98. struct sn_flush_device_common *common;
  99. if (! IS_PCI_BRIDGE_ASIC(prom_bussoft->bs_asic_type)) {
  100. return NULL;
  101. }
  102. /*
  103. * Allocate kernel bus soft and copy from prom.
  104. */
  105. soft = kmalloc(sizeof(struct pcibus_info), GFP_KERNEL);
  106. if (!soft) {
  107. return NULL;
  108. }
  109. memcpy(soft, prom_bussoft, sizeof(struct pcibus_info));
  110. soft->pbi_buscommon.bs_base =
  111. (((u64) soft->pbi_buscommon.
  112. bs_base << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  113. spin_lock_init(&soft->pbi_lock);
  114. /*
  115. * register the bridge's error interrupt handler
  116. */
  117. if (request_irq(SGI_PCIASIC_ERROR, pcibr_error_intr_handler,
  118. IRQF_SHARED, "PCIBR error", (void *)(soft))) {
  119. printk(KERN_WARNING
  120. "pcibr cannot allocate interrupt for error handler\n");
  121. }
  122. /*
  123. * Update the Bridge with the "kernel" pagesize
  124. */
  125. if (PAGE_SIZE < 16384) {
  126. pcireg_control_bit_clr(soft, PCIBR_CTRL_PAGE_SIZE);
  127. } else {
  128. pcireg_control_bit_set(soft, PCIBR_CTRL_PAGE_SIZE);
  129. }
  130. nasid = NASID_GET(soft->pbi_buscommon.bs_base);
  131. cnode = nasid_to_cnodeid(nasid);
  132. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  133. if (hubdev_info->hdi_flush_nasid_list.widget_p) {
  134. sn_flush_device_kernel = hubdev_info->hdi_flush_nasid_list.
  135. widget_p[(int)soft->pbi_buscommon.bs_xid];
  136. if (sn_flush_device_kernel) {
  137. for (j = 0; j < DEV_PER_WIDGET;
  138. j++, sn_flush_device_kernel++) {
  139. common = sn_flush_device_kernel->common;
  140. if (common->sfdl_slot == -1)
  141. continue;
  142. if ((common->sfdl_persistent_segment ==
  143. soft->pbi_buscommon.bs_persist_segment) &&
  144. (common->sfdl_persistent_busnum ==
  145. soft->pbi_buscommon.bs_persist_busnum))
  146. common->sfdl_pcibus_info =
  147. soft;
  148. }
  149. }
  150. }
  151. /* Setup the PMU ATE map */
  152. soft->pbi_int_ate_resource.lowest_free_index = 0;
  153. soft->pbi_int_ate_resource.ate =
  154. kzalloc(soft->pbi_int_ate_size * sizeof(u64), GFP_KERNEL);
  155. if (!soft->pbi_int_ate_resource.ate) {
  156. kfree(soft);
  157. return NULL;
  158. }
  159. if (prom_bussoft->bs_asic_type == PCIIO_ASIC_TYPE_TIOCP) {
  160. /* TIO PCI Bridge: find nearest node with CPUs */
  161. int e = sn_hwperf_get_nearest_node(cnode, NULL, &near_cnode);
  162. if (e < 0) {
  163. near_cnode = (cnodeid_t)-1; /* use any node */
  164. printk(KERN_WARNING "pcibr_bus_fixup: failed to find "
  165. "near node with CPUs to TIO node %d, err=%d\n",
  166. cnode, e);
  167. }
  168. controller->node = near_cnode;
  169. }
  170. else
  171. controller->node = cnode;
  172. return soft;
  173. }
  174. void pcibr_force_interrupt(struct sn_irq_info *sn_irq_info)
  175. {
  176. struct pcidev_info *pcidev_info;
  177. struct pcibus_info *pcibus_info;
  178. int bit = sn_irq_info->irq_int_bit;
  179. if (! sn_irq_info->irq_bridge)
  180. return;
  181. pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  182. if (pcidev_info) {
  183. pcibus_info =
  184. (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info->
  185. pdi_pcibus_info;
  186. pcireg_force_intr_set(pcibus_info, bit);
  187. }
  188. }
  189. void pcibr_target_interrupt(struct sn_irq_info *sn_irq_info)
  190. {
  191. struct pcidev_info *pcidev_info;
  192. struct pcibus_info *pcibus_info;
  193. int bit = sn_irq_info->irq_int_bit;
  194. u64 xtalk_addr = sn_irq_info->irq_xtalkaddr;
  195. pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  196. if (pcidev_info) {
  197. pcibus_info =
  198. (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info->
  199. pdi_pcibus_info;
  200. /* Disable the device's IRQ */
  201. pcireg_intr_enable_bit_clr(pcibus_info, (1 << bit));
  202. /* Change the device's IRQ */
  203. pcireg_intr_addr_addr_set(pcibus_info, bit, xtalk_addr);
  204. /* Re-enable the device's IRQ */
  205. pcireg_intr_enable_bit_set(pcibus_info, (1 << bit));
  206. pcibr_force_interrupt(sn_irq_info);
  207. }
  208. }
  209. /*
  210. * Provider entries for PIC/CP
  211. */
  212. struct sn_pcibus_provider pcibr_provider = {
  213. .dma_map = pcibr_dma_map,
  214. .dma_map_consistent = pcibr_dma_map_consistent,
  215. .dma_unmap = pcibr_dma_unmap,
  216. .bus_fixup = pcibr_bus_fixup,
  217. .force_interrupt = pcibr_force_interrupt,
  218. .target_interrupt = pcibr_target_interrupt
  219. };
  220. int
  221. pcibr_init_provider(void)
  222. {
  223. sn_pci_provider[PCIIO_ASIC_TYPE_PIC] = &pcibr_provider;
  224. sn_pci_provider[PCIIO_ASIC_TYPE_TIOCP] = &pcibr_provider;
  225. return 0;
  226. }
  227. EXPORT_SYMBOL_GPL(sal_pcibr_slot_enable);
  228. EXPORT_SYMBOL_GPL(sal_pcibr_slot_disable);
  229. EXPORT_SYMBOL_GPL(sn_ioboard_to_pci_bus);