gt-irq.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *
  3.  * Copyright 2002 Momentum Computer
  4.  * Author: mdharm@momenco.com
  5.  *
  6.  * arch/mips/momentum/ocelot_g/gt_irq.c
  7.  *     Interrupt routines for gt64240.  Currently it only handles timer irq.
  8.  *
  9.  * This program is free software; you can redistribute  it and/or modify it
  10.  * under  the terms of  the GNU General  Public License as published by the
  11.  * Free Software Foundation;  either version 2 of the  License, or (at your
  12.  * option) any later version.
  13.  */
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <asm/ptrace.h>
  18. #include <linux/config.h>
  19. #include <linux/sched.h>
  20. #include <linux/kernel_stat.h>
  21. #include <asm/io.h>
  22. #include "gt64240.h"
  23. unsigned long bus_clock;
  24. /*
  25.  * These are interrupt handlers for the GT on-chip interrupts.  They
  26.  * all come in to the MIPS on a single interrupt line, and have to
  27.  * be handled and ack'ed differently than other MIPS interrupts.
  28.  */
  29. #if CURRENTLY_UNUSED
  30. struct tq_struct irq_handlers[MAX_CAUSE_REGS][MAX_CAUSE_REG_WIDTH];
  31. void hook_irq_handler(int int_cause, int bit_num, void *isr_ptr);
  32. /*
  33.  * Hooks IRQ handler to the system. When the system is interrupted
  34.  * the interrupt service routine is called.
  35.  *
  36.  * Inputs :
  37.  * int_cause - The interrupt cause number. In EVB64120 two parameters
  38.  *             are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
  39.  * bit_num   - Indicates which bit number in the cause register
  40.  * isr_ptr   - Pointer to the interrupt service routine
  41.  */
  42. void hook_irq_handler(int int_cause, int bit_num, void *isr_ptr)
  43. {
  44. irq_handlers[int_cause][bit_num].routine = isr_ptr;
  45. }
  46. /*
  47.  * Enables the IRQ on Galileo Chip
  48.  *
  49.  * Inputs :
  50.  * int_cause - The interrupt cause number. In EVB64120 two parameters
  51.  *             are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
  52.  * bit_num   - Indicates which bit number in the cause register
  53.  *
  54.  * Outputs :
  55.  * 1 if succesful, 0 if failure
  56.  */
  57. int enable_galileo_irq(int int_cause, int bit_num)
  58. {
  59. if (int_cause == INT_CAUSE_MAIN)
  60. SET_REG_BITS(CPU_INTERRUPT_MASK_REGISTER, (1 << bit_num));
  61. else if (int_cause == INT_CAUSE_HIGH)
  62. SET_REG_BITS(CPU_HIGH_INTERRUPT_MASK_REGISTER,
  63.      (1 << bit_num));
  64. else
  65. return 0;
  66. return 1;
  67. }
  68. /*
  69.  * Disables the IRQ on Galileo Chip
  70.  *
  71.  * Inputs :
  72.  * int_cause - The interrupt cause number. In EVB64120 two parameters
  73.  *             are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
  74.  * bit_num   - Indicates which bit number in the cause register
  75.  *
  76.  * Outputs :
  77.  * 1 if succesful, 0 if failure
  78.  */
  79. int disable_galileo_irq(int int_cause, int bit_num)
  80. {
  81. if (int_cause == INT_CAUSE_MAIN)
  82. RESET_REG_BITS(CPU_INTERRUPT_MASK_REGISTER,
  83.        (1 << bit_num));
  84. else if (int_cause == INT_CAUSE_HIGH)
  85. RESET_REG_BITS(CPU_HIGH_INTERRUPT_MASK_REGISTER,
  86.        (1 << bit_num));
  87. else
  88. return 0;
  89. return 1;
  90. }
  91. #endif /*  UNUSED  */
  92. /*
  93.  * Interrupt handler for interrupts coming from the Galileo chip via P0_INT#.
  94.  *
  95.  * We route the timer interrupt to P0_INT# (IRQ 6), and that's all this
  96.  * routine can handle, for now.
  97.  *
  98.  * In the future, we'll route more interrupts to this pin, and that's why
  99.  * we keep this particular structure in the function.
  100.  */
  101. static void gt64240_p0int_irq(int irq, void *dev_id, struct pt_regs *regs)
  102. {
  103. uint32_t irq_src, irq_src_mask;
  104. int handled;
  105. /* get the low interrupt cause register */
  106. GT_READ(LOW_INTERRUPT_CAUSE_REGISTER, &irq_src);
  107. /* get the mask register for this pin */
  108. GT_READ(PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, &irq_src_mask);
  109. /* mask off only the interrupts we're interested in */
  110. irq_src = irq_src & irq_src_mask;
  111. handled = 0;
  112. /* Check for timer interrupt */
  113. if (irq_src & 0x00000100) {
  114. handled = 1;
  115. irq_src &= ~0x00000100;
  116. /* Clear any pending cause bits */
  117. GT_WRITE(TIMER_COUNTER_0_3_INTERRUPT_CAUSE, 0x0);
  118. /* handle the timer call */
  119. do_timer(regs);
  120. }
  121. if (irq_src) {
  122. printk(KERN_INFO
  123.        "UNKNOWN P0_INT# interrupt received, irq_src=0x%xn",
  124.        irq_src);
  125. }
  126. }
  127. /*
  128.  * Interrupt handler for interrupts coming from the Galileo chip.
  129.  * It could be built in ethernet ports etc...
  130.  */
  131. static void gt64240_irq(int irq, void *dev_id, struct pt_regs *regs)
  132. {
  133. unsigned int irq_src, int_high_src, irq_src_mask,
  134.     int_high_src_mask;
  135. int handled;
  136. #if 0
  137. GT_READ(GT_INTRCAUSE_OFS, &irq_src);
  138. GT_READ(GT_INTRMASK_OFS, &irq_src_mask);
  139. GT_READ(GT_HINTRCAUSE_OFS, &int_high_src);
  140. GT_READ(GT_HINTRMASK_OFS, &int_high_src_mask);
  141. #endif
  142. irq_src = irq_src & irq_src_mask;
  143. int_high_src = int_high_src & int_high_src_mask;
  144. handled = 0;
  145. /* Execute all interrupt handlers */
  146. /* Check for timer interrupt */
  147. if (irq_src & 0x00000800) {
  148. handled = 1;
  149. irq_src &= ~0x00000800;
  150. //    RESET_REG_BITS (INTERRUPT_CAUSE_REGISTER,BIT8);
  151. do_timer(regs);
  152. }
  153. if (irq_src) {
  154. printk(KERN_INFO
  155.        "Other Galileo interrupt received irq_src %xn",
  156.        irq_src);
  157. #if CURRENTLY_UNUSED
  158. for (count = 0; count < MAX_CAUSE_REG_WIDTH; count++) {
  159. if (irq_src & (1 << count)) {
  160. if (irq_handlers[INT_CAUSE_MAIN][count].
  161.     routine) {
  162. queue_task(&irq_handlers
  163.    [INT_CAUSE_MAIN][count],
  164.    &tq_immediate);
  165. mark_bh(IMMEDIATE_BH);
  166. handled = 1;
  167. }
  168. }
  169. }
  170. #endif /*  UNUSED  */
  171. }
  172. #if 0
  173. GT_WRITE(GT_INTRCAUSE_OFS, 0);
  174. GT_WRITE(GT_HINTRCAUSE_OFS, 0);
  175. #endif
  176. #undef GALILEO_I2O
  177. #ifdef GALILEO_I2O
  178. /*
  179.  * Future I2O support.  We currently attach I2O interrupt handlers to
  180.  * the Galileo interrupt (int 4) and handle them in do_IRQ.
  181.  */
  182. if (isInBoundDoorBellInterruptSet()) {
  183. printk(KERN_INFO "I2O doorbell interrupt received.n");
  184. handled = 1;
  185. }
  186. if (isInBoundPostQueueInterruptSet()) {
  187. printk(KERN_INFO "I2O Queue interrupt received.n");
  188. handled = 1;
  189. }
  190. /*
  191.  * This normally would be outside of the ifdef, but since we're
  192.  * handling I2O outside of this handler, this printk shows up every
  193.  * time we get a valid I2O interrupt.  So turn this off for now.
  194.  */
  195. if (handled == 0) {
  196. if (counter < 50) {
  197. printk("Spurious Galileo interrupt...n");
  198. counter++;
  199. }
  200. }
  201. #endif
  202. }
  203. /*
  204.  * Initializes timer using galileo's built in timer.
  205.  */
  206. /*
  207.  * This will ignore the standard MIPS timer interrupt handler
  208.  * that is passed in as *irq (=irq0 in ../kernel/time.c).
  209.  * We will do our own timer interrupt handling.
  210.  */
  211. void gt64240_time_init(void)
  212. {
  213. extern irq_desc_t irq_desc[NR_IRQS];
  214. static struct irqaction timer;
  215. /* Stop the timer -- we'll use timer #0 */
  216. GT_WRITE(TIMER_COUNTER_0_3_CONTROL, 0x0);
  217. /* Load timer value for 100 Hz */
  218. GT_WRITE(TIMER_COUNTER0, bus_clock / 100);
  219. /*
  220.  * Create the IRQ structure entry for the timer.  Since we're too early
  221.  * in the boot process to use the "request_irq()" call, we'll hard-code
  222.  * the values to the correct interrupt line.
  223.  */
  224. timer.handler = &gt64240_p0int_irq;
  225. timer.flags = SA_SHIRQ | SA_INTERRUPT;
  226. timer.name = "timer";
  227. timer.dev_id = NULL;
  228. timer.next = NULL;
  229. timer.mask = 0;
  230. irq_desc[6].action = &timer;
  231. enable_irq(6);
  232. /* Clear any pending cause bits */
  233. GT_WRITE(TIMER_COUNTER_0_3_INTERRUPT_CAUSE, 0x0);
  234. /* Enable the interrupt for timer 0 */
  235. GT_WRITE(TIMER_COUNTER_0_3_INTERRUPT_MASK, 0x1);
  236. /* Enable the timer interrupt for GT-64240 pin P0_INT# */
  237. GT_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0x100);
  238. /* Configure and start the timer */
  239. GT_WRITE(TIMER_COUNTER_0_3_CONTROL, 0x3);
  240. }
  241. void gt64240_irq_init(void)
  242. {
  243. #if CURRENTLY_UNUSED
  244. int i, j;
  245. /* Reset irq handlers pointers to NULL */
  246. for (i = 0; i < MAX_CAUSE_REGS; i++) {
  247. for (j = 0; j < MAX_CAUSE_REG_WIDTH; j++) {
  248. irq_handlers[i][j].next = NULL;
  249. irq_handlers[i][j].sync = 0;
  250. irq_handlers[i][j].routine = NULL;
  251. irq_handlers[i][j].data = NULL;
  252. }
  253. }
  254. #endif
  255. }