msi.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * arch/arm/mach-iop13xx/msi.c
  3. *
  4. * PCI MSI support for the iop13xx processor
  5. *
  6. * Copyright (c) 2006, Intel Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  19. * Place - Suite 330, Boston, MA 02111-1307 USA.
  20. *
  21. */
  22. #include <linux/pci.h>
  23. #include <linux/msi.h>
  24. #include <asm/mach/irq.h>
  25. #include <asm/irq.h>
  26. #define IOP13XX_NUM_MSI_IRQS 128
  27. static DECLARE_BITMAP(msi_irq_in_use, IOP13XX_NUM_MSI_IRQS);
  28. /* IMIPR0 CP6 R8 Page 1
  29. */
  30. static u32 read_imipr_0(void)
  31. {
  32. u32 val;
  33. asm volatile("mrc p6, 0, %0, c8, c1, 0":"=r" (val));
  34. return val;
  35. }
  36. static void write_imipr_0(u32 val)
  37. {
  38. asm volatile("mcr p6, 0, %0, c8, c1, 0"::"r" (val));
  39. }
  40. /* IMIPR1 CP6 R9 Page 1
  41. */
  42. static u32 read_imipr_1(void)
  43. {
  44. u32 val;
  45. asm volatile("mrc p6, 0, %0, c9, c1, 0":"=r" (val));
  46. return val;
  47. }
  48. static void write_imipr_1(u32 val)
  49. {
  50. asm volatile("mcr p6, 0, %0, c9, c1, 0"::"r" (val));
  51. }
  52. /* IMIPR2 CP6 R10 Page 1
  53. */
  54. static u32 read_imipr_2(void)
  55. {
  56. u32 val;
  57. asm volatile("mrc p6, 0, %0, c10, c1, 0":"=r" (val));
  58. return val;
  59. }
  60. static void write_imipr_2(u32 val)
  61. {
  62. asm volatile("mcr p6, 0, %0, c10, c1, 0"::"r" (val));
  63. }
  64. /* IMIPR3 CP6 R11 Page 1
  65. */
  66. static u32 read_imipr_3(void)
  67. {
  68. u32 val;
  69. asm volatile("mrc p6, 0, %0, c11, c1, 0":"=r" (val));
  70. return val;
  71. }
  72. static void write_imipr_3(u32 val)
  73. {
  74. asm volatile("mcr p6, 0, %0, c11, c1, 0"::"r" (val));
  75. }
  76. static u32 (*read_imipr[])(void) = {
  77. read_imipr_0,
  78. read_imipr_1,
  79. read_imipr_2,
  80. read_imipr_3,
  81. };
  82. static void (*write_imipr[])(u32) = {
  83. write_imipr_0,
  84. write_imipr_1,
  85. write_imipr_2,
  86. write_imipr_3,
  87. };
  88. static void iop13xx_msi_handler(unsigned int irq, struct irq_desc *desc)
  89. {
  90. int i, j;
  91. unsigned long status;
  92. /* read IMIPR registers and find any active interrupts,
  93. * then call ISR for each active interrupt
  94. */
  95. for (i = 0; i < ARRAY_SIZE(read_imipr); i++) {
  96. status = (read_imipr[i])();
  97. if (!status)
  98. continue;
  99. do {
  100. j = find_first_bit(&status, 32);
  101. (write_imipr[i])(1 << j); /* write back to clear bit */
  102. generic_handle_irq(IRQ_IOP13XX_MSI_0 + j + (32*i));
  103. status = (read_imipr[i])();
  104. } while (status);
  105. }
  106. }
  107. void __init iop13xx_msi_init(void)
  108. {
  109. irq_set_chained_handler(IRQ_IOP13XX_INBD_MSI, iop13xx_msi_handler);
  110. }
  111. /*
  112. * Dynamic irq allocate and deallocation
  113. */
  114. int create_irq(void)
  115. {
  116. int irq, pos;
  117. again:
  118. pos = find_first_zero_bit(msi_irq_in_use, IOP13XX_NUM_MSI_IRQS);
  119. irq = IRQ_IOP13XX_MSI_0 + pos;
  120. if (irq > NR_IRQS)
  121. return -ENOSPC;
  122. /* test_and_set_bit operates on 32-bits at a time */
  123. if (test_and_set_bit(pos, msi_irq_in_use))
  124. goto again;
  125. dynamic_irq_init(irq);
  126. return irq;
  127. }
  128. void destroy_irq(unsigned int irq)
  129. {
  130. int pos = irq - IRQ_IOP13XX_MSI_0;
  131. dynamic_irq_cleanup(irq);
  132. clear_bit(pos, msi_irq_in_use);
  133. }
  134. void arch_teardown_msi_irq(unsigned int irq)
  135. {
  136. destroy_irq(irq);
  137. }
  138. static void iop13xx_msi_nop(struct irq_data *d)
  139. {
  140. return;
  141. }
  142. static struct irq_chip iop13xx_msi_chip = {
  143. .name = "PCI-MSI",
  144. .irq_ack = iop13xx_msi_nop,
  145. .irq_enable = unmask_msi_irq,
  146. .irq_disable = mask_msi_irq,
  147. .irq_mask = mask_msi_irq,
  148. .irq_unmask = unmask_msi_irq,
  149. };
  150. int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
  151. {
  152. int id, irq = create_irq();
  153. struct msi_msg msg;
  154. if (irq < 0)
  155. return irq;
  156. irq_set_msi_desc(irq, desc);
  157. msg.address_hi = 0x0;
  158. msg.address_lo = IOP13XX_MU_MIMR_PCI;
  159. id = iop13xx_cpu_id();
  160. msg.data = (id << IOP13XX_MU_MIMR_CORE_SELECT) | (irq & 0x7f);
  161. write_msi_msg(irq, &msg);
  162. irq_set_chip_and_handler(irq, &iop13xx_msi_chip, handle_simple_irq);
  163. return 0;
  164. }