ints.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * linux/arch/$(ARCH)/platform/$(PLATFORM)/ints.c
  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. * Copyright (c) 2000 Michael Leslie <mleslie@lineo.com>
  9. * Copyright (c) 1996 Roman Zippel
  10. * Copyright (c) 1999 D. Jeff Dionne <jeff@uclinux.org>
  11. */
  12. #include <linux/config.h>
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/sched.h>
  17. #include <linux/kernel_stat.h>
  18. #include <linux/errno.h>
  19. #include <asm/system.h>
  20. #include <asm/irq.h>
  21. #include <asm/traps.h>
  22. #include <asm/io.h>
  23. #include <asm/machdep.h>
  24. #include <asm/setup.h>
  25. #include <asm/m68360.h>
  26. /* from quicc/commproc.c: */
  27. extern QUICC *pquicc;
  28. extern void cpm_interrupt_init(void);
  29. #define INTERNAL_IRQS (96)
  30. /* assembler routines */
  31. asmlinkage void system_call(void);
  32. asmlinkage void buserr(void);
  33. asmlinkage void trap(void);
  34. asmlinkage irqreturn_t bad_interrupt(void);
  35. asmlinkage irqreturn_t inthandler(void);
  36. extern void *_ramvec[];
  37. /* The number of spurious interrupts */
  38. volatile unsigned int num_spurious;
  39. unsigned int local_irq_count[NR_CPUS];
  40. /* irq node variables for the 32 (potential) on chip sources */
  41. static irq_node_t int_irq_list[INTERNAL_IRQS];
  42. static short int_irq_ablecount[INTERNAL_IRQS];
  43. /*
  44. * This function should be called during kernel startup to initialize
  45. * IRQ handling routines.
  46. */
  47. void init_IRQ(void)
  48. {
  49. int i;
  50. int vba = (CPM_VECTOR_BASE<<4);
  51. /* set up the vectors */
  52. _ramvec[2] = buserr;
  53. _ramvec[3] = trap;
  54. _ramvec[4] = trap;
  55. _ramvec[5] = trap;
  56. _ramvec[6] = trap;
  57. _ramvec[7] = trap;
  58. _ramvec[8] = trap;
  59. _ramvec[9] = trap;
  60. _ramvec[10] = trap;
  61. _ramvec[11] = trap;
  62. _ramvec[12] = trap;
  63. _ramvec[13] = trap;
  64. _ramvec[14] = trap;
  65. _ramvec[15] = trap;
  66. _ramvec[32] = system_call;
  67. _ramvec[33] = trap;
  68. cpm_interrupt_init();
  69. /* set up CICR for vector base address and irq level */
  70. /* irl = 4, hp = 1f - see MC68360UM p 7-377 */
  71. pquicc->intr_cicr = 0x00e49f00 | vba;
  72. /* CPM interrupt vectors: (p 7-376) */
  73. _ramvec[vba+CPMVEC_ERROR] = bad_interrupt; /* Error */
  74. _ramvec[vba+CPMVEC_PIO_PC11] = inthandler; /* pio - pc11 */
  75. _ramvec[vba+CPMVEC_PIO_PC10] = inthandler; /* pio - pc10 */
  76. _ramvec[vba+CPMVEC_SMC2] = inthandler; /* smc2/pip */
  77. _ramvec[vba+CPMVEC_SMC1] = inthandler; /* smc1 */
  78. _ramvec[vba+CPMVEC_SPI] = inthandler; /* spi */
  79. _ramvec[vba+CPMVEC_PIO_PC9] = inthandler; /* pio - pc9 */
  80. _ramvec[vba+CPMVEC_TIMER4] = inthandler; /* timer 4 */
  81. _ramvec[vba+CPMVEC_RESERVED1] = inthandler; /* reserved */
  82. _ramvec[vba+CPMVEC_PIO_PC8] = inthandler; /* pio - pc8 */
  83. _ramvec[vba+CPMVEC_PIO_PC7] = inthandler; /* pio - pc7 */
  84. _ramvec[vba+CPMVEC_PIO_PC6] = inthandler; /* pio - pc6 */
  85. _ramvec[vba+CPMVEC_TIMER3] = inthandler; /* timer 3 */
  86. _ramvec[vba+CPMVEC_RISCTIMER] = inthandler; /* reserved */
  87. _ramvec[vba+CPMVEC_PIO_PC5] = inthandler; /* pio - pc5 */
  88. _ramvec[vba+CPMVEC_PIO_PC4] = inthandler; /* pio - pc4 */
  89. _ramvec[vba+CPMVEC_RESERVED2] = inthandler; /* reserved */
  90. _ramvec[vba+CPMVEC_RISCTIMER] = inthandler; /* timer table */
  91. _ramvec[vba+CPMVEC_TIMER2] = inthandler; /* timer 2 */
  92. _ramvec[vba+CPMVEC_RESERVED3] = inthandler; /* reserved */
  93. _ramvec[vba+CPMVEC_IDMA2] = inthandler; /* idma 2 */
  94. _ramvec[vba+CPMVEC_IDMA1] = inthandler; /* idma 1 */
  95. _ramvec[vba+CPMVEC_SDMA_CB_ERR] = inthandler; /* sdma channel bus error */
  96. _ramvec[vba+CPMVEC_PIO_PC3] = inthandler; /* pio - pc3 */
  97. _ramvec[vba+CPMVEC_PIO_PC2] = inthandler; /* pio - pc2 */
  98. /* _ramvec[vba+CPMVEC_TIMER1] = cpm_isr_timer1; */ /* timer 1 */
  99. _ramvec[vba+CPMVEC_TIMER1] = inthandler; /* timer 1 */
  100. _ramvec[vba+CPMVEC_PIO_PC1] = inthandler; /* pio - pc1 */
  101. _ramvec[vba+CPMVEC_SCC4] = inthandler; /* scc 4 */
  102. _ramvec[vba+CPMVEC_SCC3] = inthandler; /* scc 3 */
  103. _ramvec[vba+CPMVEC_SCC2] = inthandler; /* scc 2 */
  104. _ramvec[vba+CPMVEC_SCC1] = inthandler; /* scc 1 */
  105. _ramvec[vba+CPMVEC_PIO_PC0] = inthandler; /* pio - pc0 */
  106. /* turn off all CPM interrupts */
  107. pquicc->intr_cimr = 0x00000000;
  108. /* initialize handlers */
  109. for (i = 0; i < INTERNAL_IRQS; i++) {
  110. int_irq_list[i].handler = NULL;
  111. int_irq_list[i].flags = IRQ_FLG_STD;
  112. int_irq_list[i].dev_id = NULL;
  113. int_irq_list[i].devname = NULL;
  114. }
  115. }
  116. #if 0
  117. void M68360_insert_irq(irq_node_t **list, irq_node_t *node)
  118. {
  119. unsigned long flags;
  120. irq_node_t *cur;
  121. if (!node->dev_id)
  122. printk(KERN_INFO "%s: Warning: dev_id of %s is zero\n",
  123. __FUNCTION__, node->devname);
  124. local_irq_save(flags);
  125. cur = *list;
  126. while (cur) {
  127. list = &cur->next;
  128. cur = cur->next;
  129. }
  130. node->next = cur;
  131. *list = node;
  132. local_irq_restore(flags);
  133. }
  134. void M68360_delete_irq(irq_node_t **list, void *dev_id)
  135. {
  136. unsigned long flags;
  137. irq_node_t *node;
  138. local_irq_save(flags);
  139. for (node = *list; node; list = &node->next, node = *list) {
  140. if (node->dev_id == dev_id) {
  141. *list = node->next;
  142. /* Mark it as free. */
  143. node->handler = NULL;
  144. local_irq_restore(flags);
  145. return;
  146. }
  147. }
  148. local_irq_restore(flags);
  149. printk (KERN_INFO "%s: tried to remove invalid irq\n", __FUNCTION__);
  150. }
  151. #endif
  152. int request_irq(
  153. unsigned int irq,
  154. irqreturn_t (*handler)(int, void *, struct pt_regs *),
  155. unsigned long flags,
  156. const char *devname,
  157. void *dev_id)
  158. {
  159. int mask = (1<<irq);
  160. irq += (CPM_VECTOR_BASE<<4);
  161. if (irq >= INTERNAL_IRQS) {
  162. printk (KERN_ERR "%s: Unknown IRQ %d from %s\n", __FUNCTION__, irq, devname);
  163. return -ENXIO;
  164. }
  165. if (!(int_irq_list[irq].flags & IRQ_FLG_STD)) {
  166. if (int_irq_list[irq].flags & IRQ_FLG_LOCK) {
  167. printk(KERN_ERR "%s: IRQ %d from %s is not replaceable\n",
  168. __FUNCTION__, irq, int_irq_list[irq].devname);
  169. return -EBUSY;
  170. }
  171. if (flags & IRQ_FLG_REPLACE) {
  172. printk(KERN_ERR "%s: %s can't replace IRQ %d from %s\n",
  173. __FUNCTION__, devname, irq, int_irq_list[irq].devname);
  174. return -EBUSY;
  175. }
  176. }
  177. int_irq_list[irq].handler = handler;
  178. int_irq_list[irq].flags = flags;
  179. int_irq_list[irq].dev_id = dev_id;
  180. int_irq_list[irq].devname = devname;
  181. /* enable in the CIMR */
  182. if (!int_irq_ablecount[irq])
  183. pquicc->intr_cimr |= mask;
  184. /* *(volatile unsigned long *)0xfffff304 &= ~(1<<irq); */
  185. return 0;
  186. }
  187. EXPORT_SYMBOL(request_irq);
  188. void free_irq(unsigned int irq, void *dev_id)
  189. {
  190. if (irq >= INTERNAL_IRQS) {
  191. printk (KERN_ERR "%s: Unknown IRQ %d\n", __FUNCTION__, irq);
  192. return;
  193. }
  194. if (int_irq_list[irq].dev_id != dev_id)
  195. printk(KERN_INFO "%s: removing probably wrong IRQ %d from %s\n",
  196. __FUNCTION__, irq, int_irq_list[irq].devname);
  197. int_irq_list[irq].handler = NULL;
  198. int_irq_list[irq].flags = IRQ_FLG_STD;
  199. int_irq_list[irq].dev_id = NULL;
  200. int_irq_list[irq].devname = NULL;
  201. *(volatile unsigned long *)0xfffff304 |= 1<<irq;
  202. }
  203. EXPORT_SYMBOL(free_irq);
  204. #if 0
  205. /*
  206. * Enable/disable a particular machine specific interrupt source.
  207. * Note that this may affect other interrupts in case of a shared interrupt.
  208. * This function should only be called for a _very_ short time to change some
  209. * internal data, that may not be changed by the interrupt at the same time.
  210. * int_(enable|disable)_irq calls may also be nested.
  211. */
  212. void M68360_enable_irq(unsigned int irq)
  213. {
  214. if (irq >= INTERNAL_IRQS) {
  215. printk(KERN_ERR "%s: Unknown IRQ %d\n", __FUNCTION__, irq);
  216. return;
  217. }
  218. if (--int_irq_ablecount[irq])
  219. return;
  220. /* enable the interrupt */
  221. *(volatile unsigned long *)0xfffff304 &= ~(1<<irq);
  222. }
  223. void M68360_disable_irq(unsigned int irq)
  224. {
  225. if (irq >= INTERNAL_IRQS) {
  226. printk(KERN_ERR "%s: Unknown IRQ %d\n", __FUNCTION__, irq);
  227. return;
  228. }
  229. if (int_irq_ablecount[irq]++)
  230. return;
  231. /* disable the interrupt */
  232. *(volatile unsigned long *)0xfffff304 |= 1<<irq;
  233. }
  234. #endif
  235. int show_interrupts(struct seq_file *p, void *v)
  236. {
  237. int i = *(loff_t *) v;
  238. if (i < NR_IRQS) {
  239. if (int_irq_list[i].devname) {
  240. seq_printf(p, "%3d: %10u ", i, kstat_cpu(0).irqs[i]);
  241. if (int_irq_list[i].flags & IRQ_FLG_LOCK)
  242. seq_printf(p, "L ");
  243. else
  244. seq_printf(p, " ");
  245. seq_printf(p, "%s\n", int_irq_list[i].devname);
  246. }
  247. }
  248. if (i == NR_IRQS)
  249. seq_printf(p, " : %10u spurious\n", num_spurious);
  250. return 0;
  251. }
  252. /* The 68k family did not have a good way to determine the source
  253. * of interrupts until later in the family. The EC000 core does
  254. * not provide the vector number on the stack, we vector everything
  255. * into one vector and look in the blasted mask register...
  256. * This code is designed to be fast, almost constant time, not clean!
  257. */
  258. void process_int(int vec, struct pt_regs *fp)
  259. {
  260. int irq;
  261. int mask;
  262. /* unsigned long pend = *(volatile unsigned long *)0xfffff30c; */
  263. /* irq = vec + (CPM_VECTOR_BASE<<4); */
  264. irq = vec;
  265. /* unsigned long pend = *(volatile unsigned long *)pquicc->intr_cipr; */
  266. /* Bugger all that weirdness. For the moment, I seem to know where I came from;
  267. * vec is passed from a specific ISR, so I'll use it. */
  268. if (int_irq_list[irq].handler) {
  269. int_irq_list[irq].handler(irq , int_irq_list[irq].dev_id, fp);
  270. kstat_cpu(0).irqs[irq]++;
  271. pquicc->intr_cisr = (1 << vec); /* indicate that irq has been serviced */
  272. } else {
  273. printk(KERN_ERR "unregistered interrupt %d!\nTurning it off in the CIMR...\n", irq);
  274. /* *(volatile unsigned long *)0xfffff304 |= mask; */
  275. pquicc->intr_cimr &= ~(1 << vec);
  276. num_spurious += 1;
  277. }
  278. return(IRQ_HANDLED);
  279. }