patch-2.1.44 linux/arch/mips/kernel/irq.c

Next file: linux/arch/mips/kernel/jazz-c.c
Previous file: linux/arch/mips/kernel/irixsig.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.43/linux/arch/mips/kernel/irq.c linux/arch/mips/kernel/irq.c
@@ -8,29 +8,20 @@
  * instead of just grabbing them. Thus setups with different IRQ numbers
  * shouldn't result in any weird surprises, and installing new handlers
  * should be easier.
- */
-
-/*
- * IRQ's are in fact implemented a bit like signal handlers for the kernel.
- * Naturally it's not a 1:1 relation, but there are similarities.
- */
-
-/*
+ *
  * Mips support by Ralf Baechle and Andreas Busse
  *
- * The Deskstation Tyne is almost completely like an IBM compatible PC with
- * another type of microprocessor. Therefore this code is almost completely
- * the same. More work needs to be done to support Acer PICA and other
- * machines.
+ * $Id: irq.c,v 1.6 1997/06/30 15:52:34 ralf Exp $
  */
-
-#include <linux/ptrace.h>
+#include <linux/config.h>
 #include <linux/errno.h>
+#include <linux/init.h>
 #include <linux/kernel_stat.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
 #include <linux/types.h>
 #include <linux/interrupt.h>
+#include <linux/ioport.h>
 #include <linux/timex.h>
 #include <linux/malloc.h>
 #include <linux/random.h>
@@ -42,51 +33,63 @@
 #include <asm/jazz.h>
 #include <asm/mipsregs.h>
 #include <asm/system.h>
-
-#define TIMER_IRQ 0                     /* Keep this in sync with time.c */
+#include <asm/vector.h>
+#ifdef CONFIG_SGI
+#include <asm/sgialib.h>
+#endif
 
 unsigned char cache_21 = 0xff;
 unsigned char cache_A1 = 0xff;
 
+unsigned int local_irq_count[NR_CPUS];
 unsigned long spurious_count = 0;
 
-void disable_irq(unsigned int irq_nr)
+/*
+ * (un)mask_irq, disable_irq() and enable_irq() only handle (E)ISA and
+ * PCI devices.  Other onboard hardware needs specific routines.
+ */
+static inline void mask_irq(unsigned int irq_nr)
 {
-	unsigned long flags;
 	unsigned char mask;
 
 	mask = 1 << (irq_nr & 7);
-	save_flags(flags);
 	if (irq_nr < 8) {
-		cli();
 		cache_21 |= mask;
 		outb(cache_21,0x21);
-		restore_flags(flags);
-		return;
+	} else {
+		cache_A1 |= mask;
+		outb(cache_A1,0xA1);
 	}
-	cli();
-	cache_A1 |= mask;
-	outb(cache_A1,0xA1);
-	restore_flags(flags);
 }
 
-void enable_irq(unsigned int irq_nr)
+static inline void unmask_irq(unsigned int irq_nr)
 {
-	unsigned long flags;
 	unsigned char mask;
 
 	mask = ~(1 << (irq_nr & 7));
-	save_flags(flags);
 	if (irq_nr < 8) {
-		cli();
 		cache_21 &= mask;
 		outb(cache_21,0x21);
-		restore_flags(flags);
-		return;
+	} else {
+		cache_A1 &= mask;
+		outb(cache_A1,0xA1);
 	}
-	cli();
-	cache_A1 &= mask;
-	outb(cache_A1,0xA1);
+}
+
+void disable_irq(unsigned int irq_nr)
+{
+	unsigned long flags;
+
+	save_and_cli(flags);
+	mask_irq(irq_nr);
+	restore_flags(flags);
+}
+
+void enable_irq(unsigned int irq_nr)
+{
+	unsigned long flags;
+	save_and_cli(flags);
+	unmask_irq(irq_nr);
 	restore_flags(flags);
 }
 
@@ -98,16 +101,11 @@
 extern void fast_interrupt(void);
 extern void bad_interrupt(void);
 
-/*
- * Initial irq handlers.
- */
-static struct irqaction timer_irq = { NULL, 0, 0, NULL, NULL, NULL};
-static struct irqaction cascade_irq = { NULL, 0, 0, NULL, NULL, NULL};
-static struct irqaction math_irq = { NULL, 0, 0, NULL, NULL, NULL};
-
-static struct irqaction *irq_action[16] = {
-	  NULL, NULL, NULL, NULL, NULL, NULL , NULL, NULL,
-	  NULL, NULL, NULL, NULL, NULL, NULL , NULL, NULL
+static struct irqaction *irq_action[32] = {
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 int get_irq_list(char *buf)
@@ -115,10 +113,10 @@
 	int i, len = 0;
 	struct irqaction * action;
 
-	for (i = 0 ; i < 16 ; i++) {
-	        action = *(i + irq_action);
+	for (i = 0 ; i < 32 ; i++) {
+		action = irq_action[i];
 		if (!action) 
-		        continue;
+			continue;
 		len += sprintf(buf+len, "%2d: %8d %c %s",
 			i, kstat.interrupts[i],
 			(action->flags & SA_INTERRUPT) ? '+' : ' ',
@@ -133,6 +131,15 @@
 	return len;
 }
 
+atomic_t __mips_bh_counter;
+
+#ifdef __SMP__
+#error Send superfluous SMP boxes to ralf@uni-koblenz.de
+#else
+#define irq_enter(cpu, irq)     (++local_irq_count[cpu])
+#define irq_exit(cpu, irq)      (--local_irq_count[cpu])
+#endif
+
 /*
  * do_IRQ handles IRQ's that have been installed without the
  * SA_INTERRUPT flag: it uses the full signal-handling return
@@ -143,14 +150,23 @@
 asmlinkage void do_IRQ(int irq, struct pt_regs * regs)
 {
 	struct irqaction * action = *(irq + irq_action);
+	int do_random, cpu = smp_processor_id();
 
+	irq_enter(cpu, irq);
 	kstat.interrupts[irq]++;
-	if (action->flags & SA_SAMPLE_RANDOM)
+
+	/* slow interrupts run with interrupts enabled */
+	sti();
+	action = *(irq + irq_action);
+	do_random = 0;
+        while (action) {
+		do_random |= action->flags;
+		action->handler(irq, action->dev_id, regs);
+		action = action->next;
+        }
+	if (do_random & SA_SAMPLE_RANDOM)
 		add_interrupt_randomness(irq);
-	while (action) {
-	    action->handler(irq, action->dev_id, regs);
-	    action = action->next;
-	}
+	irq_exit(cpu, irq);
 }
 
 /*
@@ -160,18 +176,69 @@
  */
 asmlinkage void do_fast_IRQ(int irq)
 {
-	struct irqaction * action = *(irq + irq_action);
+	struct irqaction * action;
+	int do_random, cpu = smp_processor_id();
 
+	irq_enter(cpu, irq);
 	kstat.interrupts[irq]++;
-	if (action->flags & SA_SAMPLE_RANDOM)
-		add_interrupt_randomness(irq);
+	action = *(irq + irq_action);
+	do_random = 0;
 	while (action) {
-	    action->handler(irq, action->dev_id, NULL);
-	    action = action->next;
+		do_random |= action->flags;
+		action->handler(irq, action->dev_id, NULL);
+		action = action->next;
 	}
+	if (do_random & SA_SAMPLE_RANDOM)
+		add_interrupt_randomness(irq);
+	irq_exit(cpu, irq);
 }
 
-#define SA_PROBE SA_ONESHOT
+/*
+ * Used only for setup of PC style interrupts and therefore still
+ * called setup_x86_irq.  Later on I'll provide a machine specific
+ * function with similar purpose.  Idea is to put all interrupts
+ * in a single table and differenciate them just by number.
+ */
+int setup_x86_irq(int irq, struct irqaction * new)
+{
+	int shared = 0;
+	struct irqaction *old, **p;
+	unsigned long flags;
+
+	p = irq_action + irq;
+	if ((old = *p) != NULL) {
+		/* Can't share interrupts unless both agree to */
+		if (!(old->flags & new->flags & SA_SHIRQ))
+			return -EBUSY;
+
+		/* Can't share interrupts unless both are same type */
+		if ((old->flags ^ new->flags) & SA_INTERRUPT)
+			return -EBUSY;
+
+		/* add new interrupt at end of irq queue */
+		do {
+			p = &old->next;
+			old = *p;
+		} while (old);
+		shared = 1;
+	}
+
+	if (new->flags & SA_SAMPLE_RANDOM)
+		rand_initialize_irq(irq);
+
+	save_and_cli(flags);
+	*p = new;
+
+	if (!shared) {
+		if (new->flags & SA_INTERRUPT)
+			set_int_vector(irq,fast_interrupt);
+		else
+			set_int_vector(irq,interrupt);
+		unmask_irq(irq);
+	}
+	restore_flags(flags);
+	return 0;
+}
 
 int request_irq(unsigned int irq, 
 		void (*handler)(int, void *, struct pt_regs *),
@@ -179,42 +246,17 @@
 		const char * devname,
 		void *dev_id)
 {
-	struct irqaction * action, *tmp = NULL;
-	unsigned long flags;
+	int retval;
+	struct irqaction * action;
 
-	if (irq > 15)
+	if (irq > 31)
 		return -EINVAL;
 	if (!handler)
-	    return -EINVAL;
-	action = *(irq + irq_action);
-	if (action) {
-	    if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
-		for (tmp = action; tmp->next; tmp = tmp->next);
-	    } else {
-		return -EBUSY;
-	    }
-	    if ((action->flags & SA_INTERRUPT) ^ (irqflags & SA_INTERRUPT)) {
-	      printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq);
-	      return -EBUSY;
-	    }   
-	}
-	if (irqflags & SA_SAMPLE_RANDOM)
-		rand_initialize_irq(irq);
-	save_flags(flags);
-	cli();
-	if (irq == 2)
-	    action = &cascade_irq;
-	else if (irq == 13)
-	  action = &math_irq;
-	else if (irq == TIMER_IRQ)
-	  action = &timer_irq;
-	else
-	  action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
-
-	if (!action) { 
-	    restore_flags(flags);
-	    return -ENOMEM;
-	}
+		return -EINVAL;
+
+	action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
+	if (!action)
+		return -ENOMEM;
 
 	action->handler = handler;
 	action->flags = irqflags;
@@ -223,116 +265,60 @@
 	action->next = NULL;
 	action->dev_id = dev_id;
 
-	if (tmp) {
-	    tmp->next = action;
-	} else {
-	    *(irq + irq_action) = action;
-	    if (!(action->flags & SA_PROBE)) {/* SA_ONESHOT used by probing */
-		/*
-		 * FIXME: Does the SA_INTERRUPT flag make any sense on MIPS???
-		 */
-		if (action->flags & SA_INTERRUPT)
-			set_int_vector(irq,fast_interrupt);
-		else
-			set_int_vector(irq,interrupt);
-	    }
-	    if (irq < 8) {
-		cache_21 &= ~(1<<irq);
-		outb(cache_21,0x21);
-	    } else {
-		cache_21 &= ~(1<<2);
-		cache_A1 &= ~(1<<(irq-8));
-		outb(cache_21,0x21);
-		outb(cache_A1,0xA1);
-	    }
-	}
-	restore_flags(flags);
-	return 0;
-}
+	retval = setup_x86_irq(irq, action);
 
+	if (retval)
+		kfree(action);
+	return retval;
+}
+		
 void free_irq(unsigned int irq, void *dev_id)
 {
-	struct irqaction * action = *(irq + irq_action);
-	struct irqaction * tmp = NULL;
+	struct irqaction * action, **p;
 	unsigned long flags;
 
-	if (irq > 15) {
+	if (irq > 31) {
 		printk("Trying to free IRQ%d\n",irq);
 		return;
 	}
-	if (!action->handler) {
-		printk("Trying to free free IRQ%d\n",irq);
-		return;
-	}
-	if (dev_id) {
-	    for (; action; action = action->next) {
-	        if (action->dev_id == dev_id) break;
-		tmp = action;
-	    }
-	    if (!action) {
-		printk("Trying to free free shared IRQ%d\n",irq);
+	for (p = irq + irq_action; (action = *p) != NULL; p = &action->next) {
+		if (action->dev_id != dev_id)
+			continue;
+
+		/* Found it - now free it */
+		save_and_cli(flags);
+		*p = action->next;
+		if (!irq[irq_action]) {
+			mask_irq(irq);
+			set_int_vector(irq, bad_interrupt);
+		}
+		restore_flags(flags);
+		kfree(action);
 		return;
-	    }
-	} else if (action->flags & SA_SHIRQ) {
-	    printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
-	    return;
-	}
-	save_flags(flags);
-	cli();
-	if (action && tmp) {
-	    tmp->next = action->next;
-	} else {
-	    *(irq + irq_action) = action->next;
-	}
-
-	if ((irq == 2) || (irq == 13) | (irq == TIMER_IRQ))
-	  memset(action, 0, sizeof(struct irqaction));
-	else 
-	  kfree_s(action, sizeof(struct irqaction));
-	
-	if (!(*(irq + irq_action))) {
-	    if (irq < 8) {
-		cache_21 |= 1 << irq;
-		outb(cache_21,0x21);
-	    } else {
-		cache_A1 |= 1 << (irq-8);
-		outb(cache_A1,0xA1);
-	    }
-	    set_int_vector(irq,bad_interrupt);
 	}
-	restore_flags(flags);
+	printk("Trying to free free IRQ%d\n",irq);
 }
 
-static void no_action(int cpl, void *dev_id, struct pt_regs * regs) { }
-
 unsigned long probe_irq_on (void)
 {
 	unsigned int i, irqs = 0, irqmask;
 	unsigned long delay;
 
-	/* first, snaffle up any unassigned irqs */
+	/* first, enable any unassigned (E)ISA irqs */
 	for (i = 15; i > 0; i--) {
-		if (!request_irq(i, no_action, SA_PROBE, "probe", NULL)) {
+		if (!irq_action[i]) {
 			enable_irq(i);
 			irqs |= (1 << i);
 		}
 	}
 
 	/* wait for spurious interrupts to mask themselves out again */
-	for (delay = jiffies + 2; delay > jiffies; );	/* min 10ms delay */
+	for (delay = jiffies + HZ/10; delay > jiffies; )
+		/* about 100ms delay */;
 
 	/* now filter out any obviously spurious interrupts */
 	irqmask = (((unsigned int)cache_A1)<<8) | (unsigned int)cache_21;
-	for (i = 15; i > 0; i--) {
-		if (irqs & (1 << i) & irqmask) {
-			irqs ^= (1 << i);
-			free_irq(i, NULL);
-		}
-	}
-#ifdef DEBUG
-	printk("probe_irq_on:  irqs=0x%04x irqmask=0x%04x\n", irqs, irqmask);
-#endif
-	return irqs;
+	return irqs & ~irqmask;
 }
 
 int probe_irq_off (unsigned long irqs)
@@ -340,11 +326,6 @@
 	unsigned int i, irqmask;
 
 	irqmask = (((unsigned int)cache_A1)<<8) | (unsigned int)cache_21;
-	for (i = 15; i > 0; i--) {
-		if (irqs & (1 << i)) {
-			free_irq(i, NULL);
-		}
-	}
 #ifdef DEBUG
 	printk("probe_irq_off: irqs=0x%04x irqmask=0x%04x\n", irqs, irqmask);
 #endif
@@ -357,45 +338,11 @@
 	return i;
 }
 
-void init_IRQ(void)
+__initfunc(void init_IRQ(void))
 {
 	int i;
 
-	switch (boot_info.machtype) {
-		case MACH_MIPS_MAGNUM_4000:
-		case MACH_ACER_PICA_61:
-	                r4030_write_reg16(JAZZ_IO_IRQ_ENABLE,
-					  JAZZ_IE_ETHERNET |
-					  JAZZ_IE_SERIAL1  |
-					  JAZZ_IE_SERIAL2  |
- 					  JAZZ_IE_PARALLEL |
-					  JAZZ_IE_FLOPPY);
-	                r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */
-			set_cp0_status(ST0_IM, IE_IRQ4 | IE_IRQ1);
-			/* set the clock to 100 Hz */
-			r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
-			break;
-		case MACH_DESKSTATION_TYNE:
-			/* set the clock to 100 Hz */
-			outb_p(0x34,0x43);		/* binary, mode 2, LSB/MSB, ch 0 */
-			outb_p(LATCH & 0xff , 0x40);	/* LSB */
-			outb(LATCH >> 8 , 0x40);	/* MSB */
-
-			if (request_irq(2, no_action, SA_INTERRUPT, "cascade", NULL))
-				printk("Unable to get IRQ2 for cascade\n");
-			break;
-		default:
-			panic("Unknown machtype in init_IRQ");
-	}
-
-	for (i = 0; i < 16 ; i++)
+	for (i = 0; i < 32 ; i++)
 		set_int_vector(i, bad_interrupt);
-
-	/* initialize the bottom half routines. */
-	for (i = 0; i < 32; i++) {
-		bh_base[i].routine = NULL;
-		bh_base[i].data = NULL;
-	}
-	bh_active = 0;
-	atomic_set(&intr_count, 0);
+	irq_setup();
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov