irq.c 9.8 KB

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