irq.c 9.7 KB

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