irq_32.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * Interrupt request handling routines. On the
  3. * Sparc the IRQs are basically 'cast in stone'
  4. * and you are supposed to probe the prom's device
  5. * node trees to find out who's got which IRQ.
  6. *
  7. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  8. * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  9. * Copyright (C) 1995,2002 Pete A. Zaitcev (zaitcev@yahoo.com)
  10. * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
  11. * Copyright (C) 1998-2000 Anton Blanchard (anton@samba.org)
  12. */
  13. #include <linux/kernel_stat.h>
  14. #include <linux/seq_file.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/pcic.h>
  17. #include <asm/leon.h>
  18. #include "kernel.h"
  19. #include "irq.h"
  20. #ifdef CONFIG_SMP
  21. #define SMP_NOP2 "nop; nop;\n\t"
  22. #define SMP_NOP3 "nop; nop; nop;\n\t"
  23. #else
  24. #define SMP_NOP2
  25. #define SMP_NOP3
  26. #endif /* SMP */
  27. /* platform specific irq setup */
  28. struct sparc_irq_config sparc_irq_config;
  29. unsigned long arch_local_irq_save(void)
  30. {
  31. unsigned long retval;
  32. unsigned long tmp;
  33. __asm__ __volatile__(
  34. "rd %%psr, %0\n\t"
  35. SMP_NOP3 /* Sun4m + Cypress + SMP bug */
  36. "or %0, %2, %1\n\t"
  37. "wr %1, 0, %%psr\n\t"
  38. "nop; nop; nop\n"
  39. : "=&r" (retval), "=r" (tmp)
  40. : "i" (PSR_PIL)
  41. : "memory");
  42. return retval;
  43. }
  44. EXPORT_SYMBOL(arch_local_irq_save);
  45. void arch_local_irq_enable(void)
  46. {
  47. unsigned long tmp;
  48. __asm__ __volatile__(
  49. "rd %%psr, %0\n\t"
  50. SMP_NOP3 /* Sun4m + Cypress + SMP bug */
  51. "andn %0, %1, %0\n\t"
  52. "wr %0, 0, %%psr\n\t"
  53. "nop; nop; nop\n"
  54. : "=&r" (tmp)
  55. : "i" (PSR_PIL)
  56. : "memory");
  57. }
  58. EXPORT_SYMBOL(arch_local_irq_enable);
  59. void arch_local_irq_restore(unsigned long old_psr)
  60. {
  61. unsigned long tmp;
  62. __asm__ __volatile__(
  63. "rd %%psr, %0\n\t"
  64. "and %2, %1, %2\n\t"
  65. SMP_NOP2 /* Sun4m + Cypress + SMP bug */
  66. "andn %0, %1, %0\n\t"
  67. "wr %0, %2, %%psr\n\t"
  68. "nop; nop; nop\n"
  69. : "=&r" (tmp)
  70. : "i" (PSR_PIL), "r" (old_psr)
  71. : "memory");
  72. }
  73. EXPORT_SYMBOL(arch_local_irq_restore);
  74. /*
  75. * Dave Redman (djhr@tadpole.co.uk)
  76. *
  77. * IRQ numbers.. These are no longer restricted to 15..
  78. *
  79. * this is done to enable SBUS cards and onboard IO to be masked
  80. * correctly. using the interrupt level isn't good enough.
  81. *
  82. * For example:
  83. * A device interrupting at sbus level6 and the Floppy both come in
  84. * at IRQ11, but enabling and disabling them requires writing to
  85. * different bits in the SLAVIO/SEC.
  86. *
  87. * As a result of these changes sun4m machines could now support
  88. * directed CPU interrupts using the existing enable/disable irq code
  89. * with tweaks.
  90. *
  91. */
  92. /*
  93. * Dave Redman (djhr@tadpole.co.uk)
  94. *
  95. * There used to be extern calls and hard coded values here.. very sucky!
  96. * instead, because some of the devices attach very early, I do something
  97. * equally sucky but at least we'll never try to free statically allocated
  98. * space or call kmalloc before kmalloc_init :(.
  99. *
  100. * In fact it's the timer10 that attaches first.. then timer14
  101. * then kmalloc_init is called.. then the tty interrupts attach.
  102. * hmmm....
  103. *
  104. */
  105. #define MAX_STATIC_ALLOC 4
  106. struct irqaction static_irqaction[MAX_STATIC_ALLOC];
  107. int static_irq_count;
  108. static struct {
  109. struct irqaction *action;
  110. int flags;
  111. } sparc_irq[NR_IRQS];
  112. #define SPARC_IRQ_INPROGRESS 1
  113. /* Used to protect the IRQ action lists */
  114. DEFINE_SPINLOCK(irq_action_lock);
  115. int show_interrupts(struct seq_file *p, void *v)
  116. {
  117. int i = *(loff_t *)v;
  118. struct irqaction *action;
  119. unsigned long flags;
  120. #ifdef CONFIG_SMP
  121. int j;
  122. #endif
  123. if (sparc_cpu_model == sun4d)
  124. return show_sun4d_interrupts(p, v);
  125. spin_lock_irqsave(&irq_action_lock, flags);
  126. if (i < NR_IRQS) {
  127. action = sparc_irq[i].action;
  128. if (!action)
  129. goto out_unlock;
  130. seq_printf(p, "%3d: ", i);
  131. #ifndef CONFIG_SMP
  132. seq_printf(p, "%10u ", kstat_irqs(i));
  133. #else
  134. for_each_online_cpu(j) {
  135. seq_printf(p, "%10u ",
  136. kstat_cpu(j).irqs[i]);
  137. }
  138. #endif
  139. seq_printf(p, " %c %s",
  140. (action->flags & IRQF_DISABLED) ? '+' : ' ',
  141. action->name);
  142. for (action = action->next; action; action = action->next) {
  143. seq_printf(p, ",%s %s",
  144. (action->flags & IRQF_DISABLED) ? " +" : "",
  145. action->name);
  146. }
  147. seq_putc(p, '\n');
  148. }
  149. out_unlock:
  150. spin_unlock_irqrestore(&irq_action_lock, flags);
  151. return 0;
  152. }
  153. void free_irq(unsigned int irq, void *dev_id)
  154. {
  155. struct irqaction *action;
  156. struct irqaction **actionp;
  157. unsigned long flags;
  158. unsigned int cpu_irq;
  159. if (sparc_cpu_model == sun4d) {
  160. sun4d_free_irq(irq, dev_id);
  161. return;
  162. }
  163. cpu_irq = irq & (NR_IRQS - 1);
  164. if (cpu_irq > 14) { /* 14 irq levels on the sparc */
  165. printk(KERN_ERR "Trying to free bogus IRQ %d\n", irq);
  166. return;
  167. }
  168. spin_lock_irqsave(&irq_action_lock, flags);
  169. actionp = &sparc_irq[cpu_irq].action;
  170. action = *actionp;
  171. if (!action->handler) {
  172. printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
  173. goto out_unlock;
  174. }
  175. if (dev_id) {
  176. for (; action; action = action->next) {
  177. if (action->dev_id == dev_id)
  178. break;
  179. actionp = &action->next;
  180. }
  181. if (!action) {
  182. printk(KERN_ERR "Trying to free free shared IRQ%d\n",
  183. irq);
  184. goto out_unlock;
  185. }
  186. } else if (action->flags & IRQF_SHARED) {
  187. printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
  188. irq);
  189. goto out_unlock;
  190. }
  191. if (action->flags & SA_STATIC_ALLOC) {
  192. /*
  193. * This interrupt is marked as specially allocated
  194. * so it is a bad idea to free it.
  195. */
  196. printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
  197. irq, action->name);
  198. goto out_unlock;
  199. }
  200. *actionp = action->next;
  201. spin_unlock_irqrestore(&irq_action_lock, flags);
  202. synchronize_irq(irq);
  203. spin_lock_irqsave(&irq_action_lock, flags);
  204. kfree(action);
  205. if (!sparc_irq[cpu_irq].action)
  206. __disable_irq(irq);
  207. out_unlock:
  208. spin_unlock_irqrestore(&irq_action_lock, flags);
  209. }
  210. EXPORT_SYMBOL(free_irq);
  211. /*
  212. * This is called when we want to synchronize with
  213. * interrupts. We may for example tell a device to
  214. * stop sending interrupts: but to make sure there
  215. * are no interrupts that are executing on another
  216. * CPU we need to call this function.
  217. */
  218. #ifdef CONFIG_SMP
  219. void synchronize_irq(unsigned int irq)
  220. {
  221. unsigned int cpu_irq;
  222. cpu_irq = irq & (NR_IRQS - 1);
  223. while (sparc_irq[cpu_irq].flags & SPARC_IRQ_INPROGRESS)
  224. cpu_relax();
  225. }
  226. EXPORT_SYMBOL(synchronize_irq);
  227. #endif /* SMP */
  228. void unexpected_irq(int irq, void *dev_id, struct pt_regs *regs)
  229. {
  230. int i;
  231. struct irqaction *action;
  232. unsigned int cpu_irq;
  233. cpu_irq = irq & (NR_IRQS - 1);
  234. action = sparc_irq[cpu_irq].action;
  235. printk(KERN_ERR "IO device interrupt, irq = %d\n", irq);
  236. printk(KERN_ERR "PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
  237. regs->npc, regs->u_regs[14]);
  238. if (action) {
  239. printk(KERN_ERR "Expecting: ");
  240. for (i = 0; i < 16; i++)
  241. if (action->handler)
  242. printk(KERN_CONT "[%s:%d:0x%x] ", action->name,
  243. i, (unsigned int)action->handler);
  244. }
  245. printk(KERN_ERR "AIEEE\n");
  246. panic("bogus interrupt received");
  247. }
  248. void handler_irq(int pil, struct pt_regs *regs)
  249. {
  250. struct pt_regs *old_regs;
  251. struct irqaction *action;
  252. int cpu = smp_processor_id();
  253. old_regs = set_irq_regs(regs);
  254. irq_enter();
  255. disable_pil_irq(pil);
  256. #ifdef CONFIG_SMP
  257. /* Only rotate on lower priority IRQs (scsi, ethernet, etc.). */
  258. if ((sparc_cpu_model==sun4m) && (pil < 10))
  259. smp4m_irq_rotate(cpu);
  260. #endif
  261. action = sparc_irq[pil].action;
  262. sparc_irq[pil].flags |= SPARC_IRQ_INPROGRESS;
  263. kstat_cpu(cpu).irqs[pil]++;
  264. do {
  265. if (!action || !action->handler)
  266. unexpected_irq(pil, NULL, regs);
  267. action->handler(pil, action->dev_id);
  268. action = action->next;
  269. } while (action);
  270. sparc_irq[pil].flags &= ~SPARC_IRQ_INPROGRESS;
  271. enable_pil_irq(pil);
  272. irq_exit();
  273. set_irq_regs(old_regs);
  274. }
  275. #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
  276. /*
  277. * Fast IRQs on the Sparc can only have one routine attached to them,
  278. * thus no sharing possible.
  279. */
  280. static int request_fast_irq(unsigned int irq,
  281. void (*handler)(void),
  282. unsigned long irqflags, const char *devname)
  283. {
  284. struct irqaction *action;
  285. unsigned long flags;
  286. unsigned int cpu_irq;
  287. int ret;
  288. #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
  289. struct tt_entry *trap_table;
  290. #endif
  291. cpu_irq = irq & (NR_IRQS - 1);
  292. if (cpu_irq > 14) {
  293. ret = -EINVAL;
  294. goto out;
  295. }
  296. if (!handler) {
  297. ret = -EINVAL;
  298. goto out;
  299. }
  300. spin_lock_irqsave(&irq_action_lock, flags);
  301. action = sparc_irq[cpu_irq].action;
  302. if (action) {
  303. if (action->flags & IRQF_SHARED)
  304. panic("Trying to register fast irq when already shared.\n");
  305. if (irqflags & IRQF_SHARED)
  306. panic("Trying to register fast irq as shared.\n");
  307. /* Anyway, someone already owns it so cannot be made fast. */
  308. printk(KERN_ERR "request_fast_irq: Trying to register yet already owned.\n");
  309. ret = -EBUSY;
  310. goto out_unlock;
  311. }
  312. /*
  313. * If this is flagged as statically allocated then we use our
  314. * private struct which is never freed.
  315. */
  316. if (irqflags & SA_STATIC_ALLOC) {
  317. if (static_irq_count < MAX_STATIC_ALLOC)
  318. action = &static_irqaction[static_irq_count++];
  319. else
  320. printk(KERN_ERR "Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
  321. irq, devname);
  322. }
  323. if (action == NULL)
  324. action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
  325. if (!action) {
  326. ret = -ENOMEM;
  327. goto out_unlock;
  328. }
  329. /* Dork with trap table if we get this far. */
  330. #define INSTANTIATE(table) \
  331. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
  332. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
  333. SPARC_BRANCH((unsigned long) handler, \
  334. (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
  335. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
  336. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
  337. INSTANTIATE(sparc_ttable)
  338. #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
  339. trap_table = &trapbase_cpu1;
  340. INSTANTIATE(trap_table)
  341. trap_table = &trapbase_cpu2;
  342. INSTANTIATE(trap_table)
  343. trap_table = &trapbase_cpu3;
  344. INSTANTIATE(trap_table)
  345. #endif
  346. #undef INSTANTIATE
  347. /*
  348. * XXX Correct thing whould be to flush only I- and D-cache lines
  349. * which contain the handler in question. But as of time of the
  350. * writing we have no CPU-neutral interface to fine-grained flushes.
  351. */
  352. flush_cache_all();
  353. action->flags = irqflags;
  354. action->name = devname;
  355. action->dev_id = NULL;
  356. action->next = NULL;
  357. sparc_irq[cpu_irq].action = action;
  358. __enable_irq(irq);
  359. ret = 0;
  360. out_unlock:
  361. spin_unlock_irqrestore(&irq_action_lock, flags);
  362. out:
  363. return ret;
  364. }
  365. /*
  366. * These variables are used to access state from the assembler
  367. * interrupt handler, floppy_hardint, so we cannot put these in
  368. * the floppy driver image because that would not work in the
  369. * modular case.
  370. */
  371. volatile unsigned char *fdc_status;
  372. EXPORT_SYMBOL(fdc_status);
  373. char *pdma_vaddr;
  374. EXPORT_SYMBOL(pdma_vaddr);
  375. unsigned long pdma_size;
  376. EXPORT_SYMBOL(pdma_size);
  377. volatile int doing_pdma;
  378. EXPORT_SYMBOL(doing_pdma);
  379. char *pdma_base;
  380. EXPORT_SYMBOL(pdma_base);
  381. unsigned long pdma_areasize;
  382. EXPORT_SYMBOL(pdma_areasize);
  383. static irq_handler_t floppy_irq_handler;
  384. void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
  385. {
  386. struct pt_regs *old_regs;
  387. int cpu = smp_processor_id();
  388. old_regs = set_irq_regs(regs);
  389. disable_pil_irq(irq);
  390. irq_enter();
  391. kstat_cpu(cpu).irqs[irq]++;
  392. floppy_irq_handler(irq, dev_id);
  393. irq_exit();
  394. enable_pil_irq(irq);
  395. set_irq_regs(old_regs);
  396. /*
  397. * XXX Eek, it's totally changed with preempt_count() and such
  398. * if (softirq_pending(cpu))
  399. * do_softirq();
  400. */
  401. }
  402. int sparc_floppy_request_irq(int irq, unsigned long flags,
  403. irq_handler_t irq_handler)
  404. {
  405. floppy_irq_handler = irq_handler;
  406. return request_fast_irq(irq, floppy_hardint, flags, "floppy");
  407. }
  408. EXPORT_SYMBOL(sparc_floppy_request_irq);
  409. #endif
  410. int request_irq(unsigned int irq,
  411. irq_handler_t handler,
  412. unsigned long irqflags, const char *devname, void *dev_id)
  413. {
  414. struct irqaction *action, **actionp;
  415. unsigned long flags;
  416. unsigned int cpu_irq;
  417. int ret;
  418. if (sparc_cpu_model == sun4d)
  419. return sun4d_request_irq(irq, handler, irqflags, devname, dev_id);
  420. cpu_irq = irq & (NR_IRQS - 1);
  421. if (cpu_irq > 14) {
  422. ret = -EINVAL;
  423. goto out;
  424. }
  425. if (!handler) {
  426. ret = -EINVAL;
  427. goto out;
  428. }
  429. spin_lock_irqsave(&irq_action_lock, flags);
  430. actionp = &sparc_irq[cpu_irq].action;
  431. action = *actionp;
  432. if (action) {
  433. if (!(action->flags & IRQF_SHARED) || !(irqflags & IRQF_SHARED)) {
  434. ret = -EBUSY;
  435. goto out_unlock;
  436. }
  437. if ((action->flags & IRQF_DISABLED) != (irqflags & IRQF_DISABLED)) {
  438. printk(KERN_ERR "Attempt to mix fast and slow interrupts on IRQ%d denied\n",
  439. irq);
  440. ret = -EBUSY;
  441. goto out_unlock;
  442. }
  443. for ( ; action; action = *actionp)
  444. actionp = &action->next;
  445. }
  446. /* If this is flagged as statically allocated then we use our
  447. * private struct which is never freed.
  448. */
  449. if (irqflags & SA_STATIC_ALLOC) {
  450. if (static_irq_count < MAX_STATIC_ALLOC)
  451. action = &static_irqaction[static_irq_count++];
  452. else
  453. printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
  454. irq, devname);
  455. }
  456. if (action == NULL)
  457. action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
  458. if (!action) {
  459. ret = -ENOMEM;
  460. goto out_unlock;
  461. }
  462. action->handler = handler;
  463. action->flags = irqflags;
  464. action->name = devname;
  465. action->next = NULL;
  466. action->dev_id = dev_id;
  467. *actionp = action;
  468. __enable_irq(irq);
  469. ret = 0;
  470. out_unlock:
  471. spin_unlock_irqrestore(&irq_action_lock, flags);
  472. out:
  473. return ret;
  474. }
  475. EXPORT_SYMBOL(request_irq);
  476. void disable_irq_nosync(unsigned int irq)
  477. {
  478. __disable_irq(irq);
  479. }
  480. EXPORT_SYMBOL(disable_irq_nosync);
  481. void disable_irq(unsigned int irq)
  482. {
  483. __disable_irq(irq);
  484. }
  485. EXPORT_SYMBOL(disable_irq);
  486. void enable_irq(unsigned int irq)
  487. {
  488. __enable_irq(irq);
  489. }
  490. EXPORT_SYMBOL(enable_irq);
  491. /*
  492. * We really don't need these at all on the Sparc. We only have
  493. * stubs here because they are exported to modules.
  494. */
  495. unsigned long probe_irq_on(void)
  496. {
  497. return 0;
  498. }
  499. EXPORT_SYMBOL(probe_irq_on);
  500. int probe_irq_off(unsigned long mask)
  501. {
  502. return 0;
  503. }
  504. EXPORT_SYMBOL(probe_irq_off);
  505. static unsigned int build_device_irq(struct platform_device *op,
  506. unsigned int real_irq)
  507. {
  508. return real_irq;
  509. }
  510. /* djhr
  511. * This could probably be made indirect too and assigned in the CPU
  512. * bits of the code. That would be much nicer I think and would also
  513. * fit in with the idea of being able to tune your kernel for your machine
  514. * by removing unrequired machine and device support.
  515. *
  516. */
  517. void __init init_IRQ(void)
  518. {
  519. sparc_irq_config.build_device_irq = build_device_irq;
  520. switch (sparc_cpu_model) {
  521. case sun4c:
  522. case sun4:
  523. sun4c_init_IRQ();
  524. break;
  525. case sun4m:
  526. #ifdef CONFIG_PCI
  527. pcic_probe();
  528. if (pcic_present()) {
  529. sun4m_pci_init_IRQ();
  530. break;
  531. }
  532. #endif
  533. sun4m_init_IRQ();
  534. break;
  535. case sun4d:
  536. sun4d_init_IRQ();
  537. break;
  538. case sparc_leon:
  539. leon_init_IRQ();
  540. break;
  541. default:
  542. prom_printf("Cannot initialize IRQs on this Sun machine...");
  543. break;
  544. }
  545. btfixup();
  546. }
  547. #ifdef CONFIG_PROC_FS
  548. void init_irq_proc(void)
  549. {
  550. /* For now, nothing... */
  551. }
  552. #endif /* CONFIG_PROC_FS */