ints.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * linux/arch/m68k/kernel/ints.c -- Linux/m68k general interrupt handling code
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file COPYING in the main directory of this archive
  6. * for more details.
  7. *
  8. * 07/03/96: Timer initialization, and thus mach_sched_init(),
  9. * removed from request_irq() and moved to init_time().
  10. * We should therefore consider renaming our add_isr() and
  11. * remove_isr() to request_irq() and free_irq()
  12. * respectively, so they are compliant with the other
  13. * architectures. /Jes
  14. * 11/07/96: Changed all add_/remove_isr() to request_/free_irq() calls.
  15. * Removed irq list support, if any machine needs an irq server
  16. * it must implement this itself (as it's already done), instead
  17. * only default handler are used with mach_default_handler.
  18. * request_irq got some flags different from other architectures:
  19. * - IRQ_FLG_REPLACE : Replace an existing handler (the default one
  20. * can be replaced without this flag)
  21. * - IRQ_FLG_LOCK : handler can't be replaced
  22. * There are other machine depending flags, see there
  23. * If you want to replace a default handler you should know what
  24. * you're doing, since it might handle different other irq sources
  25. * which must be served /Roman Zippel
  26. */
  27. #include <linux/module.h>
  28. #include <linux/types.h>
  29. #include <linux/sched.h>
  30. #include <linux/kernel_stat.h>
  31. #include <linux/errno.h>
  32. #include <linux/init.h>
  33. #include <asm/setup.h>
  34. #include <asm/system.h>
  35. #include <asm/irq.h>
  36. #include <asm/traps.h>
  37. #include <asm/page.h>
  38. #include <asm/machdep.h>
  39. #include <asm/cacheflush.h>
  40. #include <asm/irq_regs.h>
  41. #ifdef CONFIG_Q40
  42. #include <asm/q40ints.h>
  43. #endif
  44. extern u32 auto_irqhandler_fixup[];
  45. extern u32 user_irqhandler_fixup[];
  46. extern u16 user_irqvec_fixup[];
  47. /* table for system interrupt handlers */
  48. static struct irq_node *irq_list[NR_IRQS];
  49. static struct irq_controller *irq_controller[NR_IRQS];
  50. static int irq_depth[NR_IRQS];
  51. static int m68k_first_user_vec;
  52. static struct irq_controller auto_irq_controller = {
  53. .name = "auto",
  54. .lock = SPIN_LOCK_UNLOCKED,
  55. .startup = m68k_irq_startup,
  56. .shutdown = m68k_irq_shutdown,
  57. };
  58. static struct irq_controller user_irq_controller = {
  59. .name = "user",
  60. .lock = SPIN_LOCK_UNLOCKED,
  61. .startup = m68k_irq_startup,
  62. .shutdown = m68k_irq_shutdown,
  63. };
  64. #define NUM_IRQ_NODES 100
  65. static irq_node_t nodes[NUM_IRQ_NODES];
  66. /*
  67. * void init_IRQ(void)
  68. *
  69. * Parameters: None
  70. *
  71. * Returns: Nothing
  72. *
  73. * This function should be called during kernel startup to initialize
  74. * the IRQ handling routines.
  75. */
  76. void __init init_IRQ(void)
  77. {
  78. int i;
  79. /* assembly irq entry code relies on this... */
  80. if (HARDIRQ_MASK != 0x00ff0000) {
  81. extern void hardirq_mask_is_broken(void);
  82. hardirq_mask_is_broken();
  83. }
  84. for (i = IRQ_AUTO_1; i <= IRQ_AUTO_7; i++)
  85. irq_controller[i] = &auto_irq_controller;
  86. mach_init_IRQ();
  87. }
  88. /**
  89. * m68k_setup_auto_interrupt
  90. * @handler: called from auto vector interrupts
  91. *
  92. * setup the handler to be called from auto vector interrupts instead of the
  93. * standard __m68k_handle_int(), it will be called with irq numbers in the range
  94. * from IRQ_AUTO_1 - IRQ_AUTO_7.
  95. */
  96. void __init m68k_setup_auto_interrupt(void (*handler)(unsigned int, struct pt_regs *))
  97. {
  98. if (handler)
  99. *auto_irqhandler_fixup = (u32)handler;
  100. flush_icache();
  101. }
  102. /**
  103. * m68k_setup_user_interrupt
  104. * @vec: first user vector interrupt to handle
  105. * @cnt: number of active user vector interrupts
  106. * @handler: called from user vector interrupts
  107. *
  108. * setup user vector interrupts, this includes activating the specified range
  109. * of interrupts, only then these interrupts can be requested (note: this is
  110. * different from auto vector interrupts). An optional handler can be installed
  111. * to be called instead of the default __m68k_handle_int(), it will be called
  112. * with irq numbers starting from IRQ_USER.
  113. */
  114. void __init m68k_setup_user_interrupt(unsigned int vec, unsigned int cnt,
  115. void (*handler)(unsigned int, struct pt_regs *))
  116. {
  117. int i;
  118. BUG_ON(IRQ_USER + cnt >= NR_IRQS);
  119. m68k_first_user_vec = vec;
  120. for (i = 0; i < cnt; i++)
  121. irq_controller[IRQ_USER + i] = &user_irq_controller;
  122. *user_irqvec_fixup = vec - IRQ_USER;
  123. if (handler)
  124. *user_irqhandler_fixup = (u32)handler;
  125. flush_icache();
  126. }
  127. /**
  128. * m68k_setup_irq_controller
  129. * @contr: irq controller which controls specified irq
  130. * @irq: first irq to be managed by the controller
  131. *
  132. * Change the controller for the specified range of irq, which will be used to
  133. * manage these irq. auto/user irq already have a default controller, which can
  134. * be changed as well, but the controller probably should use m68k_irq_startup/
  135. * m68k_irq_shutdown.
  136. */
  137. void m68k_setup_irq_controller(struct irq_controller *contr, unsigned int irq,
  138. unsigned int cnt)
  139. {
  140. int i;
  141. for (i = 0; i < cnt; i++)
  142. irq_controller[irq + i] = contr;
  143. }
  144. irq_node_t *new_irq_node(void)
  145. {
  146. irq_node_t *node;
  147. short i;
  148. for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--) {
  149. if (!node->handler) {
  150. memset(node, 0, sizeof(*node));
  151. return node;
  152. }
  153. }
  154. printk ("new_irq_node: out of nodes\n");
  155. return NULL;
  156. }
  157. int setup_irq(unsigned int irq, struct irq_node *node)
  158. {
  159. struct irq_controller *contr;
  160. struct irq_node **prev;
  161. unsigned long flags;
  162. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  163. printk("%s: Incorrect IRQ %d from %s\n",
  164. __FUNCTION__, irq, node->devname);
  165. return -ENXIO;
  166. }
  167. spin_lock_irqsave(&contr->lock, flags);
  168. prev = irq_list + irq;
  169. if (*prev) {
  170. /* Can't share interrupts unless both agree to */
  171. if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
  172. spin_unlock_irqrestore(&contr->lock, flags);
  173. return -EBUSY;
  174. }
  175. while (*prev)
  176. prev = &(*prev)->next;
  177. }
  178. if (!irq_list[irq]) {
  179. if (contr->startup)
  180. contr->startup(irq);
  181. else
  182. contr->enable(irq);
  183. }
  184. node->next = NULL;
  185. *prev = node;
  186. spin_unlock_irqrestore(&contr->lock, flags);
  187. return 0;
  188. }
  189. int request_irq(unsigned int irq,
  190. irq_handler_t handler,
  191. unsigned long flags, const char *devname, void *dev_id)
  192. {
  193. struct irq_node *node;
  194. int res;
  195. node = new_irq_node();
  196. if (!node)
  197. return -ENOMEM;
  198. node->handler = handler;
  199. node->flags = flags;
  200. node->dev_id = dev_id;
  201. node->devname = devname;
  202. res = setup_irq(irq, node);
  203. if (res)
  204. node->handler = NULL;
  205. return res;
  206. }
  207. EXPORT_SYMBOL(request_irq);
  208. void free_irq(unsigned int irq, void *dev_id)
  209. {
  210. struct irq_controller *contr;
  211. struct irq_node **p, *node;
  212. unsigned long flags;
  213. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  214. printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
  215. return;
  216. }
  217. spin_lock_irqsave(&contr->lock, flags);
  218. p = irq_list + irq;
  219. while ((node = *p)) {
  220. if (node->dev_id == dev_id)
  221. break;
  222. p = &node->next;
  223. }
  224. if (node) {
  225. *p = node->next;
  226. node->handler = NULL;
  227. } else
  228. printk("%s: Removing probably wrong IRQ %d\n",
  229. __FUNCTION__, irq);
  230. if (!irq_list[irq]) {
  231. if (contr->shutdown)
  232. contr->shutdown(irq);
  233. else
  234. contr->disable(irq);
  235. }
  236. spin_unlock_irqrestore(&contr->lock, flags);
  237. }
  238. EXPORT_SYMBOL(free_irq);
  239. void enable_irq(unsigned int irq)
  240. {
  241. struct irq_controller *contr;
  242. unsigned long flags;
  243. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  244. printk("%s: Incorrect IRQ %d\n",
  245. __FUNCTION__, irq);
  246. return;
  247. }
  248. spin_lock_irqsave(&contr->lock, flags);
  249. if (irq_depth[irq]) {
  250. if (!--irq_depth[irq]) {
  251. if (contr->enable)
  252. contr->enable(irq);
  253. }
  254. } else
  255. WARN_ON(1);
  256. spin_unlock_irqrestore(&contr->lock, flags);
  257. }
  258. EXPORT_SYMBOL(enable_irq);
  259. void disable_irq(unsigned int irq)
  260. {
  261. struct irq_controller *contr;
  262. unsigned long flags;
  263. if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
  264. printk("%s: Incorrect IRQ %d\n",
  265. __FUNCTION__, irq);
  266. return;
  267. }
  268. spin_lock_irqsave(&contr->lock, flags);
  269. if (!irq_depth[irq]++) {
  270. if (contr->disable)
  271. contr->disable(irq);
  272. }
  273. spin_unlock_irqrestore(&contr->lock, flags);
  274. }
  275. EXPORT_SYMBOL(disable_irq);
  276. int m68k_irq_startup(unsigned int irq)
  277. {
  278. if (irq <= IRQ_AUTO_7)
  279. vectors[VEC_SPUR + irq] = auto_inthandler;
  280. else
  281. vectors[m68k_first_user_vec + irq - IRQ_USER] = user_inthandler;
  282. return 0;
  283. }
  284. void m68k_irq_shutdown(unsigned int irq)
  285. {
  286. if (irq <= IRQ_AUTO_7)
  287. vectors[VEC_SPUR + irq] = bad_inthandler;
  288. else
  289. vectors[m68k_first_user_vec + irq - IRQ_USER] = bad_inthandler;
  290. }
  291. /*
  292. * Do we need these probe functions on the m68k?
  293. *
  294. * ... may be useful with ISA devices
  295. */
  296. unsigned long probe_irq_on (void)
  297. {
  298. #ifdef CONFIG_Q40
  299. if (MACH_IS_Q40)
  300. return q40_probe_irq_on();
  301. #endif
  302. return 0;
  303. }
  304. EXPORT_SYMBOL(probe_irq_on);
  305. int probe_irq_off (unsigned long irqs)
  306. {
  307. #ifdef CONFIG_Q40
  308. if (MACH_IS_Q40)
  309. return q40_probe_irq_off(irqs);
  310. #endif
  311. return 0;
  312. }
  313. EXPORT_SYMBOL(probe_irq_off);
  314. unsigned int irq_canonicalize(unsigned int irq)
  315. {
  316. #ifdef CONFIG_Q40
  317. if (MACH_IS_Q40 && irq == 11)
  318. irq = 10;
  319. #endif
  320. return irq;
  321. }
  322. EXPORT_SYMBOL(irq_canonicalize);
  323. asmlinkage void m68k_handle_int(unsigned int irq)
  324. {
  325. struct irq_node *node;
  326. kstat_cpu(0).irqs[irq]++;
  327. node = irq_list[irq];
  328. do {
  329. node->handler(irq, node->dev_id);
  330. node = node->next;
  331. } while (node);
  332. }
  333. asmlinkage void __m68k_handle_int(unsigned int irq, struct pt_regs *regs)
  334. {
  335. struct pt_regs *old_regs;
  336. old_regs = set_irq_regs(regs);
  337. m68k_handle_int(irq);
  338. set_irq_regs(old_regs);
  339. }
  340. asmlinkage void handle_badint(struct pt_regs *regs)
  341. {
  342. kstat_cpu(0).irqs[0]++;
  343. printk("unexpected interrupt from %u\n", regs->vector);
  344. }
  345. int show_interrupts(struct seq_file *p, void *v)
  346. {
  347. struct irq_controller *contr;
  348. struct irq_node *node;
  349. int i = *(loff_t *) v;
  350. /* autovector interrupts */
  351. if (irq_list[i]) {
  352. contr = irq_controller[i];
  353. node = irq_list[i];
  354. seq_printf(p, "%-8s %3u: %10u %s", contr->name, i, kstat_cpu(0).irqs[i], node->devname);
  355. while ((node = node->next))
  356. seq_printf(p, ", %s", node->devname);
  357. seq_puts(p, "\n");
  358. }
  359. return 0;
  360. }
  361. void init_irq_proc(void)
  362. {
  363. /* Insert /proc/irq driver here */
  364. }