iSeries_irq.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * This module supports the iSeries PCI bus interrupt handling
  3. * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp>
  4. * Copyright (C) 2004-2005 IBM Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the:
  18. * Free Software Foundation, Inc.,
  19. * 59 Temple Place, Suite 330,
  20. * Boston, MA 02111-1307 USA
  21. *
  22. * Change Activity:
  23. * Created, December 13, 2000 by Wayne Holm
  24. * End Change Activity
  25. */
  26. #include <linux/config.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/threads.h>
  30. #include <linux/smp.h>
  31. #include <linux/param.h>
  32. #include <linux/string.h>
  33. #include <linux/bootmem.h>
  34. #include <linux/ide.h>
  35. #include <linux/irq.h>
  36. #include <linux/spinlock.h>
  37. #include <asm/ppcdebug.h>
  38. #include <asm/iSeries/HvTypes.h>
  39. #include <asm/iSeries/HvLpEvent.h>
  40. #include <asm/iSeries/HvCallPci.h>
  41. #include <asm/iSeries/HvCallXm.h>
  42. #include <asm/iSeries/iSeries_irq.h>
  43. /* This maps virtual irq numbers to real irqs */
  44. unsigned int virt_irq_to_real_map[NR_IRQS];
  45. /* The next available virtual irq number */
  46. /* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
  47. static int next_virtual_irq = 2;
  48. static long Pci_Interrupt_Count;
  49. static long Pci_Event_Count;
  50. enum XmPciLpEvent_Subtype {
  51. XmPciLpEvent_BusCreated = 0, // PHB has been created
  52. XmPciLpEvent_BusError = 1, // PHB has failed
  53. XmPciLpEvent_BusFailed = 2, // Msg to Secondary, Primary failed bus
  54. XmPciLpEvent_NodeFailed = 4, // Multi-adapter bridge has failed
  55. XmPciLpEvent_NodeRecovered = 5, // Multi-adapter bridge has recovered
  56. XmPciLpEvent_BusRecovered = 12, // PHB has been recovered
  57. XmPciLpEvent_UnQuiesceBus = 18, // Secondary bus unqiescing
  58. XmPciLpEvent_BridgeError = 21, // Bridge Error
  59. XmPciLpEvent_SlotInterrupt = 22 // Slot interrupt
  60. };
  61. struct XmPciLpEvent_BusInterrupt {
  62. HvBusNumber busNumber;
  63. HvSubBusNumber subBusNumber;
  64. };
  65. struct XmPciLpEvent_NodeInterrupt {
  66. HvBusNumber busNumber;
  67. HvSubBusNumber subBusNumber;
  68. HvAgentId deviceId;
  69. };
  70. struct XmPciLpEvent {
  71. struct HvLpEvent hvLpEvent;
  72. union {
  73. u64 alignData; // Align on an 8-byte boundary
  74. struct {
  75. u32 fisr;
  76. HvBusNumber busNumber;
  77. HvSubBusNumber subBusNumber;
  78. HvAgentId deviceId;
  79. } slotInterrupt;
  80. struct XmPciLpEvent_BusInterrupt busFailed;
  81. struct XmPciLpEvent_BusInterrupt busRecovered;
  82. struct XmPciLpEvent_BusInterrupt busCreated;
  83. struct XmPciLpEvent_NodeInterrupt nodeFailed;
  84. struct XmPciLpEvent_NodeInterrupt nodeRecovered;
  85. } eventData;
  86. };
  87. static void intReceived(struct XmPciLpEvent *eventParm,
  88. struct pt_regs *regsParm)
  89. {
  90. int irq;
  91. ++Pci_Interrupt_Count;
  92. #if 0
  93. PPCDBG(PPCDBG_BUSWALK, "PCI: XmPciLpEvent.c: intReceived\n");
  94. #endif
  95. switch (eventParm->hvLpEvent.xSubtype) {
  96. case XmPciLpEvent_SlotInterrupt:
  97. irq = eventParm->hvLpEvent.xCorrelationToken;
  98. /* Dispatch the interrupt handlers for this irq */
  99. ppc_irq_dispatch_handler(regsParm, irq);
  100. HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
  101. eventParm->eventData.slotInterrupt.subBusNumber,
  102. eventParm->eventData.slotInterrupt.deviceId);
  103. break;
  104. /* Ignore error recovery events for now */
  105. case XmPciLpEvent_BusCreated:
  106. printk(KERN_INFO "XmPciLpEvent.c: system bus %d created\n",
  107. eventParm->eventData.busCreated.busNumber);
  108. break;
  109. case XmPciLpEvent_BusError:
  110. case XmPciLpEvent_BusFailed:
  111. printk(KERN_INFO "XmPciLpEvent.c: system bus %d failed\n",
  112. eventParm->eventData.busFailed.busNumber);
  113. break;
  114. case XmPciLpEvent_BusRecovered:
  115. case XmPciLpEvent_UnQuiesceBus:
  116. printk(KERN_INFO "XmPciLpEvent.c: system bus %d recovered\n",
  117. eventParm->eventData.busRecovered.busNumber);
  118. break;
  119. case XmPciLpEvent_NodeFailed:
  120. case XmPciLpEvent_BridgeError:
  121. printk(KERN_INFO
  122. "XmPciLpEvent.c: multi-adapter bridge %d/%d/%d failed\n",
  123. eventParm->eventData.nodeFailed.busNumber,
  124. eventParm->eventData.nodeFailed.subBusNumber,
  125. eventParm->eventData.nodeFailed.deviceId);
  126. break;
  127. case XmPciLpEvent_NodeRecovered:
  128. printk(KERN_INFO
  129. "XmPciLpEvent.c: multi-adapter bridge %d/%d/%d recovered\n",
  130. eventParm->eventData.nodeRecovered.busNumber,
  131. eventParm->eventData.nodeRecovered.subBusNumber,
  132. eventParm->eventData.nodeRecovered.deviceId);
  133. break;
  134. default:
  135. printk(KERN_ERR
  136. "XmPciLpEvent.c: unrecognized event subtype 0x%x\n",
  137. eventParm->hvLpEvent.xSubtype);
  138. break;
  139. }
  140. }
  141. static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
  142. struct pt_regs *regsParm)
  143. {
  144. #ifdef CONFIG_PCI
  145. #if 0
  146. PPCDBG(PPCDBG_BUSWALK, "XmPciLpEvent_handler, type 0x%x\n",
  147. eventParm->xType);
  148. #endif
  149. ++Pci_Event_Count;
  150. if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
  151. switch (eventParm->xFlags.xFunction) {
  152. case HvLpEvent_Function_Int:
  153. intReceived((struct XmPciLpEvent *)eventParm, regsParm);
  154. break;
  155. case HvLpEvent_Function_Ack:
  156. printk(KERN_ERR
  157. "XmPciLpEvent.c: unexpected ack received\n");
  158. break;
  159. default:
  160. printk(KERN_ERR
  161. "XmPciLpEvent.c: unexpected event function %d\n",
  162. (int)eventParm->xFlags.xFunction);
  163. break;
  164. }
  165. } else if (eventParm)
  166. printk(KERN_ERR
  167. "XmPciLpEvent.c: Unrecognized PCI event type 0x%x\n",
  168. (int)eventParm->xType);
  169. else
  170. printk(KERN_ERR "XmPciLpEvent.c: NULL event received\n");
  171. #endif
  172. }
  173. /* This should be called sometime prior to buswalk (init_IRQ would be good) */
  174. int XmPciLpEvent_init()
  175. {
  176. int xRc;
  177. PPCDBG(PPCDBG_BUSWALK,
  178. "XmPciLpEvent_init, Register Event type 0x%04X\n",
  179. HvLpEvent_Type_PciIo);
  180. xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
  181. &XmPciLpEvent_handler);
  182. if (xRc == 0) {
  183. xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
  184. if (xRc != 0)
  185. printk(KERN_ERR "XmPciLpEvent.c: open event path "
  186. "failed with rc 0x%x\n", xRc);
  187. } else
  188. printk(KERN_ERR "XmPciLpEvent.c: register handler "
  189. "failed with rc 0x%x\n", xRc);
  190. return xRc;
  191. }
  192. /* This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c */
  193. void __init iSeries_init_IRQ(void)
  194. {
  195. /* Register PCI event handler and open an event path */
  196. XmPciLpEvent_init();
  197. }
  198. #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
  199. #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
  200. #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
  201. /*
  202. * This will be called by device drivers (via enable_IRQ)
  203. * to enable INTA in the bridge interrupt status register.
  204. */
  205. static void iSeries_enable_IRQ(unsigned int irq)
  206. {
  207. u32 bus, deviceId, function, mask;
  208. const u32 subBus = 0;
  209. unsigned int rirq = virt_irq_to_real_map[irq];
  210. /* The IRQ has already been locked by the caller */
  211. bus = REAL_IRQ_TO_BUS(rirq);
  212. function = REAL_IRQ_TO_FUNC(rirq);
  213. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  214. /* Unmask secondary INTA */
  215. mask = 0x80000000;
  216. HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
  217. PPCDBG(PPCDBG_BUSWALK, "iSeries_enable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
  218. bus, subBus, deviceId, irq);
  219. }
  220. /* This is called by iSeries_activate_IRQs */
  221. static unsigned int iSeries_startup_IRQ(unsigned int irq)
  222. {
  223. u32 bus, deviceId, function, mask;
  224. const u32 subBus = 0;
  225. unsigned int rirq = virt_irq_to_real_map[irq];
  226. bus = REAL_IRQ_TO_BUS(rirq);
  227. function = REAL_IRQ_TO_FUNC(rirq);
  228. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  229. /* Link the IRQ number to the bridge */
  230. HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
  231. /* Unmask bridge interrupts in the FISR */
  232. mask = 0x01010000 << function;
  233. HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
  234. iSeries_enable_IRQ(irq);
  235. return 0;
  236. }
  237. /*
  238. * This is called out of iSeries_fixup to activate interrupt
  239. * generation for usable slots
  240. */
  241. void __init iSeries_activate_IRQs()
  242. {
  243. int irq;
  244. unsigned long flags;
  245. for_each_irq (irq) {
  246. irq_desc_t *desc = get_irq_desc(irq);
  247. if (desc && desc->handler && desc->handler->startup) {
  248. spin_lock_irqsave(&desc->lock, flags);
  249. desc->handler->startup(irq);
  250. spin_unlock_irqrestore(&desc->lock, flags);
  251. }
  252. }
  253. }
  254. /* this is not called anywhere currently */
  255. static void iSeries_shutdown_IRQ(unsigned int irq)
  256. {
  257. u32 bus, deviceId, function, mask;
  258. const u32 subBus = 0;
  259. unsigned int rirq = virt_irq_to_real_map[irq];
  260. /* irq should be locked by the caller */
  261. bus = REAL_IRQ_TO_BUS(rirq);
  262. function = REAL_IRQ_TO_FUNC(rirq);
  263. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  264. /* Invalidate the IRQ number in the bridge */
  265. HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
  266. /* Mask bridge interrupts in the FISR */
  267. mask = 0x01010000 << function;
  268. HvCallPci_maskFisr(bus, subBus, deviceId, mask);
  269. }
  270. /*
  271. * This will be called by device drivers (via disable_IRQ)
  272. * to disable INTA in the bridge interrupt status register.
  273. */
  274. static void iSeries_disable_IRQ(unsigned int irq)
  275. {
  276. u32 bus, deviceId, function, mask;
  277. const u32 subBus = 0;
  278. unsigned int rirq = virt_irq_to_real_map[irq];
  279. /* The IRQ has already been locked by the caller */
  280. bus = REAL_IRQ_TO_BUS(rirq);
  281. function = REAL_IRQ_TO_FUNC(rirq);
  282. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  283. /* Mask secondary INTA */
  284. mask = 0x80000000;
  285. HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
  286. PPCDBG(PPCDBG_BUSWALK, "iSeries_disable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
  287. bus, subBus, deviceId, irq);
  288. }
  289. /*
  290. * Need to define this so ppc_irq_dispatch_handler will NOT call
  291. * enable_IRQ at the end of interrupt handling. However, this does
  292. * nothing because there is not enough information provided to do
  293. * the EOI HvCall. This is done by XmPciLpEvent.c
  294. */
  295. static void iSeries_end_IRQ(unsigned int irq)
  296. {
  297. }
  298. static hw_irq_controller iSeries_IRQ_handler = {
  299. .typename = "iSeries irq controller",
  300. .startup = iSeries_startup_IRQ,
  301. .shutdown = iSeries_shutdown_IRQ,
  302. .enable = iSeries_enable_IRQ,
  303. .disable = iSeries_disable_IRQ,
  304. .end = iSeries_end_IRQ
  305. };
  306. /*
  307. * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
  308. * It calculates the irq value for the slot.
  309. * Note that subBusNumber is always 0 (at the moment at least).
  310. */
  311. int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
  312. HvSubBusNumber subBusNumber, HvAgentId deviceId)
  313. {
  314. unsigned int realirq, virtirq;
  315. u8 idsel = (deviceId >> 4);
  316. u8 function = deviceId & 7;
  317. virtirq = next_virtual_irq++;
  318. realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
  319. virt_irq_to_real_map[virtirq] = realirq;
  320. irq_desc[virtirq].handler = &iSeries_IRQ_handler;
  321. return virtirq;
  322. }