ints.c 10 KB

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