pcibr_provider.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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/types.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/pci.h>
  11. #include <asm/sn/sn_sal.h>
  12. #include "xtalk/xwidgetdev.h"
  13. #include <asm/sn/geo.h>
  14. #include "xtalk/hubdev.h"
  15. #include <asm/sn/pcibus_provider_defs.h>
  16. #include <asm/sn/pcidev.h>
  17. #include "pci/pcibr_provider.h"
  18. #include <asm/sn/addrs.h>
  19. static int sal_pcibr_error_interrupt(struct pcibus_info *soft)
  20. {
  21. struct ia64_sal_retval ret_stuff;
  22. uint64_t busnum;
  23. int segment;
  24. ret_stuff.status = 0;
  25. ret_stuff.v0 = 0;
  26. segment = 0;
  27. busnum = soft->pbi_buscommon.bs_persist_busnum;
  28. SAL_CALL_NOLOCK(ret_stuff,
  29. (u64) SN_SAL_IOIF_ERROR_INTERRUPT,
  30. (u64) segment, (u64) busnum, 0, 0, 0, 0, 0);
  31. return (int)ret_stuff.v0;
  32. }
  33. /*
  34. * PCI Bridge Error interrupt handler. Gets invoked whenever a PCI
  35. * bridge sends an error interrupt.
  36. */
  37. static irqreturn_t
  38. pcibr_error_intr_handler(int irq, void *arg, struct pt_regs *regs)
  39. {
  40. struct pcibus_info *soft = (struct pcibus_info *)arg;
  41. if (sal_pcibr_error_interrupt(soft) < 0) {
  42. panic("pcibr_error_intr_handler(): Fatal Bridge Error");
  43. }
  44. return IRQ_HANDLED;
  45. }
  46. void *
  47. pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft)
  48. {
  49. int nasid, cnode, j;
  50. struct hubdev_info *hubdev_info;
  51. struct pcibus_info *soft;
  52. struct sn_flush_device_list *sn_flush_device_list;
  53. if (! IS_PCI_BRIDGE_ASIC(prom_bussoft->bs_asic_type)) {
  54. return NULL;
  55. }
  56. /*
  57. * Allocate kernel bus soft and copy from prom.
  58. */
  59. soft = kmalloc(sizeof(struct pcibus_info), GFP_KERNEL);
  60. if (!soft) {
  61. return NULL;
  62. }
  63. memcpy(soft, prom_bussoft, sizeof(struct pcibus_info));
  64. soft->pbi_buscommon.bs_base =
  65. (((u64) soft->pbi_buscommon.
  66. bs_base << 4) >> 4) | __IA64_UNCACHED_OFFSET;
  67. spin_lock_init(&soft->pbi_lock);
  68. /*
  69. * register the bridge's error interrupt handler
  70. */
  71. if (request_irq(SGI_PCIBR_ERROR, (void *)pcibr_error_intr_handler,
  72. SA_SHIRQ, "PCIBR error", (void *)(soft))) {
  73. printk(KERN_WARNING
  74. "pcibr cannot allocate interrupt for error handler\n");
  75. }
  76. /*
  77. * Update the Bridge with the "kernel" pagesize
  78. */
  79. if (PAGE_SIZE < 16384) {
  80. pcireg_control_bit_clr(soft, PCIBR_CTRL_PAGE_SIZE);
  81. } else {
  82. pcireg_control_bit_set(soft, PCIBR_CTRL_PAGE_SIZE);
  83. }
  84. nasid = NASID_GET(soft->pbi_buscommon.bs_base);
  85. cnode = nasid_to_cnodeid(nasid);
  86. hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);
  87. if (hubdev_info->hdi_flush_nasid_list.widget_p) {
  88. sn_flush_device_list = hubdev_info->hdi_flush_nasid_list.
  89. widget_p[(int)soft->pbi_buscommon.bs_xid];
  90. if (sn_flush_device_list) {
  91. for (j = 0; j < DEV_PER_WIDGET;
  92. j++, sn_flush_device_list++) {
  93. if (sn_flush_device_list->sfdl_slot == -1)
  94. continue;
  95. if (sn_flush_device_list->
  96. sfdl_persistent_busnum ==
  97. soft->pbi_buscommon.bs_persist_busnum)
  98. sn_flush_device_list->sfdl_pcibus_info =
  99. soft;
  100. }
  101. }
  102. }
  103. /* Setup the PMU ATE map */
  104. soft->pbi_int_ate_resource.lowest_free_index = 0;
  105. soft->pbi_int_ate_resource.ate =
  106. kmalloc(soft->pbi_int_ate_size * sizeof(uint64_t), GFP_KERNEL);
  107. memset(soft->pbi_int_ate_resource.ate, 0,
  108. (soft->pbi_int_ate_size * sizeof(uint64_t)));
  109. return soft;
  110. }
  111. void pcibr_force_interrupt(struct sn_irq_info *sn_irq_info)
  112. {
  113. struct pcidev_info *pcidev_info;
  114. struct pcibus_info *pcibus_info;
  115. int bit = sn_irq_info->irq_int_bit;
  116. pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  117. if (pcidev_info) {
  118. pcibus_info =
  119. (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info->
  120. pdi_pcibus_info;
  121. pcireg_force_intr_set(pcibus_info, bit);
  122. }
  123. }
  124. void pcibr_change_devices_irq(struct sn_irq_info *sn_irq_info)
  125. {
  126. struct pcidev_info *pcidev_info;
  127. struct pcibus_info *pcibus_info;
  128. int bit = sn_irq_info->irq_int_bit;
  129. uint64_t xtalk_addr = sn_irq_info->irq_xtalkaddr;
  130. pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  131. if (pcidev_info) {
  132. pcibus_info =
  133. (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info->
  134. pdi_pcibus_info;
  135. /* Disable the device's IRQ */
  136. pcireg_intr_enable_bit_clr(pcibus_info, bit);
  137. /* Change the device's IRQ */
  138. pcireg_intr_addr_addr_set(pcibus_info, bit, xtalk_addr);
  139. /* Re-enable the device's IRQ */
  140. pcireg_intr_enable_bit_set(pcibus_info, bit);
  141. pcibr_force_interrupt(sn_irq_info);
  142. }
  143. }
  144. /*
  145. * Provider entries for PIC/CP
  146. */
  147. struct sn_pcibus_provider pcibr_provider = {
  148. .dma_map = pcibr_dma_map,
  149. .dma_map_consistent = pcibr_dma_map_consistent,
  150. .dma_unmap = pcibr_dma_unmap,
  151. .bus_fixup = pcibr_bus_fixup,
  152. };
  153. int
  154. pcibr_init_provider(void)
  155. {
  156. sn_pci_provider[PCIIO_ASIC_TYPE_PIC] = &pcibr_provider;
  157. sn_pci_provider[PCIIO_ASIC_TYPE_TIOCP] = &pcibr_provider;
  158. return 0;
  159. }