irq.c 21 KB

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