irq.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. /* This maps virtual irq numbers to real irqs */
  43. unsigned int virt_irq_to_real_map[NR_IRQS];
  44. /* The next available virtual irq number */
  45. /* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
  46. static int next_virtual_irq = 2;
  47. static long Pci_Interrupt_Count;
  48. static long Pci_Event_Count;
  49. enum XmPciLpEvent_Subtype {
  50. XmPciLpEvent_BusCreated = 0, // PHB has been created
  51. XmPciLpEvent_BusError = 1, // PHB has failed
  52. XmPciLpEvent_BusFailed = 2, // Msg to Secondary, Primary failed bus
  53. XmPciLpEvent_NodeFailed = 4, // Multi-adapter bridge has failed
  54. XmPciLpEvent_NodeRecovered = 5, // Multi-adapter bridge has recovered
  55. XmPciLpEvent_BusRecovered = 12, // PHB has been recovered
  56. XmPciLpEvent_UnQuiesceBus = 18, // Secondary bus unqiescing
  57. XmPciLpEvent_BridgeError = 21, // Bridge Error
  58. XmPciLpEvent_SlotInterrupt = 22 // Slot interrupt
  59. };
  60. struct XmPciLpEvent_BusInterrupt {
  61. HvBusNumber busNumber;
  62. HvSubBusNumber subBusNumber;
  63. };
  64. struct XmPciLpEvent_NodeInterrupt {
  65. HvBusNumber busNumber;
  66. HvSubBusNumber subBusNumber;
  67. HvAgentId deviceId;
  68. };
  69. struct XmPciLpEvent {
  70. struct HvLpEvent hvLpEvent;
  71. union {
  72. u64 alignData; // Align on an 8-byte boundary
  73. struct {
  74. u32 fisr;
  75. HvBusNumber busNumber;
  76. HvSubBusNumber subBusNumber;
  77. HvAgentId deviceId;
  78. } slotInterrupt;
  79. struct XmPciLpEvent_BusInterrupt busFailed;
  80. struct XmPciLpEvent_BusInterrupt busRecovered;
  81. struct XmPciLpEvent_BusInterrupt busCreated;
  82. struct XmPciLpEvent_NodeInterrupt nodeFailed;
  83. struct XmPciLpEvent_NodeInterrupt nodeRecovered;
  84. } eventData;
  85. };
  86. static void intReceived(struct XmPciLpEvent *eventParm,
  87. struct pt_regs *regsParm)
  88. {
  89. int irq;
  90. #ifdef CONFIG_IRQSTACKS
  91. struct thread_info *curtp, *irqtp;
  92. #endif
  93. ++Pci_Interrupt_Count;
  94. switch (eventParm->hvLpEvent.xSubtype) {
  95. case XmPciLpEvent_SlotInterrupt:
  96. irq = eventParm->hvLpEvent.xCorrelationToken;
  97. /* Dispatch the interrupt handlers for this irq */
  98. #ifdef CONFIG_IRQSTACKS
  99. /* Switch to the irq stack to handle this */
  100. curtp = current_thread_info();
  101. irqtp = hardirq_ctx[smp_processor_id()];
  102. if (curtp != irqtp) {
  103. irqtp->task = curtp->task;
  104. irqtp->flags = 0;
  105. call___do_IRQ(irq, regsParm, irqtp);
  106. irqtp->task = NULL;
  107. if (irqtp->flags)
  108. set_bits(irqtp->flags, &curtp->flags);
  109. } else
  110. #endif
  111. __do_IRQ(irq, regsParm);
  112. HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
  113. eventParm->eventData.slotInterrupt.subBusNumber,
  114. eventParm->eventData.slotInterrupt.deviceId);
  115. break;
  116. /* Ignore error recovery events for now */
  117. case XmPciLpEvent_BusCreated:
  118. printk(KERN_INFO "intReceived: system bus %d created\n",
  119. eventParm->eventData.busCreated.busNumber);
  120. break;
  121. case XmPciLpEvent_BusError:
  122. case XmPciLpEvent_BusFailed:
  123. printk(KERN_INFO "intReceived: system bus %d failed\n",
  124. eventParm->eventData.busFailed.busNumber);
  125. break;
  126. case XmPciLpEvent_BusRecovered:
  127. case XmPciLpEvent_UnQuiesceBus:
  128. printk(KERN_INFO "intReceived: system bus %d recovered\n",
  129. eventParm->eventData.busRecovered.busNumber);
  130. break;
  131. case XmPciLpEvent_NodeFailed:
  132. case XmPciLpEvent_BridgeError:
  133. printk(KERN_INFO
  134. "intReceived: multi-adapter bridge %d/%d/%d failed\n",
  135. eventParm->eventData.nodeFailed.busNumber,
  136. eventParm->eventData.nodeFailed.subBusNumber,
  137. eventParm->eventData.nodeFailed.deviceId);
  138. break;
  139. case XmPciLpEvent_NodeRecovered:
  140. printk(KERN_INFO
  141. "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
  142. eventParm->eventData.nodeRecovered.busNumber,
  143. eventParm->eventData.nodeRecovered.subBusNumber,
  144. eventParm->eventData.nodeRecovered.deviceId);
  145. break;
  146. default:
  147. printk(KERN_ERR
  148. "intReceived: unrecognized event subtype 0x%x\n",
  149. eventParm->hvLpEvent.xSubtype);
  150. break;
  151. }
  152. }
  153. static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
  154. struct pt_regs *regsParm)
  155. {
  156. #ifdef CONFIG_PCI
  157. ++Pci_Event_Count;
  158. if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
  159. switch (eventParm->xFlags.xFunction) {
  160. case HvLpEvent_Function_Int:
  161. intReceived((struct XmPciLpEvent *)eventParm, regsParm);
  162. break;
  163. case HvLpEvent_Function_Ack:
  164. printk(KERN_ERR
  165. "XmPciLpEvent_handler: unexpected ack received\n");
  166. break;
  167. default:
  168. printk(KERN_ERR
  169. "XmPciLpEvent_handler: unexpected event function %d\n",
  170. (int)eventParm->xFlags.xFunction);
  171. break;
  172. }
  173. } else if (eventParm)
  174. printk(KERN_ERR
  175. "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
  176. (int)eventParm->xType);
  177. else
  178. printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
  179. #endif
  180. }
  181. /*
  182. * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
  183. * It must be called before the bus walk.
  184. */
  185. void __init iSeries_init_IRQ(void)
  186. {
  187. /* Register PCI event handler and open an event path */
  188. int xRc;
  189. xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
  190. &XmPciLpEvent_handler);
  191. if (xRc == 0) {
  192. xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
  193. if (xRc != 0)
  194. printk(KERN_ERR "iSeries_init_IRQ: open event path "
  195. "failed with rc 0x%x\n", xRc);
  196. } else
  197. printk(KERN_ERR "iSeries_init_IRQ: register handler "
  198. "failed with rc 0x%x\n", xRc);
  199. }
  200. #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
  201. #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
  202. #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
  203. /*
  204. * This will be called by device drivers (via enable_IRQ)
  205. * to enable INTA in the bridge interrupt status register.
  206. */
  207. static void iSeries_enable_IRQ(unsigned int irq)
  208. {
  209. u32 bus, deviceId, function, mask;
  210. const u32 subBus = 0;
  211. unsigned int rirq = virt_irq_to_real_map[irq];
  212. /* The IRQ has already been locked by the caller */
  213. bus = REAL_IRQ_TO_BUS(rirq);
  214. function = REAL_IRQ_TO_FUNC(rirq);
  215. deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  216. /* Unmask secondary INTA */
  217. mask = 0x80000000;
  218. HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
  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. }
  287. /*
  288. * This does nothing because there is not enough information
  289. * provided to do the EOI HvCall. This is done by XmPciLpEvent.c
  290. */
  291. static void iSeries_end_IRQ(unsigned int irq)
  292. {
  293. }
  294. static hw_irq_controller iSeries_IRQ_handler = {
  295. .typename = "iSeries irq controller",
  296. .startup = iSeries_startup_IRQ,
  297. .shutdown = iSeries_shutdown_IRQ,
  298. .enable = iSeries_enable_IRQ,
  299. .disable = iSeries_disable_IRQ,
  300. .end = iSeries_end_IRQ
  301. };
  302. /*
  303. * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
  304. * It calculates the irq value for the slot.
  305. * Note that subBusNumber is always 0 (at the moment at least).
  306. */
  307. int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
  308. HvSubBusNumber subBusNumber, HvAgentId deviceId)
  309. {
  310. unsigned int realirq, virtirq;
  311. u8 idsel = (deviceId >> 4);
  312. u8 function = deviceId & 7;
  313. virtirq = next_virtual_irq++;
  314. realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
  315. virt_irq_to_real_map[virtirq] = realirq;
  316. irq_desc[virtirq].handler = &iSeries_IRQ_handler;
  317. return virtirq;
  318. }
  319. int virt_irq_create_mapping(unsigned int real_irq)
  320. {
  321. BUG(); /* Don't call this on iSeries, yet */
  322. return 0;
  323. }
  324. void virt_irq_init(void)
  325. {
  326. return;
  327. }