irq.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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/pci.h>
  27. #include <linux/init.h>
  28. #include <linux/threads.h>
  29. #include <linux/smp.h>
  30. #include <linux/param.h>
  31. #include <linux/string.h>
  32. #include <linux/bootmem.h>
  33. #include <linux/ide.h>
  34. #include <linux/irq.h>
  35. #include <linux/spinlock.h>
  36. #include <asm/paca.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 <asm/iseries/it_lp_queue.h>
  41. #include "irq.h"
  42. #include "pci.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. #define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff)
  155. #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
  156. #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
  157. #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
  158. /*
  159. * This will be called by device drivers (via enable_IRQ)
  160. * to enable INTA in the bridge interrupt status register.
  161. */
  162. static void iseries_enable_IRQ(unsigned int irq)
  163. {
  164. u32 bus, dev_id, function, mask;
  165. const u32 sub_bus = 0;
  166. unsigned int rirq = (unsigned int)irq_map[irq].hwirq;
  167. /* The IRQ has already been locked by the caller */
  168. bus = REAL_IRQ_TO_BUS(rirq);
  169. function = REAL_IRQ_TO_FUNC(rirq);
  170. dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  171. /* Unmask secondary INTA */
  172. mask = 0x80000000;
  173. HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask);
  174. }
  175. /* This is called by iseries_activate_IRQs */
  176. static unsigned int iseries_startup_IRQ(unsigned int irq)
  177. {
  178. u32 bus, dev_id, function, mask;
  179. const u32 sub_bus = 0;
  180. unsigned int rirq = (unsigned int)irq_map[irq].hwirq;
  181. bus = REAL_IRQ_TO_BUS(rirq);
  182. function = REAL_IRQ_TO_FUNC(rirq);
  183. dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  184. /* Link the IRQ number to the bridge */
  185. HvCallXm_connectBusUnit(bus, sub_bus, dev_id, irq);
  186. /* Unmask bridge interrupts in the FISR */
  187. mask = 0x01010000 << function;
  188. HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask);
  189. iseries_enable_IRQ(irq);
  190. return 0;
  191. }
  192. /*
  193. * This is called out of iSeries_fixup to activate interrupt
  194. * generation for usable slots
  195. */
  196. void __init iSeries_activate_IRQs()
  197. {
  198. int irq;
  199. unsigned long flags;
  200. for_each_irq (irq) {
  201. irq_desc_t *desc = get_irq_desc(irq);
  202. if (desc && desc->chip && desc->chip->startup) {
  203. spin_lock_irqsave(&desc->lock, flags);
  204. desc->chip->startup(irq);
  205. spin_unlock_irqrestore(&desc->lock, flags);
  206. }
  207. }
  208. }
  209. /* this is not called anywhere currently */
  210. static void iseries_shutdown_IRQ(unsigned int irq)
  211. {
  212. u32 bus, dev_id, function, mask;
  213. const u32 sub_bus = 0;
  214. unsigned int rirq = (unsigned int)irq_map[irq].hwirq;
  215. /* irq should be locked by the caller */
  216. bus = REAL_IRQ_TO_BUS(rirq);
  217. function = REAL_IRQ_TO_FUNC(rirq);
  218. dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
  219. /* Invalidate the IRQ number in the bridge */
  220. HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0);
  221. /* Mask bridge interrupts in the FISR */
  222. mask = 0x01010000 << function;
  223. HvCallPci_maskFisr(bus, sub_bus, dev_id, mask);
  224. }
  225. /*
  226. * This will be called by device drivers (via disable_IRQ)
  227. * to disable INTA in the bridge interrupt status register.
  228. */
  229. static void iseries_disable_IRQ(unsigned int irq)
  230. {
  231. u32 bus, dev_id, function, mask;
  232. const u32 sub_bus = 0;
  233. unsigned int rirq = (unsigned int)irq_map[irq].hwirq;
  234. /* The IRQ has already been 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. /* Mask secondary INTA */
  239. mask = 0x80000000;
  240. HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask);
  241. }
  242. static void iseries_end_IRQ(unsigned int irq)
  243. {
  244. unsigned int rirq = (unsigned int)irq_map[irq].hwirq;
  245. HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq),
  246. (REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq));
  247. }
  248. static struct irq_chip iseries_pic = {
  249. .typename = "iSeries irq controller",
  250. .startup = iseries_startup_IRQ,
  251. .shutdown = iseries_shutdown_IRQ,
  252. .unmask = iseries_enable_IRQ,
  253. .mask = iseries_disable_IRQ,
  254. .eoi = iseries_end_IRQ
  255. };
  256. /*
  257. * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
  258. * It calculates the irq value for the slot.
  259. * Note that sub_bus is always 0 (at the moment at least).
  260. */
  261. int __init iSeries_allocate_IRQ(HvBusNumber bus,
  262. HvSubBusNumber sub_bus, u32 bsubbus)
  263. {
  264. unsigned int realirq;
  265. u8 idsel = ISERIES_GET_DEVICE_FROM_SUBBUS(bsubbus);
  266. u8 function = ISERIES_GET_FUNCTION_FROM_SUBBUS(bsubbus);
  267. realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3)
  268. + function;
  269. return irq_create_mapping(NULL, realirq);
  270. }
  271. #endif /* CONFIG_PCI */
  272. /*
  273. * Get the next pending IRQ.
  274. */
  275. unsigned int iSeries_get_irq(struct pt_regs *regs)
  276. {
  277. int irq = NO_IRQ_IGNORE;
  278. #ifdef CONFIG_SMP
  279. if (get_lppaca()->int_dword.fields.ipi_cnt) {
  280. get_lppaca()->int_dword.fields.ipi_cnt = 0;
  281. iSeries_smp_message_recv(regs);
  282. }
  283. #endif /* CONFIG_SMP */
  284. if (hvlpevent_is_pending())
  285. process_hvlpevents(regs);
  286. #ifdef CONFIG_PCI
  287. if (num_pending_irqs) {
  288. spin_lock(&pending_irqs_lock);
  289. for (irq = 0; irq < NR_IRQS; irq++) {
  290. if (pending_irqs[irq]) {
  291. pending_irqs[irq]--;
  292. num_pending_irqs--;
  293. break;
  294. }
  295. }
  296. spin_unlock(&pending_irqs_lock);
  297. if (irq >= NR_IRQS)
  298. irq = NO_IRQ_IGNORE;
  299. }
  300. #endif
  301. return irq;
  302. }
  303. static int iseries_irq_host_map(struct irq_host *h, unsigned int virq,
  304. irq_hw_number_t hw)
  305. {
  306. set_irq_chip_and_handler(virq, &iseries_pic, handle_fasteoi_irq);
  307. return 0;
  308. }
  309. static struct irq_host_ops iseries_irq_host_ops = {
  310. .map = iseries_irq_host_map,
  311. };
  312. /*
  313. * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
  314. * It must be called before the bus walk.
  315. */
  316. void __init iSeries_init_IRQ(void)
  317. {
  318. /* Register PCI event handler and open an event path */
  319. struct irq_host *host;
  320. int ret;
  321. /*
  322. * The Hypervisor only allows us up to 256 interrupt
  323. * sources (the irq number is passed in a u8).
  324. */
  325. irq_set_virq_count(256);
  326. /* Create irq host. No need for a revmap since HV will give us
  327. * back our virtual irq number
  328. */
  329. host = irq_alloc_host(IRQ_HOST_MAP_NOMAP, 0, &iseries_irq_host_ops, 0);
  330. BUG_ON(host == NULL);
  331. irq_set_default_host(host);
  332. ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
  333. &pci_event_handler);
  334. if (ret == 0) {
  335. ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
  336. if (ret != 0)
  337. printk(KERN_ERR "iseries_init_IRQ: open event path "
  338. "failed with rc 0x%x\n", ret);
  339. } else
  340. printk(KERN_ERR "iseries_init_IRQ: register handler "
  341. "failed with rc 0x%x\n", ret);
  342. }