iSeries_irq.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * This module supports the iSeries PCI bus interrupt handling
  3. * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the:
  17. * Free Software Foundation, Inc.,
  18. * 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 USA
  20. *
  21. * Change Activity:
  22. * Created, December 13, 2000 by Wayne Holm
  23. * End Change Activity
  24. */
  25. #include <linux/pci.h>
  26. #include <linux/init.h>
  27. #include <linux/threads.h>
  28. #include <linux/smp.h>
  29. #include <linux/param.h>
  30. #include <linux/string.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/ide.h>
  33. #include <linux/irq.h>
  34. #include <linux/spinlock.h>
  35. #include <asm/ppcdebug.h>
  36. #include <asm/iSeries/HvCallPci.h>
  37. #include <asm/iSeries/HvCallXm.h>
  38. #include <asm/iSeries/iSeries_irq.h>
  39. /* This maps virtual irq numbers to real irqs */
  40. unsigned int virt_irq_to_real_map[NR_IRQS];
  41. /* The next available virtual irq number */
  42. /* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
  43. static int next_virtual_irq = 2;
  44. /* This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c */
  45. void __init iSeries_init_IRQ(void)
  46. {
  47. /* Register PCI event handler and open an event path */
  48. XmPciLpEvent_init();
  49. }
  50. #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
  51. #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
  52. #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
  53. /*
  54. * This will be called by device drivers (via enable_IRQ)
  55. * to enable INTA in the bridge interrupt status register.
  56. */
  57. static void iSeries_enable_IRQ(unsigned int irq)
  58. {
  59. u32 bus, deviceId, function, mask;
  60. const u32 subBus = 0;
  61. unsigned int rirq = virt_irq_to_real_map[irq];
  62. /* The IRQ has already been locked by the caller */
  63. bus = REAL_IRQ_TO_BUS(rirq);
  64. function = REAL_IRQ_TO_FUNC(rirq);
  65. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  66. /* Unmask secondary INTA */
  67. mask = 0x80000000;
  68. HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
  69. PPCDBG(PPCDBG_BUSWALK, "iSeries_enable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
  70. bus, subBus, deviceId, irq);
  71. }
  72. /* This is called by iSeries_activate_IRQs */
  73. static unsigned int iSeries_startup_IRQ(unsigned int irq)
  74. {
  75. u32 bus, deviceId, function, mask;
  76. const u32 subBus = 0;
  77. unsigned int rirq = virt_irq_to_real_map[irq];
  78. bus = REAL_IRQ_TO_BUS(rirq);
  79. function = REAL_IRQ_TO_FUNC(rirq);
  80. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  81. /* Link the IRQ number to the bridge */
  82. HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
  83. /* Unmask bridge interrupts in the FISR */
  84. mask = 0x01010000 << function;
  85. HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
  86. iSeries_enable_IRQ(irq);
  87. return 0;
  88. }
  89. /*
  90. * This is called out of iSeries_fixup to activate interrupt
  91. * generation for usable slots
  92. */
  93. void __init iSeries_activate_IRQs()
  94. {
  95. int irq;
  96. unsigned long flags;
  97. for_each_irq (irq) {
  98. irq_desc_t *desc = get_irq_desc(irq);
  99. if (desc && desc->handler && desc->handler->startup) {
  100. spin_lock_irqsave(&desc->lock, flags);
  101. desc->handler->startup(irq);
  102. spin_unlock_irqrestore(&desc->lock, flags);
  103. }
  104. }
  105. }
  106. /* this is not called anywhere currently */
  107. static void iSeries_shutdown_IRQ(unsigned int irq)
  108. {
  109. u32 bus, deviceId, function, mask;
  110. const u32 subBus = 0;
  111. unsigned int rirq = virt_irq_to_real_map[irq];
  112. /* irq should be locked by the caller */
  113. bus = REAL_IRQ_TO_BUS(rirq);
  114. function = REAL_IRQ_TO_FUNC(rirq);
  115. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  116. /* Invalidate the IRQ number in the bridge */
  117. HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
  118. /* Mask bridge interrupts in the FISR */
  119. mask = 0x01010000 << function;
  120. HvCallPci_maskFisr(bus, subBus, deviceId, mask);
  121. }
  122. /*
  123. * This will be called by device drivers (via disable_IRQ)
  124. * to disable INTA in the bridge interrupt status register.
  125. */
  126. static void iSeries_disable_IRQ(unsigned int irq)
  127. {
  128. u32 bus, deviceId, function, mask;
  129. const u32 subBus = 0;
  130. unsigned int rirq = virt_irq_to_real_map[irq];
  131. /* The IRQ has already been locked by the caller */
  132. bus = REAL_IRQ_TO_BUS(rirq);
  133. function = REAL_IRQ_TO_FUNC(rirq);
  134. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  135. /* Mask secondary INTA */
  136. mask = 0x80000000;
  137. HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
  138. PPCDBG(PPCDBG_BUSWALK, "iSeries_disable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
  139. bus, subBus, deviceId, irq);
  140. }
  141. /*
  142. * Need to define this so ppc_irq_dispatch_handler will NOT call
  143. * enable_IRQ at the end of interrupt handling. However, this does
  144. * nothing because there is not enough information provided to do
  145. * the EOI HvCall. This is done by XmPciLpEvent.c
  146. */
  147. static void iSeries_end_IRQ(unsigned int irq)
  148. {
  149. }
  150. static hw_irq_controller iSeries_IRQ_handler = {
  151. .typename = "iSeries irq controller",
  152. .startup = iSeries_startup_IRQ,
  153. .shutdown = iSeries_shutdown_IRQ,
  154. .enable = iSeries_enable_IRQ,
  155. .disable = iSeries_disable_IRQ,
  156. .end = iSeries_end_IRQ
  157. };
  158. /*
  159. * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
  160. * It calculates the irq value for the slot.
  161. * Note that subBusNumber is always 0 (at the moment at least).
  162. */
  163. int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
  164. HvSubBusNumber subBusNumber, HvAgentId deviceId)
  165. {
  166. unsigned int realirq, virtirq;
  167. u8 idsel = (deviceId >> 4);
  168. u8 function = deviceId & 7;
  169. virtirq = next_virtual_irq++;
  170. realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
  171. virt_irq_to_real_map[virtirq] = realirq;
  172. irq_desc[virtirq].handler = &iSeries_IRQ_handler;
  173. return virtirq;
  174. }