irq.c 9.7 KB

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