pcibr_provider.c 6.5 KB

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