irq.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /*
  2. * Derived from arch/i386/kernel/irq.c
  3. * Copyright (C) 1992 Linus Torvalds
  4. * Adapted from arch/i386 by Gary Thomas
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. * Updated and modified by Cort Dougan <cort@fsmlabs.com>
  7. * Copyright (C) 1996-2001 Cort Dougan
  8. * Adapted for Power Macintosh by Paul Mackerras
  9. * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
  10. * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. *
  17. * This file contains the code used by various IRQ handling routines:
  18. * asking for different IRQ's should be done through these routines
  19. * instead of just grabbing them. Thus setups with different IRQ numbers
  20. * shouldn't result in any weird surprises, and installing new handlers
  21. * should be easier.
  22. *
  23. * The MPC8xx has an interrupt mask in the SIU. If a bit is set, the
  24. * interrupt is _enabled_. As expected, IRQ0 is bit 0 in the 32-bit
  25. * mask register (of which only 16 are defined), hence the weird shifting
  26. * and complement of the cached_irq_mask. I want to be able to stuff
  27. * this right into the SIU SMASK register.
  28. * Many of the prep/chrp functions are conditional compiled on CONFIG_8xx
  29. * to reduce code space and undefined function references.
  30. */
  31. #undef DEBUG
  32. #include <linux/module.h>
  33. #include <linux/threads.h>
  34. #include <linux/kernel_stat.h>
  35. #include <linux/signal.h>
  36. #include <linux/sched.h>
  37. #include <linux/ptrace.h>
  38. #include <linux/ioport.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/timex.h>
  41. #include <linux/init.h>
  42. #include <linux/slab.h>
  43. #include <linux/delay.h>
  44. #include <linux/irq.h>
  45. #include <linux/seq_file.h>
  46. #include <linux/cpumask.h>
  47. #include <linux/profile.h>
  48. #include <linux/bitops.h>
  49. #include <linux/list.h>
  50. #include <linux/radix-tree.h>
  51. #include <linux/mutex.h>
  52. #include <linux/bootmem.h>
  53. #include <asm/uaccess.h>
  54. #include <asm/system.h>
  55. #include <asm/io.h>
  56. #include <asm/pgtable.h>
  57. #include <asm/irq.h>
  58. #include <asm/cache.h>
  59. #include <asm/prom.h>
  60. #include <asm/ptrace.h>
  61. #include <asm/machdep.h>
  62. #include <asm/udbg.h>
  63. #ifdef CONFIG_PPC_ISERIES
  64. #include <asm/paca.h>
  65. #endif
  66. int __irq_offset_value;
  67. static int ppc_spurious_interrupts;
  68. #ifdef CONFIG_PPC32
  69. EXPORT_SYMBOL(__irq_offset_value);
  70. atomic_t ppc_n_lost_interrupts;
  71. #ifndef CONFIG_PPC_MERGE
  72. #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
  73. unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
  74. #endif
  75. #ifdef CONFIG_TAU_INT
  76. extern int tau_initialized;
  77. extern int tau_interrupts(int);
  78. #endif
  79. #endif /* CONFIG_PPC32 */
  80. #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE)
  81. extern atomic_t ipi_recv;
  82. extern atomic_t ipi_sent;
  83. #endif
  84. #ifdef CONFIG_PPC64
  85. EXPORT_SYMBOL(irq_desc);
  86. int distribute_irqs = 1;
  87. #endif /* CONFIG_PPC64 */
  88. int show_interrupts(struct seq_file *p, void *v)
  89. {
  90. int i = *(loff_t *)v, j;
  91. struct irqaction *action;
  92. irq_desc_t *desc;
  93. unsigned long flags;
  94. if (i == 0) {
  95. seq_puts(p, " ");
  96. for_each_online_cpu(j)
  97. seq_printf(p, "CPU%d ", j);
  98. seq_putc(p, '\n');
  99. }
  100. if (i < NR_IRQS) {
  101. desc = get_irq_desc(i);
  102. spin_lock_irqsave(&desc->lock, flags);
  103. action = desc->action;
  104. if (!action || !action->handler)
  105. goto skip;
  106. seq_printf(p, "%3d: ", i);
  107. #ifdef CONFIG_SMP
  108. for_each_online_cpu(j)
  109. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  110. #else
  111. seq_printf(p, "%10u ", kstat_irqs(i));
  112. #endif /* CONFIG_SMP */
  113. if (desc->chip)
  114. seq_printf(p, " %s ", desc->chip->typename);
  115. else
  116. seq_puts(p, " None ");
  117. seq_printf(p, "%s", (desc->status & IRQ_LEVEL) ? "Level " : "Edge ");
  118. seq_printf(p, " %s", action->name);
  119. for (action = action->next; action; action = action->next)
  120. seq_printf(p, ", %s", action->name);
  121. seq_putc(p, '\n');
  122. skip:
  123. spin_unlock_irqrestore(&desc->lock, flags);
  124. } else if (i == NR_IRQS) {
  125. #ifdef CONFIG_PPC32
  126. #ifdef CONFIG_TAU_INT
  127. if (tau_initialized){
  128. seq_puts(p, "TAU: ");
  129. for_each_online_cpu(j)
  130. seq_printf(p, "%10u ", tau_interrupts(j));
  131. seq_puts(p, " PowerPC Thermal Assist (cpu temp)\n");
  132. }
  133. #endif
  134. #if defined(CONFIG_SMP) && !defined(CONFIG_PPC_MERGE)
  135. /* should this be per processor send/receive? */
  136. seq_printf(p, "IPI (recv/sent): %10u/%u\n",
  137. atomic_read(&ipi_recv), atomic_read(&ipi_sent));
  138. #endif
  139. #endif /* CONFIG_PPC32 */
  140. seq_printf(p, "BAD: %10u\n", ppc_spurious_interrupts);
  141. }
  142. return 0;
  143. }
  144. #ifdef CONFIG_HOTPLUG_CPU
  145. void fixup_irqs(cpumask_t map)
  146. {
  147. unsigned int irq;
  148. static int warned;
  149. for_each_irq(irq) {
  150. cpumask_t mask;
  151. if (irq_desc[irq].status & IRQ_PER_CPU)
  152. continue;
  153. cpus_and(mask, irq_desc[irq].affinity, map);
  154. if (any_online_cpu(mask) == NR_CPUS) {
  155. printk("Breaking affinity for irq %i\n", irq);
  156. mask = map;
  157. }
  158. if (irq_desc[irq].chip->set_affinity)
  159. irq_desc[irq].chip->set_affinity(irq, mask);
  160. else if (irq_desc[irq].action && !(warned++))
  161. printk("Cannot set affinity for irq %i\n", irq);
  162. }
  163. local_irq_enable();
  164. mdelay(1);
  165. local_irq_disable();
  166. }
  167. #endif
  168. void do_IRQ(struct pt_regs *regs)
  169. {
  170. unsigned int irq;
  171. #ifdef CONFIG_IRQSTACKS
  172. struct thread_info *curtp, *irqtp;
  173. #endif
  174. irq_enter();
  175. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  176. /* Debugging check for stack overflow: is there less than 2KB free? */
  177. {
  178. long sp;
  179. sp = __get_SP() & (THREAD_SIZE-1);
  180. if (unlikely(sp < (sizeof(struct thread_info) + 2048))) {
  181. printk("do_IRQ: stack overflow: %ld\n",
  182. sp - sizeof(struct thread_info));
  183. dump_stack();
  184. }
  185. }
  186. #endif
  187. /*
  188. * Every platform is required to implement ppc_md.get_irq.
  189. * This function will either return an irq number or -1 to
  190. * indicate there are no more pending.
  191. * The value -2 is for buggy hardware and means that this IRQ
  192. * has already been handled. -- Tom
  193. */
  194. irq = ppc_md.get_irq(regs);
  195. if (irq != NO_IRQ && irq != NO_IRQ_IGNORE) {
  196. #ifdef CONFIG_IRQSTACKS
  197. /* Switch to the irq stack to handle this */
  198. curtp = current_thread_info();
  199. irqtp = hardirq_ctx[smp_processor_id()];
  200. if (curtp != irqtp) {
  201. struct irq_desc *desc = irq_desc + irq;
  202. void *handler = desc->handle_irq;
  203. if (handler == NULL)
  204. handler = &__do_IRQ;
  205. irqtp->task = curtp->task;
  206. irqtp->flags = 0;
  207. call_handle_irq(irq, desc, regs, irqtp, handler);
  208. irqtp->task = NULL;
  209. if (irqtp->flags)
  210. set_bits(irqtp->flags, &curtp->flags);
  211. } else
  212. #endif
  213. generic_handle_irq(irq, regs);
  214. } else if (irq != NO_IRQ_IGNORE)
  215. /* That's not SMP safe ... but who cares ? */
  216. ppc_spurious_interrupts++;
  217. irq_exit();
  218. #ifdef CONFIG_PPC_ISERIES
  219. if (get_lppaca()->int_dword.fields.decr_int) {
  220. get_lppaca()->int_dword.fields.decr_int = 0;
  221. /* Signal a fake decrementer interrupt */
  222. timer_interrupt(regs);
  223. }
  224. #endif
  225. }
  226. void __init init_IRQ(void)
  227. {
  228. ppc_md.init_IRQ();
  229. #ifdef CONFIG_PPC64
  230. irq_ctx_init();
  231. #endif
  232. }
  233. #ifdef CONFIG_IRQSTACKS
  234. struct thread_info *softirq_ctx[NR_CPUS] __read_mostly;
  235. struct thread_info *hardirq_ctx[NR_CPUS] __read_mostly;
  236. void irq_ctx_init(void)
  237. {
  238. struct thread_info *tp;
  239. int i;
  240. for_each_possible_cpu(i) {
  241. memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
  242. tp = softirq_ctx[i];
  243. tp->cpu = i;
  244. tp->preempt_count = SOFTIRQ_OFFSET;
  245. memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
  246. tp = hardirq_ctx[i];
  247. tp->cpu = i;
  248. tp->preempt_count = HARDIRQ_OFFSET;
  249. }
  250. }
  251. static inline void do_softirq_onstack(void)
  252. {
  253. struct thread_info *curtp, *irqtp;
  254. curtp = current_thread_info();
  255. irqtp = softirq_ctx[smp_processor_id()];
  256. irqtp->task = curtp->task;
  257. call_do_softirq(irqtp);
  258. irqtp->task = NULL;
  259. }
  260. #else
  261. #define do_softirq_onstack() __do_softirq()
  262. #endif /* CONFIG_IRQSTACKS */
  263. void do_softirq(void)
  264. {
  265. unsigned long flags;
  266. if (in_interrupt())
  267. return;
  268. local_irq_save(flags);
  269. if (local_softirq_pending())
  270. do_softirq_onstack();
  271. local_irq_restore(flags);
  272. }
  273. EXPORT_SYMBOL(do_softirq);
  274. /*
  275. * IRQ controller and virtual interrupts
  276. */
  277. #ifdef CONFIG_PPC_MERGE
  278. static LIST_HEAD(irq_hosts);
  279. static spinlock_t irq_big_lock = SPIN_LOCK_UNLOCKED;
  280. struct irq_map_entry irq_map[NR_IRQS];
  281. static unsigned int irq_virq_count = NR_IRQS;
  282. static struct irq_host *irq_default_host;
  283. struct irq_host *irq_alloc_host(unsigned int revmap_type,
  284. unsigned int revmap_arg,
  285. struct irq_host_ops *ops,
  286. irq_hw_number_t inval_irq)
  287. {
  288. struct irq_host *host;
  289. unsigned int size = sizeof(struct irq_host);
  290. unsigned int i;
  291. unsigned int *rmap;
  292. unsigned long flags;
  293. /* Allocate structure and revmap table if using linear mapping */
  294. if (revmap_type == IRQ_HOST_MAP_LINEAR)
  295. size += revmap_arg * sizeof(unsigned int);
  296. if (mem_init_done)
  297. host = kzalloc(size, GFP_KERNEL);
  298. else {
  299. host = alloc_bootmem(size);
  300. if (host)
  301. memset(host, 0, size);
  302. }
  303. if (host == NULL)
  304. return NULL;
  305. /* Fill structure */
  306. host->revmap_type = revmap_type;
  307. host->inval_irq = inval_irq;
  308. host->ops = ops;
  309. spin_lock_irqsave(&irq_big_lock, flags);
  310. /* If it's a legacy controller, check for duplicates and
  311. * mark it as allocated (we use irq 0 host pointer for that
  312. */
  313. if (revmap_type == IRQ_HOST_MAP_LEGACY) {
  314. if (irq_map[0].host != NULL) {
  315. spin_unlock_irqrestore(&irq_big_lock, flags);
  316. /* If we are early boot, we can't free the structure,
  317. * too bad...
  318. * this will be fixed once slab is made available early
  319. * instead of the current cruft
  320. */
  321. if (mem_init_done)
  322. kfree(host);
  323. return NULL;
  324. }
  325. irq_map[0].host = host;
  326. }
  327. list_add(&host->link, &irq_hosts);
  328. spin_unlock_irqrestore(&irq_big_lock, flags);
  329. /* Additional setups per revmap type */
  330. switch(revmap_type) {
  331. case IRQ_HOST_MAP_LEGACY:
  332. /* 0 is always the invalid number for legacy */
  333. host->inval_irq = 0;
  334. /* setup us as the host for all legacy interrupts */
  335. for (i = 1; i < NUM_ISA_INTERRUPTS; i++) {
  336. irq_map[i].hwirq = 0;
  337. smp_wmb();
  338. irq_map[i].host = host;
  339. smp_wmb();
  340. /* Clear norequest flags */
  341. get_irq_desc(i)->status &= ~IRQ_NOREQUEST;
  342. /* Legacy flags are left to default at this point,
  343. * one can then use irq_create_mapping() to
  344. * explicitely change them
  345. */
  346. ops->map(host, i, i);
  347. }
  348. break;
  349. case IRQ_HOST_MAP_LINEAR:
  350. rmap = (unsigned int *)(host + 1);
  351. for (i = 0; i < revmap_arg; i++)
  352. rmap[i] = IRQ_NONE;
  353. host->revmap_data.linear.size = revmap_arg;
  354. smp_wmb();
  355. host->revmap_data.linear.revmap = rmap;
  356. break;
  357. default:
  358. break;
  359. }
  360. pr_debug("irq: Allocated host of type %d @0x%p\n", revmap_type, host);
  361. return host;
  362. }
  363. struct irq_host *irq_find_host(struct device_node *node)
  364. {
  365. struct irq_host *h, *found = NULL;
  366. unsigned long flags;
  367. /* We might want to match the legacy controller last since
  368. * it might potentially be set to match all interrupts in
  369. * the absence of a device node. This isn't a problem so far
  370. * yet though...
  371. */
  372. spin_lock_irqsave(&irq_big_lock, flags);
  373. list_for_each_entry(h, &irq_hosts, link)
  374. if (h->ops->match == NULL || h->ops->match(h, node)) {
  375. found = h;
  376. break;
  377. }
  378. spin_unlock_irqrestore(&irq_big_lock, flags);
  379. return found;
  380. }
  381. EXPORT_SYMBOL_GPL(irq_find_host);
  382. void irq_set_default_host(struct irq_host *host)
  383. {
  384. pr_debug("irq: Default host set to @0x%p\n", host);
  385. irq_default_host = host;
  386. }
  387. void irq_set_virq_count(unsigned int count)
  388. {
  389. pr_debug("irq: Trying to set virq count to %d\n", count);
  390. BUG_ON(count < NUM_ISA_INTERRUPTS);
  391. if (count < NR_IRQS)
  392. irq_virq_count = count;
  393. }
  394. unsigned int irq_create_mapping(struct irq_host *host,
  395. irq_hw_number_t hwirq)
  396. {
  397. unsigned int virq, hint;
  398. pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", host, hwirq);
  399. /* Look for default host if nececssary */
  400. if (host == NULL)
  401. host = irq_default_host;
  402. if (host == NULL) {
  403. printk(KERN_WARNING "irq_create_mapping called for"
  404. " NULL host, hwirq=%lx\n", hwirq);
  405. WARN_ON(1);
  406. return NO_IRQ;
  407. }
  408. pr_debug("irq: -> using host @%p\n", host);
  409. /* Check if mapping already exist, if it does, call
  410. * host->ops->map() to update the flags
  411. */
  412. virq = irq_find_mapping(host, hwirq);
  413. if (virq != IRQ_NONE) {
  414. pr_debug("irq: -> existing mapping on virq %d\n", virq);
  415. return virq;
  416. }
  417. /* Get a virtual interrupt number */
  418. if (host->revmap_type == IRQ_HOST_MAP_LEGACY) {
  419. /* Handle legacy */
  420. virq = (unsigned int)hwirq;
  421. if (virq == 0 || virq >= NUM_ISA_INTERRUPTS)
  422. return NO_IRQ;
  423. return virq;
  424. } else {
  425. /* Allocate a virtual interrupt number */
  426. hint = hwirq % irq_virq_count;
  427. virq = irq_alloc_virt(host, 1, hint);
  428. if (virq == NO_IRQ) {
  429. pr_debug("irq: -> virq allocation failed\n");
  430. return NO_IRQ;
  431. }
  432. }
  433. pr_debug("irq: -> obtained virq %d\n", virq);
  434. /* Clear IRQ_NOREQUEST flag */
  435. get_irq_desc(virq)->status &= ~IRQ_NOREQUEST;
  436. /* map it */
  437. smp_wmb();
  438. irq_map[virq].hwirq = hwirq;
  439. smp_mb();
  440. if (host->ops->map(host, virq, hwirq)) {
  441. pr_debug("irq: -> mapping failed, freeing\n");
  442. irq_free_virt(virq, 1);
  443. return NO_IRQ;
  444. }
  445. return virq;
  446. }
  447. EXPORT_SYMBOL_GPL(irq_create_mapping);
  448. extern unsigned int irq_create_of_mapping(struct device_node *controller,
  449. u32 *intspec, unsigned int intsize)
  450. {
  451. struct irq_host *host;
  452. irq_hw_number_t hwirq;
  453. unsigned int type = IRQ_TYPE_NONE;
  454. unsigned int virq;
  455. if (controller == NULL)
  456. host = irq_default_host;
  457. else
  458. host = irq_find_host(controller);
  459. if (host == NULL) {
  460. printk(KERN_WARNING "irq: no irq host found for %s !\n",
  461. controller->full_name);
  462. return NO_IRQ;
  463. }
  464. /* If host has no translation, then we assume interrupt line */
  465. if (host->ops->xlate == NULL)
  466. hwirq = intspec[0];
  467. else {
  468. if (host->ops->xlate(host, controller, intspec, intsize,
  469. &hwirq, &type))
  470. return NO_IRQ;
  471. }
  472. /* Create mapping */
  473. virq = irq_create_mapping(host, hwirq);
  474. if (virq == NO_IRQ)
  475. return virq;
  476. /* Set type if specified and different than the current one */
  477. if (type != IRQ_TYPE_NONE &&
  478. type != (get_irq_desc(virq)->status & IRQF_TRIGGER_MASK))
  479. set_irq_type(virq, type);
  480. return virq;
  481. }
  482. EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  483. unsigned int irq_of_parse_and_map(struct device_node *dev, int index)
  484. {
  485. struct of_irq oirq;
  486. if (of_irq_map_one(dev, index, &oirq))
  487. return NO_IRQ;
  488. return irq_create_of_mapping(oirq.controller, oirq.specifier,
  489. oirq.size);
  490. }
  491. EXPORT_SYMBOL_GPL(irq_of_parse_and_map);
  492. void irq_dispose_mapping(unsigned int virq)
  493. {
  494. struct irq_host *host = irq_map[virq].host;
  495. irq_hw_number_t hwirq;
  496. unsigned long flags;
  497. WARN_ON (host == NULL);
  498. if (host == NULL)
  499. return;
  500. /* Never unmap legacy interrupts */
  501. if (host->revmap_type == IRQ_HOST_MAP_LEGACY)
  502. return;
  503. /* remove chip and handler */
  504. set_irq_chip_and_handler(virq, NULL, NULL);
  505. /* Make sure it's completed */
  506. synchronize_irq(virq);
  507. /* Tell the PIC about it */
  508. if (host->ops->unmap)
  509. host->ops->unmap(host, virq);
  510. smp_mb();
  511. /* Clear reverse map */
  512. hwirq = irq_map[virq].hwirq;
  513. switch(host->revmap_type) {
  514. case IRQ_HOST_MAP_LINEAR:
  515. if (hwirq < host->revmap_data.linear.size)
  516. host->revmap_data.linear.revmap[hwirq] = IRQ_NONE;
  517. break;
  518. case IRQ_HOST_MAP_TREE:
  519. /* Check if radix tree allocated yet */
  520. if (host->revmap_data.tree.gfp_mask == 0)
  521. break;
  522. /* XXX radix tree not safe ! remove lock whem it becomes safe
  523. * and use some RCU sync to make sure everything is ok before we
  524. * can re-use that map entry
  525. */
  526. spin_lock_irqsave(&irq_big_lock, flags);
  527. radix_tree_delete(&host->revmap_data.tree, hwirq);
  528. spin_unlock_irqrestore(&irq_big_lock, flags);
  529. break;
  530. }
  531. /* Destroy map */
  532. smp_mb();
  533. irq_map[virq].hwirq = host->inval_irq;
  534. /* Set some flags */
  535. get_irq_desc(virq)->status |= IRQ_NOREQUEST;
  536. /* Free it */
  537. irq_free_virt(virq, 1);
  538. }
  539. EXPORT_SYMBOL_GPL(irq_dispose_mapping);
  540. unsigned int irq_find_mapping(struct irq_host *host,
  541. irq_hw_number_t hwirq)
  542. {
  543. unsigned int i;
  544. unsigned int hint = hwirq % irq_virq_count;
  545. /* Look for default host if nececssary */
  546. if (host == NULL)
  547. host = irq_default_host;
  548. if (host == NULL)
  549. return NO_IRQ;
  550. /* legacy -> bail early */
  551. if (host->revmap_type == IRQ_HOST_MAP_LEGACY)
  552. return hwirq;
  553. /* Slow path does a linear search of the map */
  554. if (hint < NUM_ISA_INTERRUPTS)
  555. hint = NUM_ISA_INTERRUPTS;
  556. i = hint;
  557. do {
  558. if (irq_map[i].host == host &&
  559. irq_map[i].hwirq == hwirq)
  560. return i;
  561. i++;
  562. if (i >= irq_virq_count)
  563. i = NUM_ISA_INTERRUPTS;
  564. } while(i != hint);
  565. return NO_IRQ;
  566. }
  567. EXPORT_SYMBOL_GPL(irq_find_mapping);
  568. unsigned int irq_radix_revmap(struct irq_host *host,
  569. irq_hw_number_t hwirq)
  570. {
  571. struct radix_tree_root *tree;
  572. struct irq_map_entry *ptr;
  573. unsigned int virq;
  574. unsigned long flags;
  575. WARN_ON(host->revmap_type != IRQ_HOST_MAP_TREE);
  576. /* Check if the radix tree exist yet. We test the value of
  577. * the gfp_mask for that. Sneaky but saves another int in the
  578. * structure. If not, we fallback to slow mode
  579. */
  580. tree = &host->revmap_data.tree;
  581. if (tree->gfp_mask == 0)
  582. return irq_find_mapping(host, hwirq);
  583. /* XXX Current radix trees are NOT SMP safe !!! Remove that lock
  584. * when that is fixed (when Nick's patch gets in
  585. */
  586. spin_lock_irqsave(&irq_big_lock, flags);
  587. /* Now try to resolve */
  588. ptr = radix_tree_lookup(tree, hwirq);
  589. /* Found it, return */
  590. if (ptr) {
  591. virq = ptr - irq_map;
  592. goto bail;
  593. }
  594. /* If not there, try to insert it */
  595. virq = irq_find_mapping(host, hwirq);
  596. if (virq != NO_IRQ)
  597. radix_tree_insert(tree, hwirq, &irq_map[virq]);
  598. bail:
  599. spin_unlock_irqrestore(&irq_big_lock, flags);
  600. return virq;
  601. }
  602. unsigned int irq_linear_revmap(struct irq_host *host,
  603. irq_hw_number_t hwirq)
  604. {
  605. unsigned int *revmap;
  606. WARN_ON(host->revmap_type != IRQ_HOST_MAP_LINEAR);
  607. /* Check revmap bounds */
  608. if (unlikely(hwirq >= host->revmap_data.linear.size))
  609. return irq_find_mapping(host, hwirq);
  610. /* Check if revmap was allocated */
  611. revmap = host->revmap_data.linear.revmap;
  612. if (unlikely(revmap == NULL))
  613. return irq_find_mapping(host, hwirq);
  614. /* Fill up revmap with slow path if no mapping found */
  615. if (unlikely(revmap[hwirq] == NO_IRQ))
  616. revmap[hwirq] = irq_find_mapping(host, hwirq);
  617. return revmap[hwirq];
  618. }
  619. unsigned int irq_alloc_virt(struct irq_host *host,
  620. unsigned int count,
  621. unsigned int hint)
  622. {
  623. unsigned long flags;
  624. unsigned int i, j, found = NO_IRQ;
  625. unsigned int limit = irq_virq_count - count;
  626. if (count == 0 || count > (irq_virq_count - NUM_ISA_INTERRUPTS))
  627. return NO_IRQ;
  628. spin_lock_irqsave(&irq_big_lock, flags);
  629. /* Use hint for 1 interrupt if any */
  630. if (count == 1 && hint >= NUM_ISA_INTERRUPTS &&
  631. hint < irq_virq_count && irq_map[hint].host == NULL) {
  632. found = hint;
  633. goto hint_found;
  634. }
  635. /* Look for count consecutive numbers in the allocatable
  636. * (non-legacy) space
  637. */
  638. for (i = NUM_ISA_INTERRUPTS; i <= limit; ) {
  639. for (j = i; j < (i + count); j++)
  640. if (irq_map[j].host != NULL) {
  641. i = j + 1;
  642. continue;
  643. }
  644. found = i;
  645. break;
  646. }
  647. if (found == NO_IRQ) {
  648. spin_unlock_irqrestore(&irq_big_lock, flags);
  649. return NO_IRQ;
  650. }
  651. hint_found:
  652. for (i = found; i < (found + count); i++) {
  653. irq_map[i].hwirq = host->inval_irq;
  654. smp_wmb();
  655. irq_map[i].host = host;
  656. }
  657. spin_unlock_irqrestore(&irq_big_lock, flags);
  658. return found;
  659. }
  660. void irq_free_virt(unsigned int virq, unsigned int count)
  661. {
  662. unsigned long flags;
  663. unsigned int i;
  664. WARN_ON (virq < NUM_ISA_INTERRUPTS);
  665. WARN_ON (count == 0 || (virq + count) > irq_virq_count);
  666. spin_lock_irqsave(&irq_big_lock, flags);
  667. for (i = virq; i < (virq + count); i++) {
  668. struct irq_host *host;
  669. if (i < NUM_ISA_INTERRUPTS ||
  670. (virq + count) > irq_virq_count)
  671. continue;
  672. host = irq_map[i].host;
  673. irq_map[i].hwirq = host->inval_irq;
  674. smp_wmb();
  675. irq_map[i].host = NULL;
  676. }
  677. spin_unlock_irqrestore(&irq_big_lock, flags);
  678. }
  679. void irq_early_init(void)
  680. {
  681. unsigned int i;
  682. for (i = 0; i < NR_IRQS; i++)
  683. get_irq_desc(i)->status |= IRQ_NOREQUEST;
  684. }
  685. /* We need to create the radix trees late */
  686. static int irq_late_init(void)
  687. {
  688. struct irq_host *h;
  689. unsigned long flags;
  690. spin_lock_irqsave(&irq_big_lock, flags);
  691. list_for_each_entry(h, &irq_hosts, link) {
  692. if (h->revmap_type == IRQ_HOST_MAP_TREE)
  693. INIT_RADIX_TREE(&h->revmap_data.tree, GFP_ATOMIC);
  694. }
  695. spin_unlock_irqrestore(&irq_big_lock, flags);
  696. return 0;
  697. }
  698. arch_initcall(irq_late_init);
  699. #endif /* CONFIG_PPC_MERGE */
  700. #ifdef CONFIG_PCI_MSI
  701. int pci_enable_msi(struct pci_dev * pdev)
  702. {
  703. if (ppc_md.enable_msi)
  704. return ppc_md.enable_msi(pdev);
  705. else
  706. return -1;
  707. }
  708. void pci_disable_msi(struct pci_dev * pdev)
  709. {
  710. if (ppc_md.disable_msi)
  711. ppc_md.disable_msi(pdev);
  712. }
  713. void pci_scan_msi_device(struct pci_dev *dev) {}
  714. int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) {return -1;}
  715. void pci_disable_msix(struct pci_dev *dev) {}
  716. void msi_remove_pci_irq_vectors(struct pci_dev *dev) {}
  717. void disable_msi_mode(struct pci_dev *dev, int pos, int type) {}
  718. void pci_no_msi(void) {}
  719. #endif
  720. #ifdef CONFIG_PPC64
  721. static int __init setup_noirqdistrib(char *str)
  722. {
  723. distribute_irqs = 0;
  724. return 1;
  725. }
  726. __setup("noirqdistrib", setup_noirqdistrib);
  727. #endif /* CONFIG_PPC64 */