irq.c 24 KB

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