msi_sn.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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) 2006 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. #include <linux/types.h>
  9. #include <linux/irq.h>
  10. #include <linux/pci.h>
  11. #include <linux/cpumask.h>
  12. #include <linux/msi.h>
  13. #include <linux/slab.h>
  14. #include <asm/sn/addrs.h>
  15. #include <asm/sn/intr.h>
  16. #include <asm/sn/pcibus_provider_defs.h>
  17. #include <asm/sn/pcidev.h>
  18. #include <asm/sn/nodepda.h>
  19. struct sn_msi_info {
  20. u64 pci_addr;
  21. struct sn_irq_info *sn_irq_info;
  22. };
  23. static struct sn_msi_info sn_msi_info[NR_IRQS];
  24. static struct irq_chip sn_msi_chip;
  25. void sn_teardown_msi_irq(unsigned int irq)
  26. {
  27. nasid_t nasid;
  28. int widget;
  29. struct pci_dev *pdev;
  30. struct pcidev_info *sn_pdev;
  31. struct sn_irq_info *sn_irq_info;
  32. struct pcibus_bussoft *bussoft;
  33. struct sn_pcibus_provider *provider;
  34. sn_irq_info = sn_msi_info[irq].sn_irq_info;
  35. if (sn_irq_info == NULL || sn_irq_info->irq_int_bit >= 0)
  36. return;
  37. sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  38. pdev = sn_pdev->pdi_linux_pcidev;
  39. provider = SN_PCIDEV_BUSPROVIDER(pdev);
  40. (*provider->dma_unmap)(pdev,
  41. sn_msi_info[irq].pci_addr,
  42. PCI_DMA_FROMDEVICE);
  43. sn_msi_info[irq].pci_addr = 0;
  44. bussoft = SN_PCIDEV_BUSSOFT(pdev);
  45. nasid = NASID_GET(bussoft->bs_base);
  46. widget = (nasid & 1) ?
  47. TIO_SWIN_WIDGETNUM(bussoft->bs_base) :
  48. SWIN_WIDGETNUM(bussoft->bs_base);
  49. sn_intr_free(nasid, widget, sn_irq_info);
  50. sn_msi_info[irq].sn_irq_info = NULL;
  51. destroy_irq(irq);
  52. }
  53. int sn_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *entry)
  54. {
  55. struct msi_msg msg;
  56. int widget;
  57. int status;
  58. nasid_t nasid;
  59. u64 bus_addr;
  60. struct sn_irq_info *sn_irq_info;
  61. struct pcibus_bussoft *bussoft = SN_PCIDEV_BUSSOFT(pdev);
  62. struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
  63. int irq;
  64. if (!entry->msi_attrib.is_64)
  65. return -EINVAL;
  66. if (bussoft == NULL)
  67. return -EINVAL;
  68. if (provider == NULL || provider->dma_map_consistent == NULL)
  69. return -EINVAL;
  70. irq = create_irq();
  71. if (irq < 0)
  72. return irq;
  73. /*
  74. * Set up the vector plumbing. Let the prom (via sn_intr_alloc)
  75. * decide which cpu to direct this msi at by default.
  76. */
  77. nasid = NASID_GET(bussoft->bs_base);
  78. widget = (nasid & 1) ?
  79. TIO_SWIN_WIDGETNUM(bussoft->bs_base) :
  80. SWIN_WIDGETNUM(bussoft->bs_base);
  81. sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
  82. if (! sn_irq_info) {
  83. destroy_irq(irq);
  84. return -ENOMEM;
  85. }
  86. status = sn_intr_alloc(nasid, widget, sn_irq_info, irq, -1, -1);
  87. if (status) {
  88. kfree(sn_irq_info);
  89. destroy_irq(irq);
  90. return -ENOMEM;
  91. }
  92. sn_irq_info->irq_int_bit = -1; /* mark this as an MSI irq */
  93. sn_irq_fixup(pdev, sn_irq_info);
  94. /* Prom probably should fill these in, but doesn't ... */
  95. sn_irq_info->irq_bridge_type = bussoft->bs_asic_type;
  96. sn_irq_info->irq_bridge = (void *)bussoft->bs_base;
  97. /*
  98. * Map the xio address into bus space
  99. */
  100. bus_addr = (*provider->dma_map_consistent)(pdev,
  101. sn_irq_info->irq_xtalkaddr,
  102. sizeof(sn_irq_info->irq_xtalkaddr),
  103. SN_DMA_MSI|SN_DMA_ADDR_XIO);
  104. if (! bus_addr) {
  105. sn_intr_free(nasid, widget, sn_irq_info);
  106. kfree(sn_irq_info);
  107. destroy_irq(irq);
  108. return -ENOMEM;
  109. }
  110. sn_msi_info[irq].sn_irq_info = sn_irq_info;
  111. sn_msi_info[irq].pci_addr = bus_addr;
  112. msg.address_hi = (u32)(bus_addr >> 32);
  113. msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
  114. /*
  115. * In the SN platform, bit 16 is a "send vector" bit which
  116. * must be present in order to move the vector through the system.
  117. */
  118. msg.data = 0x100 + irq;
  119. irq_set_msi_desc(irq, entry);
  120. pci_write_msi_msg(irq, &msg);
  121. irq_set_chip_and_handler(irq, &sn_msi_chip, handle_edge_irq);
  122. return 0;
  123. }
  124. #ifdef CONFIG_SMP
  125. static int sn_set_msi_irq_affinity(struct irq_data *data,
  126. const struct cpumask *cpu_mask, bool force)
  127. {
  128. struct msi_msg msg;
  129. int slice;
  130. nasid_t nasid;
  131. u64 bus_addr;
  132. struct pci_dev *pdev;
  133. struct pcidev_info *sn_pdev;
  134. struct sn_irq_info *sn_irq_info;
  135. struct sn_irq_info *new_irq_info;
  136. struct sn_pcibus_provider *provider;
  137. unsigned int cpu, irq = data->irq;
  138. cpu = cpumask_first_and(cpu_mask, cpu_online_mask);
  139. sn_irq_info = sn_msi_info[irq].sn_irq_info;
  140. if (sn_irq_info == NULL || sn_irq_info->irq_int_bit >= 0)
  141. return -1;
  142. /*
  143. * Release XIO resources for the old MSI PCI address
  144. */
  145. __get_cached_msi_msg(data->msi_desc, &msg);
  146. sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
  147. pdev = sn_pdev->pdi_linux_pcidev;
  148. provider = SN_PCIDEV_BUSPROVIDER(pdev);
  149. bus_addr = (u64)(msg.address_hi) << 32 | (u64)(msg.address_lo);
  150. (*provider->dma_unmap)(pdev, bus_addr, PCI_DMA_FROMDEVICE);
  151. sn_msi_info[irq].pci_addr = 0;
  152. nasid = cpuid_to_nasid(cpu);
  153. slice = cpuid_to_slice(cpu);
  154. new_irq_info = sn_retarget_vector(sn_irq_info, nasid, slice);
  155. sn_msi_info[irq].sn_irq_info = new_irq_info;
  156. if (new_irq_info == NULL)
  157. return -1;
  158. /*
  159. * Map the xio address into bus space
  160. */
  161. bus_addr = (*provider->dma_map_consistent)(pdev,
  162. new_irq_info->irq_xtalkaddr,
  163. sizeof(new_irq_info->irq_xtalkaddr),
  164. SN_DMA_MSI|SN_DMA_ADDR_XIO);
  165. sn_msi_info[irq].pci_addr = bus_addr;
  166. msg.address_hi = (u32)(bus_addr >> 32);
  167. msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
  168. pci_write_msi_msg(irq, &msg);
  169. cpumask_copy(data->affinity, cpu_mask);
  170. return 0;
  171. }
  172. #endif /* CONFIG_SMP */
  173. static void sn_ack_msi_irq(struct irq_data *data)
  174. {
  175. irq_move_irq(data);
  176. ia64_eoi();
  177. }
  178. static int sn_msi_retrigger_irq(struct irq_data *data)
  179. {
  180. unsigned int vector = data->irq;
  181. ia64_resend_irq(vector);
  182. return 1;
  183. }
  184. static struct irq_chip sn_msi_chip = {
  185. .name = "PCI-MSI",
  186. .irq_mask = pci_msi_mask_irq,
  187. .irq_unmask = pci_msi_unmask_irq,
  188. .irq_ack = sn_ack_msi_irq,
  189. #ifdef CONFIG_SMP
  190. .irq_set_affinity = sn_set_msi_irq_affinity,
  191. #endif
  192. .irq_retrigger = sn_msi_retrigger_irq,
  193. };