irq_32.c 15 KB

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