irq.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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/iseries/hv_types.h>
  38. #include <asm/iseries/hv_lp_event.h>
  39. #include <asm/iseries/hv_call_xm.h>
  40. #include "irq.h"
  41. #include "call_pci.h"
  42. static long Pci_Interrupt_Count;
  43. static long Pci_Event_Count;
  44. enum XmPciLpEvent_Subtype {
  45. XmPciLpEvent_BusCreated = 0, // PHB has been created
  46. XmPciLpEvent_BusError = 1, // PHB has failed
  47. XmPciLpEvent_BusFailed = 2, // Msg to Secondary, Primary failed bus
  48. XmPciLpEvent_NodeFailed = 4, // Multi-adapter bridge has failed
  49. XmPciLpEvent_NodeRecovered = 5, // Multi-adapter bridge has recovered
  50. XmPciLpEvent_BusRecovered = 12, // PHB has been recovered
  51. XmPciLpEvent_UnQuiesceBus = 18, // Secondary bus unqiescing
  52. XmPciLpEvent_BridgeError = 21, // Bridge Error
  53. XmPciLpEvent_SlotInterrupt = 22 // Slot interrupt
  54. };
  55. struct XmPciLpEvent_BusInterrupt {
  56. HvBusNumber busNumber;
  57. HvSubBusNumber subBusNumber;
  58. };
  59. struct XmPciLpEvent_NodeInterrupt {
  60. HvBusNumber busNumber;
  61. HvSubBusNumber subBusNumber;
  62. HvAgentId deviceId;
  63. };
  64. struct XmPciLpEvent {
  65. struct HvLpEvent hvLpEvent;
  66. union {
  67. u64 alignData; // Align on an 8-byte boundary
  68. struct {
  69. u32 fisr;
  70. HvBusNumber busNumber;
  71. HvSubBusNumber subBusNumber;
  72. HvAgentId deviceId;
  73. } slotInterrupt;
  74. struct XmPciLpEvent_BusInterrupt busFailed;
  75. struct XmPciLpEvent_BusInterrupt busRecovered;
  76. struct XmPciLpEvent_BusInterrupt busCreated;
  77. struct XmPciLpEvent_NodeInterrupt nodeFailed;
  78. struct XmPciLpEvent_NodeInterrupt nodeRecovered;
  79. } eventData;
  80. };
  81. static void intReceived(struct XmPciLpEvent *eventParm,
  82. struct pt_regs *regsParm)
  83. {
  84. int irq;
  85. #ifdef CONFIG_IRQSTACKS
  86. struct thread_info *curtp, *irqtp;
  87. #endif
  88. ++Pci_Interrupt_Count;
  89. switch (eventParm->hvLpEvent.xSubtype) {
  90. case XmPciLpEvent_SlotInterrupt:
  91. irq = eventParm->hvLpEvent.xCorrelationToken;
  92. /* Dispatch the interrupt handlers for this irq */
  93. #ifdef CONFIG_IRQSTACKS
  94. /* Switch to the irq stack to handle this */
  95. curtp = current_thread_info();
  96. irqtp = hardirq_ctx[smp_processor_id()];
  97. if (curtp != irqtp) {
  98. irqtp->task = curtp->task;
  99. irqtp->flags = 0;
  100. call___do_IRQ(irq, regsParm, irqtp);
  101. irqtp->task = NULL;
  102. if (irqtp->flags)
  103. set_bits(irqtp->flags, &curtp->flags);
  104. } else
  105. #endif
  106. __do_IRQ(irq, regsParm);
  107. HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
  108. eventParm->eventData.slotInterrupt.subBusNumber,
  109. eventParm->eventData.slotInterrupt.deviceId);
  110. break;
  111. /* Ignore error recovery events for now */
  112. case XmPciLpEvent_BusCreated:
  113. printk(KERN_INFO "intReceived: system bus %d created\n",
  114. eventParm->eventData.busCreated.busNumber);
  115. break;
  116. case XmPciLpEvent_BusError:
  117. case XmPciLpEvent_BusFailed:
  118. printk(KERN_INFO "intReceived: system bus %d failed\n",
  119. eventParm->eventData.busFailed.busNumber);
  120. break;
  121. case XmPciLpEvent_BusRecovered:
  122. case XmPciLpEvent_UnQuiesceBus:
  123. printk(KERN_INFO "intReceived: system bus %d recovered\n",
  124. eventParm->eventData.busRecovered.busNumber);
  125. break;
  126. case XmPciLpEvent_NodeFailed:
  127. case XmPciLpEvent_BridgeError:
  128. printk(KERN_INFO
  129. "intReceived: multi-adapter bridge %d/%d/%d failed\n",
  130. eventParm->eventData.nodeFailed.busNumber,
  131. eventParm->eventData.nodeFailed.subBusNumber,
  132. eventParm->eventData.nodeFailed.deviceId);
  133. break;
  134. case XmPciLpEvent_NodeRecovered:
  135. printk(KERN_INFO
  136. "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
  137. eventParm->eventData.nodeRecovered.busNumber,
  138. eventParm->eventData.nodeRecovered.subBusNumber,
  139. eventParm->eventData.nodeRecovered.deviceId);
  140. break;
  141. default:
  142. printk(KERN_ERR
  143. "intReceived: unrecognized event subtype 0x%x\n",
  144. eventParm->hvLpEvent.xSubtype);
  145. break;
  146. }
  147. }
  148. static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
  149. struct pt_regs *regsParm)
  150. {
  151. #ifdef CONFIG_PCI
  152. ++Pci_Event_Count;
  153. if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
  154. switch (eventParm->xFlags.xFunction) {
  155. case HvLpEvent_Function_Int:
  156. intReceived((struct XmPciLpEvent *)eventParm, regsParm);
  157. break;
  158. case HvLpEvent_Function_Ack:
  159. printk(KERN_ERR
  160. "XmPciLpEvent_handler: unexpected ack received\n");
  161. break;
  162. default:
  163. printk(KERN_ERR
  164. "XmPciLpEvent_handler: unexpected event function %d\n",
  165. (int)eventParm->xFlags.xFunction);
  166. break;
  167. }
  168. } else if (eventParm)
  169. printk(KERN_ERR
  170. "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
  171. (int)eventParm->xType);
  172. else
  173. printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
  174. #endif
  175. }
  176. /*
  177. * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
  178. * It must be called before the bus walk.
  179. */
  180. void __init iSeries_init_IRQ(void)
  181. {
  182. /* Register PCI event handler and open an event path */
  183. int xRc;
  184. xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
  185. &XmPciLpEvent_handler);
  186. if (xRc == 0) {
  187. xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
  188. if (xRc != 0)
  189. printk(KERN_ERR "iSeries_init_IRQ: open event path "
  190. "failed with rc 0x%x\n", xRc);
  191. } else
  192. printk(KERN_ERR "iSeries_init_IRQ: register handler "
  193. "failed with rc 0x%x\n", xRc);
  194. }
  195. #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
  196. #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
  197. #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
  198. /*
  199. * This will be called by device drivers (via enable_IRQ)
  200. * to enable INTA in the bridge interrupt status register.
  201. */
  202. static void iSeries_enable_IRQ(unsigned int irq)
  203. {
  204. u32 bus, deviceId, function, mask;
  205. const u32 subBus = 0;
  206. unsigned int rirq = virt_irq_to_real_map[irq];
  207. /* The IRQ has already been locked by the caller */
  208. bus = REAL_IRQ_TO_BUS(rirq);
  209. function = REAL_IRQ_TO_FUNC(rirq);
  210. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  211. /* Unmask secondary INTA */
  212. mask = 0x80000000;
  213. HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
  214. }
  215. /* This is called by iSeries_activate_IRQs */
  216. static unsigned int iSeries_startup_IRQ(unsigned int irq)
  217. {
  218. u32 bus, deviceId, function, mask;
  219. const u32 subBus = 0;
  220. unsigned int rirq = virt_irq_to_real_map[irq];
  221. bus = REAL_IRQ_TO_BUS(rirq);
  222. function = REAL_IRQ_TO_FUNC(rirq);
  223. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  224. /* Link the IRQ number to the bridge */
  225. HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
  226. /* Unmask bridge interrupts in the FISR */
  227. mask = 0x01010000 << function;
  228. HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
  229. iSeries_enable_IRQ(irq);
  230. return 0;
  231. }
  232. /*
  233. * This is called out of iSeries_fixup to activate interrupt
  234. * generation for usable slots
  235. */
  236. void __init iSeries_activate_IRQs()
  237. {
  238. int irq;
  239. unsigned long flags;
  240. for_each_irq (irq) {
  241. irq_desc_t *desc = get_irq_desc(irq);
  242. if (desc && desc->handler && desc->handler->startup) {
  243. spin_lock_irqsave(&desc->lock, flags);
  244. desc->handler->startup(irq);
  245. spin_unlock_irqrestore(&desc->lock, flags);
  246. }
  247. }
  248. }
  249. /* this is not called anywhere currently */
  250. static void iSeries_shutdown_IRQ(unsigned int irq)
  251. {
  252. u32 bus, deviceId, function, mask;
  253. const u32 subBus = 0;
  254. unsigned int rirq = virt_irq_to_real_map[irq];
  255. /* irq should be locked by the caller */
  256. bus = REAL_IRQ_TO_BUS(rirq);
  257. function = REAL_IRQ_TO_FUNC(rirq);
  258. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  259. /* Invalidate the IRQ number in the bridge */
  260. HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
  261. /* Mask bridge interrupts in the FISR */
  262. mask = 0x01010000 << function;
  263. HvCallPci_maskFisr(bus, subBus, deviceId, mask);
  264. }
  265. /*
  266. * This will be called by device drivers (via disable_IRQ)
  267. * to disable INTA in the bridge interrupt status register.
  268. */
  269. static void iSeries_disable_IRQ(unsigned int irq)
  270. {
  271. u32 bus, deviceId, function, mask;
  272. const u32 subBus = 0;
  273. unsigned int rirq = virt_irq_to_real_map[irq];
  274. /* The IRQ has already been locked by the caller */
  275. bus = REAL_IRQ_TO_BUS(rirq);
  276. function = REAL_IRQ_TO_FUNC(rirq);
  277. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  278. /* Mask secondary INTA */
  279. mask = 0x80000000;
  280. HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
  281. }
  282. /*
  283. * This does nothing because there is not enough information
  284. * provided to do the EOI HvCall. This is done by XmPciLpEvent.c
  285. */
  286. static void iSeries_end_IRQ(unsigned int irq)
  287. {
  288. }
  289. static hw_irq_controller iSeries_IRQ_handler = {
  290. .typename = "iSeries irq controller",
  291. .startup = iSeries_startup_IRQ,
  292. .shutdown = iSeries_shutdown_IRQ,
  293. .enable = iSeries_enable_IRQ,
  294. .disable = iSeries_disable_IRQ,
  295. .end = iSeries_end_IRQ
  296. };
  297. /*
  298. * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
  299. * It calculates the irq value for the slot.
  300. * Note that subBusNumber is always 0 (at the moment at least).
  301. */
  302. int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
  303. HvSubBusNumber subBusNumber, HvAgentId deviceId)
  304. {
  305. int virtirq;
  306. unsigned int realirq;
  307. u8 idsel = (deviceId >> 4);
  308. u8 function = deviceId & 7;
  309. realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
  310. virtirq = virt_irq_create_mapping(realirq);
  311. irq_desc[virtirq].handler = &iSeries_IRQ_handler;
  312. return virtirq;
  313. }