ints.c 9.8 KB

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