ints.c 9.3 KB

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