irq.c 9.9 KB

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