PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src/linux/linux/arch/cris/kernel/irq.c

https://github.com/SgtPepperKSU/TomatoVPN
C | 497 lines | 315 code | 86 blank | 96 comment | 33 complexity | 0e0c7136cd6784b893407a98bb3730fd MD5 | raw file
  1. /* $Id: irq.c,v 1.1.1.4 2003/10/14 08:07:17 sparq Exp $
  2. *
  3. * linux/arch/cris/kernel/irq.c
  4. *
  5. * Copyright (c) 2000,2001 Axis Communications AB
  6. *
  7. * Authors: Bjorn Wesen (bjornw@axis.com)
  8. *
  9. * This file contains the code used by various IRQ handling routines:
  10. * asking for different IRQ's should be done through these routines
  11. * instead of just grabbing them. Thus setups with different IRQ numbers
  12. * shouldn't result in any weird surprises, and installing new handlers
  13. * should be easier.
  14. *
  15. * Notice Linux/CRIS: these routines do not care about SMP
  16. *
  17. */
  18. /*
  19. * IRQ's are in fact implemented a bit like signal handlers for the kernel.
  20. * Naturally it's not a 1:1 relation, but there are similarities.
  21. */
  22. #include <linux/config.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/errno.h>
  25. #include <linux/kernel_stat.h>
  26. #include <linux/signal.h>
  27. #include <linux/sched.h>
  28. #include <linux/ioport.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/timex.h>
  31. #include <linux/slab.h>
  32. #include <linux/random.h>
  33. #include <linux/init.h>
  34. #include <asm/system.h>
  35. #include <asm/io.h>
  36. #include <asm/irq.h>
  37. #include <asm/bitops.h>
  38. #include <asm/svinto.h>
  39. char *hw_bp_msg = "BP 0x%x\n";
  40. static inline void
  41. mask_irq(unsigned int irq_nr)
  42. {
  43. *R_VECT_MASK_CLR = 1 << irq_nr;
  44. }
  45. static inline void
  46. unmask_irq(unsigned int irq_nr)
  47. {
  48. *R_VECT_MASK_SET = 1 << irq_nr;
  49. }
  50. void
  51. disable_irq(unsigned int irq_nr)
  52. {
  53. unsigned long flags;
  54. save_flags(flags);
  55. cli();
  56. mask_irq(irq_nr);
  57. restore_flags(flags);
  58. }
  59. void
  60. enable_irq(unsigned int irq_nr)
  61. {
  62. unsigned long flags;
  63. save_flags(flags);
  64. cli();
  65. unmask_irq(irq_nr);
  66. restore_flags(flags);
  67. }
  68. unsigned long
  69. probe_irq_on()
  70. {
  71. return 0;
  72. }
  73. int
  74. probe_irq_off(unsigned long x)
  75. {
  76. return 0;
  77. }
  78. irqvectptr irq_shortcuts[NR_IRQS]; /* vector of shortcut jumps after the irq prologue */
  79. /* don't use set_int_vector, it bypasses the linux interrupt handlers. it is
  80. * global just so that the kernel gdb can use it.
  81. */
  82. void
  83. set_int_vector(int n, irqvectptr addr, irqvectptr saddr)
  84. {
  85. /* remember the shortcut entry point, after the prologue */
  86. irq_shortcuts[n] = saddr;
  87. etrax_irv->v[n + 0x20] = (irqvectptr)addr;
  88. }
  89. /* the breakpoint vector is obviously not made just like the normal irq handlers
  90. * but needs to contain _code_ to jump to addr.
  91. *
  92. * the BREAK n instruction jumps to IBR + n * 8
  93. */
  94. void
  95. set_break_vector(int n, irqvectptr addr)
  96. {
  97. unsigned short *jinstr = (unsigned short *)&etrax_irv->v[n*2];
  98. unsigned long *jaddr = (unsigned long *)(jinstr + 1);
  99. /* if you don't know what this does, do not touch it! */
  100. *jinstr = 0x0d3f;
  101. *jaddr = (unsigned long)addr;
  102. /* 00000026 <clrlop+1a> 3f0d82000000 jump 0x82 */
  103. }
  104. /*
  105. * This builds up the IRQ handler stubs using some ugly macros in irq.h
  106. *
  107. * These macros create the low-level assembly IRQ routines that do all
  108. * the operations that are needed. They are also written to be fast - and to
  109. * disable interrupts as little as humanly possible.
  110. *
  111. */
  112. /* IRQ0 and 1 are special traps */
  113. void hwbreakpoint(void);
  114. void IRQ1_interrupt(void);
  115. BUILD_TIMER_IRQ(2, 0x04) /* the timer interrupt is somewhat special */
  116. BUILD_IRQ(3, 0x08)
  117. BUILD_IRQ(4, 0x10)
  118. BUILD_IRQ(5, 0x20)
  119. BUILD_IRQ(6, 0x40)
  120. BUILD_IRQ(7, 0x80)
  121. BUILD_IRQ(8, 0x100)
  122. BUILD_IRQ(9, 0x200)
  123. BUILD_IRQ(10, 0x400)
  124. BUILD_IRQ(11, 0x800)
  125. BUILD_IRQ(12, 0x1000)
  126. BUILD_IRQ(13, 0x2000)
  127. void mmu_bus_fault(void); /* IRQ 14 is the bus fault interrupt */
  128. void multiple_interrupt(void); /* IRQ 15 is the multiple IRQ interrupt */
  129. BUILD_IRQ(16, 0x10000)
  130. BUILD_IRQ(17, 0x20000)
  131. BUILD_IRQ(18, 0x40000)
  132. BUILD_IRQ(19, 0x80000)
  133. BUILD_IRQ(20, 0x100000)
  134. BUILD_IRQ(21, 0x200000)
  135. BUILD_IRQ(22, 0x400000)
  136. BUILD_IRQ(23, 0x800000)
  137. BUILD_IRQ(24, 0x1000000)
  138. BUILD_IRQ(25, 0x2000000)
  139. /* IRQ 26-30 are reserved */
  140. BUILD_IRQ(31, 0x80000000)
  141. /*
  142. * Pointers to the low-level handlers
  143. */
  144. static void (*interrupt[NR_IRQS])(void) = {
  145. NULL, NULL, IRQ2_interrupt, IRQ3_interrupt,
  146. IRQ4_interrupt, IRQ5_interrupt, IRQ6_interrupt, IRQ7_interrupt,
  147. IRQ8_interrupt, IRQ9_interrupt, IRQ10_interrupt, IRQ11_interrupt,
  148. IRQ12_interrupt, IRQ13_interrupt, NULL, NULL,
  149. IRQ16_interrupt, IRQ17_interrupt, IRQ18_interrupt, IRQ19_interrupt,
  150. IRQ20_interrupt, IRQ21_interrupt, IRQ22_interrupt, IRQ23_interrupt,
  151. IRQ24_interrupt, IRQ25_interrupt, NULL, NULL, NULL, NULL, NULL,
  152. IRQ31_interrupt
  153. };
  154. static void (*sinterrupt[NR_IRQS])(void) = {
  155. NULL, NULL, sIRQ2_interrupt, sIRQ3_interrupt,
  156. sIRQ4_interrupt, sIRQ5_interrupt, sIRQ6_interrupt, sIRQ7_interrupt,
  157. sIRQ8_interrupt, sIRQ9_interrupt, sIRQ10_interrupt, sIRQ11_interrupt,
  158. sIRQ12_interrupt, sIRQ13_interrupt, NULL, NULL,
  159. sIRQ16_interrupt, sIRQ17_interrupt, sIRQ18_interrupt, sIRQ19_interrupt,
  160. sIRQ20_interrupt, sIRQ21_interrupt, sIRQ22_interrupt, sIRQ23_interrupt,
  161. sIRQ24_interrupt, sIRQ25_interrupt, NULL, NULL, NULL, NULL, NULL,
  162. sIRQ31_interrupt
  163. };
  164. static void (*bad_interrupt[NR_IRQS])(void) = {
  165. NULL, NULL,
  166. NULL, bad_IRQ3_interrupt,
  167. bad_IRQ4_interrupt, bad_IRQ5_interrupt,
  168. bad_IRQ6_interrupt, bad_IRQ7_interrupt,
  169. bad_IRQ8_interrupt, bad_IRQ9_interrupt,
  170. bad_IRQ10_interrupt, bad_IRQ11_interrupt,
  171. bad_IRQ12_interrupt, bad_IRQ13_interrupt,
  172. NULL, NULL,
  173. bad_IRQ16_interrupt, bad_IRQ17_interrupt,
  174. bad_IRQ18_interrupt, bad_IRQ19_interrupt,
  175. bad_IRQ20_interrupt, bad_IRQ21_interrupt,
  176. bad_IRQ22_interrupt, bad_IRQ23_interrupt,
  177. bad_IRQ24_interrupt, bad_IRQ25_interrupt,
  178. NULL, NULL, NULL, NULL, NULL,
  179. bad_IRQ31_interrupt
  180. };
  181. /*
  182. * Initial irq handlers.
  183. */
  184. static struct irqaction *irq_action[NR_IRQS] = {
  185. NULL, NULL, NULL, NULL,
  186. NULL, NULL, NULL, NULL,
  187. NULL, NULL, NULL, NULL,
  188. NULL, NULL, NULL, NULL,
  189. NULL, NULL, NULL, NULL,
  190. NULL, NULL, NULL, NULL,
  191. NULL, NULL, NULL, NULL,
  192. NULL, NULL, NULL, NULL
  193. };
  194. int get_irq_list(char *buf)
  195. {
  196. int i, len = 0;
  197. struct irqaction * action;
  198. for (i = 0; i < NR_IRQS; i++) {
  199. action = irq_action[i];
  200. if (!action)
  201. continue;
  202. len += sprintf(buf+len, "%2d: %10u %c %s",
  203. i, kstat.irqs[0][i],
  204. (action->flags & SA_INTERRUPT) ? '+' : ' ',
  205. action->name);
  206. for (action = action->next; action; action = action->next) {
  207. len += sprintf(buf+len, ",%s %s",
  208. (action->flags & SA_INTERRUPT) ? " +" : "",
  209. action->name);
  210. }
  211. len += sprintf(buf+len, "\n");
  212. }
  213. return len;
  214. }
  215. /* called by the assembler IRQ entry functions defined in irq.h
  216. * to dispatch the interrupts to registred handlers
  217. * interrupts are disabled upon entry - depending on if the
  218. * interrupt was registred with SA_INTERRUPT or not, interrupts
  219. * are re-enabled or not.
  220. */
  221. asmlinkage void do_IRQ(int irq, struct pt_regs * regs)
  222. {
  223. struct irqaction *action;
  224. int do_random, cpu;
  225. cpu = smp_processor_id();
  226. irq_enter(cpu);
  227. kstat.irqs[cpu][irq]++;
  228. action = irq_action[irq];
  229. if (action) {
  230. if (!(action->flags & SA_INTERRUPT))
  231. __sti();
  232. action = irq_action[irq];
  233. do_random = 0;
  234. do {
  235. do_random |= action->flags;
  236. action->handler(irq, action->dev_id, regs);
  237. action = action->next;
  238. } while (action);
  239. if (do_random & SA_SAMPLE_RANDOM)
  240. add_interrupt_randomness(irq);
  241. __cli();
  242. }
  243. irq_exit(cpu);
  244. if (softirq_pending(cpu))
  245. do_softirq();
  246. /* unmasking and bottom half handling is done magically for us. */
  247. }
  248. /* this function links in a handler into the chain of handlers for the
  249. given irq, and if the irq has never been registred, the appropriate
  250. handler is entered into the interrupt vector
  251. */
  252. int setup_etrax_irq(int irq, struct irqaction * new)
  253. {
  254. int shared = 0;
  255. struct irqaction *old, **p;
  256. unsigned long flags;
  257. p = irq_action + irq;
  258. if ((old = *p) != NULL) {
  259. /* Can't share interrupts unless both agree to */
  260. if (!(old->flags & new->flags & SA_SHIRQ))
  261. return -EBUSY;
  262. /* Can't share interrupts unless both are same type */
  263. if ((old->flags ^ new->flags) & SA_INTERRUPT)
  264. return -EBUSY;
  265. /* add new interrupt at end of irq queue */
  266. do {
  267. p = &old->next;
  268. old = *p;
  269. } while (old);
  270. shared = 1;
  271. }
  272. if (new->flags & SA_SAMPLE_RANDOM)
  273. rand_initialize_irq(irq);
  274. save_flags(flags);
  275. cli();
  276. *p = new;
  277. if (!shared) {
  278. /* if the irq wasn't registred before, enter it into the vector table
  279. and unmask it physically
  280. */
  281. set_int_vector(irq, interrupt[irq], sinterrupt[irq]);
  282. unmask_irq(irq);
  283. }
  284. restore_flags(flags);
  285. return 0;
  286. }
  287. /* this function is called by a driver to register an irq handler
  288. Valid flags:
  289. SA_INTERRUPT -> it's a fast interrupt, handler called with irq disabled and
  290. no signal checking etc is performed upon exit
  291. SA_SHIRQ -> the interrupt can be shared between different handlers, the handler
  292. is required to check if the irq was "aimed" at it explicitely
  293. SA_RANDOM -> the interrupt will add to the random generators entropy
  294. */
  295. int request_irq(unsigned int irq,
  296. void (*handler)(int, void *, struct pt_regs *),
  297. unsigned long irqflags,
  298. const char * devname,
  299. void *dev_id)
  300. {
  301. int retval;
  302. struct irqaction * action;
  303. /* interrupts 0 and 1 are hardware breakpoint and NMI and we can't support
  304. these yet. interrupt 15 is the multiple irq, it's special. */
  305. if(irq < 2 || irq == 15 || irq >= NR_IRQS)
  306. return -EINVAL;
  307. if(!handler)
  308. return -EINVAL;
  309. /* allocate and fill in a handler structure and setup the irq */
  310. action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
  311. if (!action)
  312. return -ENOMEM;
  313. action->handler = handler;
  314. action->flags = irqflags;
  315. action->mask = 0;
  316. action->name = devname;
  317. action->next = NULL;
  318. action->dev_id = dev_id;
  319. retval = setup_etrax_irq(irq, action);
  320. if (retval)
  321. kfree(action);
  322. return retval;
  323. }
  324. void free_irq(unsigned int irq, void *dev_id)
  325. {
  326. struct irqaction * action, **p;
  327. unsigned long flags;
  328. if (irq >= NR_IRQS) {
  329. printk("Trying to free IRQ%d\n",irq);
  330. return;
  331. }
  332. for (p = irq + irq_action; (action = *p) != NULL; p = &action->next) {
  333. if (action->dev_id != dev_id)
  334. continue;
  335. /* Found it - now free it */
  336. save_flags(flags);
  337. cli();
  338. *p = action->next;
  339. if (!irq_action[irq]) {
  340. mask_irq(irq);
  341. set_int_vector(irq, bad_interrupt[irq], 0);
  342. }
  343. restore_flags(flags);
  344. kfree(action);
  345. return;
  346. }
  347. printk("Trying to free free IRQ%d\n",irq);
  348. }
  349. void weird_irq(void)
  350. {
  351. __asm__("di");
  352. printk("weird irq\n");
  353. while(1);
  354. }
  355. /* init_IRQ() is called by start_kernel and is responsible for fixing IRQ masks and
  356. setting the irq vector table to point to bad_interrupt ptrs.
  357. */
  358. void system_call(void); /* from entry.S */
  359. void do_sigtrap(void); /* from entry.S */
  360. void gdb_handle_breakpoint(void); /* from entry.S */
  361. void __init
  362. init_IRQ(void)
  363. {
  364. int i;
  365. /* clear all interrupt masks */
  366. #ifndef CONFIG_SVINTO_SIM
  367. *R_IRQ_MASK0_CLR = 0xffffffff;
  368. *R_IRQ_MASK1_CLR = 0xffffffff;
  369. *R_IRQ_MASK2_CLR = 0xffffffff;
  370. #endif
  371. *R_VECT_MASK_CLR = 0xffffffff;
  372. /* clear the shortcut entry points */
  373. for(i = 0; i < NR_IRQS; i++)
  374. irq_shortcuts[i] = NULL;
  375. for (i = 0; i < 256; i++)
  376. etrax_irv->v[i] = weird_irq;
  377. /* the entries in the break vector contain actual code to be
  378. executed by the associated break handler, rather than just a jump
  379. address. therefore we need to setup a default breakpoint handler
  380. for all breakpoints */
  381. for (i = 0; i < 16; i++)
  382. set_break_vector(i, do_sigtrap);
  383. /* set all etrax irq's to the bad handlers */
  384. for (i = 2; i < NR_IRQS; i++)
  385. set_int_vector(i, bad_interrupt[i], 0);
  386. /* except IRQ 15 which is the multiple-IRQ handler on Etrax100 */
  387. set_int_vector(15, multiple_interrupt, 0);
  388. /* 0 and 1 which are special breakpoint/NMI traps */
  389. set_int_vector(0, hwbreakpoint, 0);
  390. set_int_vector(1, IRQ1_interrupt, 0);
  391. /* and irq 14 which is the mmu bus fault handler */
  392. set_int_vector(14, mmu_bus_fault, 0);
  393. /* setup the system-call trap, which is reached by BREAK 13 */
  394. set_break_vector(13, system_call);
  395. /* setup a breakpoint handler for debugging used for both user and
  396. kernel mode debugging (which is why it is not inside an ifdef
  397. CONFIG_ETRAX_KGDB) */
  398. set_break_vector(8, gdb_handle_breakpoint);
  399. #ifdef CONFIG_ETRAX_KGDB
  400. /* setup kgdb if its enabled, and break into the debugger */
  401. kgdb_init();
  402. breakpoint();
  403. #endif
  404. }
  405. #if defined(CONFIG_PROC_FS) && defined(CONFIG_SYSCTL)
  406. /* Used by other archs to show/control IRQ steering during SMP */
  407. void __init
  408. init_irq_proc(void)
  409. {
  410. }
  411. #endif