irq.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * linux/arch/alpha/kernel/irq.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. *
  6. * This file contains the code used by various IRQ handling routines:
  7. * asking for different IRQ's should be done through these routines
  8. * instead of just grabbing them. Thus setups with different IRQ numbers
  9. * shouldn't result in any weird surprises, and installing new handlers
  10. * should be easier.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/signal.h>
  18. #include <linux/sched.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/slab.h>
  22. #include <linux/random.h>
  23. #include <linux/init.h>
  24. #include <linux/irq.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/profile.h>
  28. #include <linux/bitops.h>
  29. #include <asm/system.h>
  30. #include <asm/io.h>
  31. #include <asm/uaccess.h>
  32. /*
  33. * Controller mappings for all interrupt sources:
  34. */
  35. irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = {
  36. [0 ... NR_IRQS-1] = {
  37. .handler = &no_irq_type,
  38. .lock = SPIN_LOCK_UNLOCKED
  39. }
  40. };
  41. static void register_irq_proc(unsigned int irq);
  42. volatile unsigned long irq_err_count;
  43. /*
  44. * Special irq handlers.
  45. */
  46. irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
  47. {
  48. return IRQ_NONE;
  49. }
  50. /*
  51. * Generic no controller code
  52. */
  53. static void no_irq_enable_disable(unsigned int irq) { }
  54. static unsigned int no_irq_startup(unsigned int irq) { return 0; }
  55. static void
  56. no_irq_ack(unsigned int irq)
  57. {
  58. irq_err_count++;
  59. printk(KERN_CRIT "Unexpected IRQ trap at vector %u\n", irq);
  60. }
  61. struct hw_interrupt_type no_irq_type = {
  62. .typename = "none",
  63. .startup = no_irq_startup,
  64. .shutdown = no_irq_enable_disable,
  65. .enable = no_irq_enable_disable,
  66. .disable = no_irq_enable_disable,
  67. .ack = no_irq_ack,
  68. .end = no_irq_enable_disable,
  69. };
  70. int
  71. handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
  72. struct irqaction *action)
  73. {
  74. int status = 1; /* Force the "do bottom halves" bit */
  75. int ret;
  76. do {
  77. if (!(action->flags & SA_INTERRUPT))
  78. local_irq_enable();
  79. else
  80. local_irq_disable();
  81. ret = action->handler(irq, action->dev_id, regs);
  82. if (ret == IRQ_HANDLED)
  83. status |= action->flags;
  84. action = action->next;
  85. } while (action);
  86. if (status & SA_SAMPLE_RANDOM)
  87. add_interrupt_randomness(irq);
  88. local_irq_disable();
  89. return status;
  90. }
  91. /*
  92. * Generic enable/disable code: this just calls
  93. * down into the PIC-specific version for the actual
  94. * hardware disable after having gotten the irq
  95. * controller lock.
  96. */
  97. void inline
  98. disable_irq_nosync(unsigned int irq)
  99. {
  100. irq_desc_t *desc = irq_desc + irq;
  101. unsigned long flags;
  102. spin_lock_irqsave(&desc->lock, flags);
  103. if (!desc->depth++) {
  104. desc->status |= IRQ_DISABLED;
  105. desc->handler->disable(irq);
  106. }
  107. spin_unlock_irqrestore(&desc->lock, flags);
  108. }
  109. /*
  110. * Synchronous version of the above, making sure the IRQ is
  111. * no longer running on any other IRQ..
  112. */
  113. void
  114. disable_irq(unsigned int irq)
  115. {
  116. disable_irq_nosync(irq);
  117. synchronize_irq(irq);
  118. }
  119. void
  120. enable_irq(unsigned int irq)
  121. {
  122. irq_desc_t *desc = irq_desc + irq;
  123. unsigned long flags;
  124. spin_lock_irqsave(&desc->lock, flags);
  125. switch (desc->depth) {
  126. case 1: {
  127. unsigned int status = desc->status & ~IRQ_DISABLED;
  128. desc->status = status;
  129. if ((status & (IRQ_PENDING | IRQ_REPLAY)) == IRQ_PENDING) {
  130. desc->status = status | IRQ_REPLAY;
  131. hw_resend_irq(desc->handler,irq);
  132. }
  133. desc->handler->enable(irq);
  134. /* fall-through */
  135. }
  136. default:
  137. desc->depth--;
  138. break;
  139. case 0:
  140. printk(KERN_ERR "enable_irq() unbalanced from %p\n",
  141. __builtin_return_address(0));
  142. }
  143. spin_unlock_irqrestore(&desc->lock, flags);
  144. }
  145. int
  146. setup_irq(unsigned int irq, struct irqaction * new)
  147. {
  148. int shared = 0;
  149. struct irqaction *old, **p;
  150. unsigned long flags;
  151. irq_desc_t *desc = irq_desc + irq;
  152. if (desc->handler == &no_irq_type)
  153. return -ENOSYS;
  154. /*
  155. * Some drivers like serial.c use request_irq() heavily,
  156. * so we have to be careful not to interfere with a
  157. * running system.
  158. */
  159. if (new->flags & SA_SAMPLE_RANDOM) {
  160. /*
  161. * This function might sleep, we want to call it first,
  162. * outside of the atomic block.
  163. * Yes, this might clear the entropy pool if the wrong
  164. * driver is attempted to be loaded, without actually
  165. * installing a new handler, but is this really a problem,
  166. * only the sysadmin is able to do this.
  167. */
  168. rand_initialize_irq(irq);
  169. }
  170. /*
  171. * The following block of code has to be executed atomically
  172. */
  173. spin_lock_irqsave(&desc->lock,flags);
  174. p = &desc->action;
  175. if ((old = *p) != NULL) {
  176. /* Can't share interrupts unless both agree to */
  177. if (!(old->flags & new->flags & SA_SHIRQ)) {
  178. spin_unlock_irqrestore(&desc->lock,flags);
  179. return -EBUSY;
  180. }
  181. /* add new interrupt at end of irq queue */
  182. do {
  183. p = &old->next;
  184. old = *p;
  185. } while (old);
  186. shared = 1;
  187. }
  188. *p = new;
  189. if (!shared) {
  190. desc->depth = 0;
  191. desc->status &=
  192. ~(IRQ_DISABLED|IRQ_AUTODETECT|IRQ_WAITING|IRQ_INPROGRESS);
  193. desc->handler->startup(irq);
  194. }
  195. spin_unlock_irqrestore(&desc->lock,flags);
  196. return 0;
  197. }
  198. static struct proc_dir_entry * root_irq_dir;
  199. static struct proc_dir_entry * irq_dir[NR_IRQS];
  200. #ifdef CONFIG_SMP
  201. static struct proc_dir_entry * smp_affinity_entry[NR_IRQS];
  202. static char irq_user_affinity[NR_IRQS];
  203. static cpumask_t irq_affinity[NR_IRQS] = { [0 ... NR_IRQS-1] = CPU_MASK_ALL };
  204. static void
  205. select_smp_affinity(int irq)
  206. {
  207. static int last_cpu;
  208. int cpu = last_cpu + 1;
  209. if (! irq_desc[irq].handler->set_affinity || irq_user_affinity[irq])
  210. return;
  211. while (!cpu_possible(cpu))
  212. cpu = (cpu < (NR_CPUS-1) ? cpu + 1 : 0);
  213. last_cpu = cpu;
  214. irq_affinity[irq] = cpumask_of_cpu(cpu);
  215. irq_desc[irq].handler->set_affinity(irq, cpumask_of_cpu(cpu));
  216. }
  217. static int
  218. irq_affinity_read_proc (char *page, char **start, off_t off,
  219. int count, int *eof, void *data)
  220. {
  221. int len = cpumask_scnprintf(page, count, irq_affinity[(long)data]);
  222. if (count - len < 2)
  223. return -EINVAL;
  224. len += sprintf(page + len, "\n");
  225. return len;
  226. }
  227. static int
  228. irq_affinity_write_proc(struct file *file, const char __user *buffer,
  229. unsigned long count, void *data)
  230. {
  231. int irq = (long) data, full_count = count, err;
  232. cpumask_t new_value;
  233. if (!irq_desc[irq].handler->set_affinity)
  234. return -EIO;
  235. err = cpumask_parse(buffer, count, new_value);
  236. /* The special value 0 means release control of the
  237. affinity to kernel. */
  238. cpus_and(new_value, new_value, cpu_online_map);
  239. if (cpus_empty(new_value)) {
  240. irq_user_affinity[irq] = 0;
  241. select_smp_affinity(irq);
  242. }
  243. /* Do not allow disabling IRQs completely - it's a too easy
  244. way to make the system unusable accidentally :-) At least
  245. one online CPU still has to be targeted. */
  246. else {
  247. irq_affinity[irq] = new_value;
  248. irq_user_affinity[irq] = 1;
  249. irq_desc[irq].handler->set_affinity(irq, new_value);
  250. }
  251. return full_count;
  252. }
  253. #endif /* CONFIG_SMP */
  254. #define MAX_NAMELEN 10
  255. static void
  256. register_irq_proc (unsigned int irq)
  257. {
  258. char name [MAX_NAMELEN];
  259. if (!root_irq_dir || (irq_desc[irq].handler == &no_irq_type) ||
  260. irq_dir[irq])
  261. return;
  262. memset(name, 0, MAX_NAMELEN);
  263. sprintf(name, "%d", irq);
  264. /* create /proc/irq/1234 */
  265. irq_dir[irq] = proc_mkdir(name, root_irq_dir);
  266. #ifdef CONFIG_SMP
  267. if (irq_desc[irq].handler->set_affinity) {
  268. struct proc_dir_entry *entry;
  269. /* create /proc/irq/1234/smp_affinity */
  270. entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
  271. if (entry) {
  272. entry->nlink = 1;
  273. entry->data = (void *)(long)irq;
  274. entry->read_proc = irq_affinity_read_proc;
  275. entry->write_proc = irq_affinity_write_proc;
  276. }
  277. smp_affinity_entry[irq] = entry;
  278. }
  279. #endif
  280. }
  281. void
  282. init_irq_proc (void)
  283. {
  284. int i;
  285. /* create /proc/irq */
  286. root_irq_dir = proc_mkdir("irq", NULL);
  287. #ifdef CONFIG_SMP
  288. /* create /proc/irq/prof_cpu_mask */
  289. create_prof_cpu_mask(root_irq_dir);
  290. #endif
  291. /*
  292. * Create entries for all existing IRQs.
  293. */
  294. for (i = 0; i < ACTUAL_NR_IRQS; i++) {
  295. if (irq_desc[i].handler == &no_irq_type)
  296. continue;
  297. register_irq_proc(i);
  298. }
  299. }
  300. int
  301. request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *),
  302. unsigned long irqflags, const char * devname, void *dev_id)
  303. {
  304. int retval;
  305. struct irqaction * action;
  306. if (irq >= ACTUAL_NR_IRQS)
  307. return -EINVAL;
  308. if (!handler)
  309. return -EINVAL;
  310. #if 1
  311. /*
  312. * Sanity-check: shared interrupts should REALLY pass in
  313. * a real dev-ID, otherwise we'll have trouble later trying
  314. * to figure out which interrupt is which (messes up the
  315. * interrupt freeing logic etc).
  316. */
  317. if ((irqflags & SA_SHIRQ) && !dev_id) {
  318. printk(KERN_ERR
  319. "Bad boy: %s (at %p) called us without a dev_id!\n",
  320. devname, __builtin_return_address(0));
  321. }
  322. #endif
  323. action = (struct irqaction *)
  324. kmalloc(sizeof(struct irqaction), GFP_KERNEL);
  325. if (!action)
  326. return -ENOMEM;
  327. action->handler = handler;
  328. action->flags = irqflags;
  329. cpus_clear(action->mask);
  330. action->name = devname;
  331. action->next = NULL;
  332. action->dev_id = dev_id;
  333. #ifdef CONFIG_SMP
  334. select_smp_affinity(irq);
  335. #endif
  336. retval = setup_irq(irq, action);
  337. if (retval)
  338. kfree(action);
  339. return retval;
  340. }
  341. EXPORT_SYMBOL(request_irq);
  342. void
  343. free_irq(unsigned int irq, void *dev_id)
  344. {
  345. irq_desc_t *desc;
  346. struct irqaction **p;
  347. unsigned long flags;
  348. if (irq >= ACTUAL_NR_IRQS) {
  349. printk(KERN_CRIT "Trying to free IRQ%d\n", irq);
  350. return;
  351. }
  352. desc = irq_desc + irq;
  353. spin_lock_irqsave(&desc->lock,flags);
  354. p = &desc->action;
  355. for (;;) {
  356. struct irqaction * action = *p;
  357. if (action) {
  358. struct irqaction **pp = p;
  359. p = &action->next;
  360. if (action->dev_id != dev_id)
  361. continue;
  362. /* Found - now remove it from the list of entries. */
  363. *pp = action->next;
  364. if (!desc->action) {
  365. desc->status |= IRQ_DISABLED;
  366. desc->handler->shutdown(irq);
  367. }
  368. spin_unlock_irqrestore(&desc->lock,flags);
  369. #ifdef CONFIG_SMP
  370. /* Wait to make sure it's not being used on
  371. another CPU. */
  372. while (desc->status & IRQ_INPROGRESS)
  373. barrier();
  374. #endif
  375. kfree(action);
  376. return;
  377. }
  378. printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
  379. spin_unlock_irqrestore(&desc->lock,flags);
  380. return;
  381. }
  382. }
  383. EXPORT_SYMBOL(free_irq);
  384. int
  385. show_interrupts(struct seq_file *p, void *v)
  386. {
  387. #ifdef CONFIG_SMP
  388. int j;
  389. #endif
  390. int i = *(loff_t *) v;
  391. struct irqaction * action;
  392. unsigned long flags;
  393. #ifdef CONFIG_SMP
  394. if (i == 0) {
  395. seq_puts(p, " ");
  396. for (i = 0; i < NR_CPUS; i++)
  397. if (cpu_online(i))
  398. seq_printf(p, "CPU%d ", i);
  399. seq_putc(p, '\n');
  400. }
  401. #endif
  402. if (i < ACTUAL_NR_IRQS) {
  403. spin_lock_irqsave(&irq_desc[i].lock, flags);
  404. action = irq_desc[i].action;
  405. if (!action)
  406. goto unlock;
  407. seq_printf(p, "%3d: ",i);
  408. #ifndef CONFIG_SMP
  409. seq_printf(p, "%10u ", kstat_irqs(i));
  410. #else
  411. for (j = 0; j < NR_CPUS; j++)
  412. if (cpu_online(j))
  413. seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
  414. #endif
  415. seq_printf(p, " %14s", irq_desc[i].handler->typename);
  416. seq_printf(p, " %c%s",
  417. (action->flags & SA_INTERRUPT)?'+':' ',
  418. action->name);
  419. for (action=action->next; action; action = action->next) {
  420. seq_printf(p, ", %c%s",
  421. (action->flags & SA_INTERRUPT)?'+':' ',
  422. action->name);
  423. }
  424. seq_putc(p, '\n');
  425. unlock:
  426. spin_unlock_irqrestore(&irq_desc[i].lock, flags);
  427. } else if (i == ACTUAL_NR_IRQS) {
  428. #ifdef CONFIG_SMP
  429. seq_puts(p, "IPI: ");
  430. for (i = 0; i < NR_CPUS; i++)
  431. if (cpu_online(i))
  432. seq_printf(p, "%10lu ", cpu_data[i].ipi_count);
  433. seq_putc(p, '\n');
  434. #endif
  435. seq_printf(p, "ERR: %10lu\n", irq_err_count);
  436. }
  437. return 0;
  438. }
  439. /*
  440. * handle_irq handles all normal device IRQ's (the special
  441. * SMP cross-CPU interrupts have their own specific
  442. * handlers).
  443. */
  444. #define MAX_ILLEGAL_IRQS 16
  445. void
  446. handle_irq(int irq, struct pt_regs * regs)
  447. {
  448. /*
  449. * We ack quickly, we don't want the irq controller
  450. * thinking we're snobs just because some other CPU has
  451. * disabled global interrupts (we have already done the
  452. * INT_ACK cycles, it's too late to try to pretend to the
  453. * controller that we aren't taking the interrupt).
  454. *
  455. * 0 return value means that this irq is already being
  456. * handled by some other CPU. (or is disabled)
  457. */
  458. int cpu = smp_processor_id();
  459. irq_desc_t *desc = irq_desc + irq;
  460. struct irqaction * action;
  461. unsigned int status;
  462. static unsigned int illegal_count=0;
  463. if ((unsigned) irq > ACTUAL_NR_IRQS && illegal_count < MAX_ILLEGAL_IRQS ) {
  464. irq_err_count++;
  465. illegal_count++;
  466. printk(KERN_CRIT "device_interrupt: invalid interrupt %d\n",
  467. irq);
  468. return;
  469. }
  470. irq_enter();
  471. kstat_cpu(cpu).irqs[irq]++;
  472. spin_lock_irq(&desc->lock); /* mask also the higher prio events */
  473. desc->handler->ack(irq);
  474. /*
  475. * REPLAY is when Linux resends an IRQ that was dropped earlier.
  476. * WAITING is used by probe to mark irqs that are being tested.
  477. */
  478. status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
  479. status |= IRQ_PENDING; /* we _want_ to handle it */
  480. /*
  481. * If the IRQ is disabled for whatever reason, we cannot
  482. * use the action we have.
  483. */
  484. action = NULL;
  485. if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  486. action = desc->action;
  487. status &= ~IRQ_PENDING; /* we commit to handling */
  488. status |= IRQ_INPROGRESS; /* we are handling it */
  489. }
  490. desc->status = status;
  491. /*
  492. * If there is no IRQ handler or it was disabled, exit early.
  493. * Since we set PENDING, if another processor is handling
  494. * a different instance of this same irq, the other processor
  495. * will take care of it.
  496. */
  497. if (!action)
  498. goto out;
  499. /*
  500. * Edge triggered interrupts need to remember pending events.
  501. * This applies to any hw interrupts that allow a second
  502. * instance of the same irq to arrive while we are in handle_irq
  503. * or in the handler. But the code here only handles the _second_
  504. * instance of the irq, not the third or fourth. So it is mostly
  505. * useful for irq hardware that does not mask cleanly in an
  506. * SMP environment.
  507. */
  508. for (;;) {
  509. spin_unlock(&desc->lock);
  510. handle_IRQ_event(irq, regs, action);
  511. spin_lock(&desc->lock);
  512. if (!(desc->status & IRQ_PENDING)
  513. || (desc->status & IRQ_LEVEL))
  514. break;
  515. desc->status &= ~IRQ_PENDING;
  516. }
  517. desc->status &= ~IRQ_INPROGRESS;
  518. out:
  519. /*
  520. * The ->end() handler has to deal with interrupts which got
  521. * disabled while the handler was running.
  522. */
  523. desc->handler->end(irq);
  524. spin_unlock(&desc->lock);
  525. irq_exit();
  526. }
  527. /*
  528. * IRQ autodetection code..
  529. *
  530. * This depends on the fact that any interrupt that
  531. * comes in on to an unassigned handler will get stuck
  532. * with "IRQ_WAITING" cleared and the interrupt
  533. * disabled.
  534. */
  535. unsigned long
  536. probe_irq_on(void)
  537. {
  538. int i;
  539. irq_desc_t *desc;
  540. unsigned long delay;
  541. unsigned long val;
  542. /* Something may have generated an irq long ago and we want to
  543. flush such a longstanding irq before considering it as spurious. */
  544. for (i = NR_IRQS-1; i >= 0; i--) {
  545. desc = irq_desc + i;
  546. spin_lock_irq(&desc->lock);
  547. if (!irq_desc[i].action)
  548. irq_desc[i].handler->startup(i);
  549. spin_unlock_irq(&desc->lock);
  550. }
  551. /* Wait for longstanding interrupts to trigger. */
  552. for (delay = jiffies + HZ/50; time_after(delay, jiffies); )
  553. /* about 20ms delay */ barrier();
  554. /* enable any unassigned irqs (we must startup again here because
  555. if a longstanding irq happened in the previous stage, it may have
  556. masked itself) first, enable any unassigned irqs. */
  557. for (i = NR_IRQS-1; i >= 0; i--) {
  558. desc = irq_desc + i;
  559. spin_lock_irq(&desc->lock);
  560. if (!desc->action) {
  561. desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
  562. if (desc->handler->startup(i))
  563. desc->status |= IRQ_PENDING;
  564. }
  565. spin_unlock_irq(&desc->lock);
  566. }
  567. /*
  568. * Wait for spurious interrupts to trigger
  569. */
  570. for (delay = jiffies + HZ/10; time_after(delay, jiffies); )
  571. /* about 100ms delay */ barrier();
  572. /*
  573. * Now filter out any obviously spurious interrupts
  574. */
  575. val = 0;
  576. for (i=0; i<NR_IRQS; i++) {
  577. irq_desc_t *desc = irq_desc + i;
  578. unsigned int status;
  579. spin_lock_irq(&desc->lock);
  580. status = desc->status;
  581. if (status & IRQ_AUTODETECT) {
  582. /* It triggered already - consider it spurious. */
  583. if (!(status & IRQ_WAITING)) {
  584. desc->status = status & ~IRQ_AUTODETECT;
  585. desc->handler->shutdown(i);
  586. } else
  587. if (i < 32)
  588. val |= 1 << i;
  589. }
  590. spin_unlock_irq(&desc->lock);
  591. }
  592. return val;
  593. }
  594. EXPORT_SYMBOL(probe_irq_on);
  595. /*
  596. * Return a mask of triggered interrupts (this
  597. * can handle only legacy ISA interrupts).
  598. */
  599. unsigned int
  600. probe_irq_mask(unsigned long val)
  601. {
  602. int i;
  603. unsigned int mask;
  604. mask = 0;
  605. for (i = 0; i < NR_IRQS; i++) {
  606. irq_desc_t *desc = irq_desc + i;
  607. unsigned int status;
  608. spin_lock_irq(&desc->lock);
  609. status = desc->status;
  610. if (status & IRQ_AUTODETECT) {
  611. /* We only react to ISA interrupts */
  612. if (!(status & IRQ_WAITING)) {
  613. if (i < 16)
  614. mask |= 1 << i;
  615. }
  616. desc->status = status & ~IRQ_AUTODETECT;
  617. desc->handler->shutdown(i);
  618. }
  619. spin_unlock_irq(&desc->lock);
  620. }
  621. return mask & val;
  622. }
  623. /*
  624. * Get the result of the IRQ probe.. A negative result means that
  625. * we have several candidates (but we return the lowest-numbered
  626. * one).
  627. */
  628. int
  629. probe_irq_off(unsigned long val)
  630. {
  631. int i, irq_found, nr_irqs;
  632. nr_irqs = 0;
  633. irq_found = 0;
  634. for (i=0; i<NR_IRQS; i++) {
  635. irq_desc_t *desc = irq_desc + i;
  636. unsigned int status;
  637. spin_lock_irq(&desc->lock);
  638. status = desc->status;
  639. if (status & IRQ_AUTODETECT) {
  640. if (!(status & IRQ_WAITING)) {
  641. if (!nr_irqs)
  642. irq_found = i;
  643. nr_irqs++;
  644. }
  645. desc->status = status & ~IRQ_AUTODETECT;
  646. desc->handler->shutdown(i);
  647. }
  648. spin_unlock_irq(&desc->lock);
  649. }
  650. if (nr_irqs > 1)
  651. irq_found = -irq_found;
  652. return irq_found;
  653. }
  654. EXPORT_SYMBOL(probe_irq_off);
  655. #ifdef CONFIG_SMP
  656. void synchronize_irq(unsigned int irq)
  657. {
  658. /* is there anything to synchronize with? */
  659. if (!irq_desc[irq].action)
  660. return;
  661. while (irq_desc[irq].status & IRQ_INPROGRESS)
  662. barrier();
  663. }
  664. #endif