patch-1.3.93 linux/arch/sparc/kernel/irq.c

Next file: linux/arch/sparc/kernel/mp.S
Previous file: linux/arch/sparc/kernel/ioport.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.92/linux/arch/sparc/kernel/irq.c linux/arch/sparc/kernel/irq.c
@@ -1,4 +1,4 @@
-/*  $Id: irq.c,v 1.34 1996/02/20 07:45:04 davem Exp $
+/*  $Id: irq.c,v 1.43 1996/04/17 12:37:45 zaitcev Exp $
  *  arch/sparc/kernel/irq.c:  Interrupt request handling routines. On the
  *                            Sparc the IRQ's are basically 'cast in stone'
  *                            and you are supposed to probe the prom's device
@@ -6,9 +6,11 @@
  *
  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  *  Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
- *  Copyright (C) 1995 Pete A. Zaitcev (zaitcev@jamica.lab.ipmce.su)
+ *  Copyright (C) 1995 Pete A. Zaitcev (zaitcev@ipmce.su)
+ *  Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
  */
 
+#include <linux/config.h>
 #include <linux/ptrace.h>
 #include <linux/errno.h>
 #include <linux/linkage.h>
@@ -22,6 +24,7 @@
 #include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/psr.h>
+#include <asm/smp.h>
 #include <asm/vaddrs.h>
 #include <asm/timer.h>
 #include <asm/openprom.h>
@@ -30,146 +33,74 @@
 #include <asm/irq.h>
 #include <asm/io.h>
 
-/* Pointer to the interrupt enable byte */
-unsigned char *interrupt_enable = 0;
-struct sun4m_intregs *sun4m_interrupts;
-
-void sun4c_disable_irq(unsigned int irq_nr)
-{
-	unsigned long flags;
-	unsigned char current_mask, new_mask;
-
-	if(sparc_cpu_model != sun4c)
-		return;
-	save_flags(flags); cli();
-	current_mask = *interrupt_enable;
-	switch(irq_nr) {
-	case 1:
-		new_mask = ((current_mask) & (~(SUN4C_INT_E1)));
-		break;
-	case 8:
-		new_mask = ((current_mask) & (~(SUN4C_INT_E8)));
-		break;
-	case 10:
-		new_mask = ((current_mask) & (~(SUN4C_INT_E10)));
-		break;
-	case 14:
-		new_mask = ((current_mask) & (~(SUN4C_INT_E14)));
-		break;
-	default:
-		restore_flags(flags);
-		return;
-	}
-	*interrupt_enable = new_mask;
-	restore_flags(flags);
-}
-
-void sun4m_disable_irq(unsigned int irq_nr)
-{
-#if 0
-	printk("IRQ routines not yet written for the sun4m\n");
-	panic("disable_irq: Unsupported arch.");
-#endif
-}
-
-void disable_irq(unsigned int irq_nr)
-{
-	switch(sparc_cpu_model) {
-	case sun4c:
-		sun4c_disable_irq(irq_nr);
-		break;
-	case sun4m:
-		sun4m_disable_irq(irq_nr);
-		break;
-	default:
-		panic("disable_irq: Unsupported arch.");
-	}
-}
-
-void sun4c_enable_irq(unsigned int irq_nr)
-{
-	unsigned long flags;
-	unsigned char current_mask, new_mask;
-
-	if(sparc_cpu_model != sun4c)
-		return;
-	save_flags(flags); cli();
-	current_mask = *interrupt_enable;
-	switch(irq_nr) {
-	case 1:
-		new_mask = ((current_mask) | SUN4C_INT_E1);
-		break;
-	case 8:
-		new_mask = ((current_mask) | SUN4C_INT_E8);
-		break;
-	case 10:
-		new_mask = ((current_mask) | SUN4C_INT_E10);
-		break;
-	case 14:
-		new_mask = ((current_mask) | SUN4C_INT_E14);
-		break;
-	default:
-		restore_flags(flags);
-		return;
-	}
-	*interrupt_enable = new_mask;
-	restore_flags(flags);
-}
+/*
+ * Dave Redman (djhr@tadpole.co.uk)
+ *
+ * IRQ numbers.. These are no longer restricted to 15..
+ *
+ * this is done to enable SBUS cards and onboard IO to be masked
+ * correctly. using the interrupt level isn't good enough.
+ *
+ * For example:
+ *   A device interrupting at sbus level6 and the Floppy both come in
+ *   at IRQ11, but enabling and disabling them requires writing to
+ *   different bits in the SLAVIO/SEC.
+ *
+ * As a result of these changes sun4m machines could now support
+ * directed CPU interrupts using the existing enable/disable irq code
+ * with tweaks.
+ *
+ */
 
-void sun4m_enable_irq(unsigned int irq_nr)
+static void irq_panic(void)
 {
-#if 0
-	printk("IRQ routines not written for the sun4m yet.\n");
-	panic("IRQ unsupported arch.");
+    extern char *cputypval;
+    prom_printf("machine: %s doesn't have irq handlers defined!\n",cputypval);
+    prom_halt();
+}
+
+void (*enable_irq)(unsigned int) = (void (*)(unsigned int)) irq_panic;
+void (*disable_irq)(unsigned int) = (void (*)(unsigned int)) irq_panic;
+void (*clear_clock_irq)( void ) = irq_panic;
+void (*clear_profile_irq)( void ) = irq_panic;
+void (*load_profile_irq)( unsigned int ) =  (void (*)(unsigned int)) irq_panic;
+void (*init_timers)( void (*)(int, void *,struct pt_regs *)) =
+    (void (*)( void (*)(int, void *,struct pt_regs *))) irq_panic;
+
+#ifdef __SMP__
+void (*set_cpu_int)(int, int);
+void (*clear_cpu_int)(int, int);
+void (*set_irq_udt)(int);
 #endif
-}
-
-void enable_irq(unsigned int irq_nr)
-{
-	switch(sparc_cpu_model) {
-	case sun4c:
-		sun4c_enable_irq(irq_nr);
-		break;
-	case sun4m:
-		sun4m_enable_irq(irq_nr);
-		break;
-	default:
-		panic("IRQ unsupported arch.");
-	}
-}
 
 /*
- * Initial irq handlers.
+ * Dave Redman (djhr@tadpole.co.uk)
+ *
+ * There used to be extern calls and hard coded values here.. very sucky!
+ * instead, because some of the devices attach very early, I do something
+ * equally sucky but at least we'll never try to free statically allocated
+ * space or call kmalloc before kmalloc_init :(.
+ * 
+ * In fact its the timer10 that attaches first.. then timer14
+ * then kmalloc_init is called.. then the tty interrupts attach.
+ * hmmm....
+ *
  */
-extern void timer_interrupt(int, void *, struct pt_regs *);
-extern void rs_interrupt(int, void *, struct pt_regs *);
+#define MAX_STATIC_ALLOC	4
+static struct irqaction static_irqaction[MAX_STATIC_ALLOC];
+static int static_irq_count = 0;
 
-static struct irqaction timer_irq = {
-	timer_interrupt,
-	SA_INTERRUPT,
-	0, "timer",
-	NULL, NULL
-};
-
-static struct irqaction serial_irq = {
-	rs_interrupt,
-	SA_INTERRUPT,
-	0, "zilog serial",
-	NULL, NULL
-};
-
-static struct irqaction *irq_action[16] = {
+static struct irqaction *irq_action[NR_IRQS+1] = {
 	  NULL, NULL, NULL, NULL, NULL, NULL , NULL, NULL,
-	  NULL, NULL, &timer_irq, NULL, &serial_irq, NULL , NULL, NULL
+	  NULL, NULL, NULL, NULL, NULL, NULL , NULL, NULL
 };
 
-
 int get_irq_list(char *buf)
 {
 	int i, len = 0;
 	struct irqaction * action;
 
-	for (i = 0 ; i < 16 ; i++) {
+	for (i = 0 ; i < (NR_IRQS+1) ; i++) {
 	        action = *(i + irq_action);
 		if (!action) 
 		        continue;
@@ -189,11 +120,14 @@
 
 void free_irq(unsigned int irq, void *dev_id)
 {
-	struct irqaction * action = *(irq + irq_action);
+	struct irqaction * action;
 	struct irqaction * tmp = NULL;
         unsigned long flags;
-
-        if (irq > 14) {  /* 14 irq levels on the sparc */
+	unsigned int cpu_irq;
+	
+	cpu_irq = irq & NR_IRQS;
+	action = *(cpu_irq + irq_action);
+        if (cpu_irq > 14) {  /* 14 irq levels on the sparc */
                 printk("Trying to free bogus IRQ %d\n", irq);
                 return;
         }
@@ -214,15 +148,25 @@
 		printk("Trying to free shared IRQ%d with NULL device ID\n", irq);
 		return;
 	}
+	if (action->flags & SA_STATIC_ALLOC)
+	{
+	    /* This interrupt is marked as specially allocted
+	     * so it is a bad idea to free it.
+	     */
+	    printk("Attempt to free statically allocated IRQ%d (%s)\n",
+		   irq, action->name);
+	    return;
+	}
+	
         save_flags(flags); cli();
 	if (action && tmp)
 		tmp->next = action->next;
 	else
-		*(irq + irq_action) = action->next;
+		*(cpu_irq + irq_action) = action->next;
 
 	kfree_s(action, sizeof(struct irqaction));
 
-	if (!(*(irq + irq_action)))
+	if (!(*(cpu_irq + irq_action)))
 		disable_irq(irq);
 
         restore_flags(flags);
@@ -231,7 +175,11 @@
 void unexpected_irq(int irq, void *dev_id, struct pt_regs * regs)
 {
         int i;
-	struct irqaction * action = *(irq + irq_action);
+	struct irqaction * action;
+	unsigned int cpu_irq;
+	
+	cpu_irq = irq & NR_IRQS;
+	action = *(cpu_irq + irq_action);
 
         printk("IO device interrupt, irq = %d\n", irq);
         printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc, 
@@ -247,9 +195,15 @@
 
 void handler_irq(int irq, struct pt_regs * regs)
 {
-	struct irqaction * action = *(irq + irq_action);
-
-	kstat.interrupts[irq]++;
+	struct irqaction * action;
+	unsigned int cpu_irq;
+	
+	cpu_irq = irq & NR_IRQS;
+	action = *(cpu_irq + irq_action);
+	kstat.interrupts[cpu_irq]++;
+#if 0
+	printk("I<%d,%d,%d>", smp_processor_id(), irq, smp_proc_in_lock[smp_processor_id()]);
+#endif
 	while (action) {
 		if (!action->handler)
 			unexpected_irq(irq, action->dev_id, regs);
@@ -268,9 +222,12 @@
  */
 asmlinkage void do_IRQ(int irq, struct pt_regs * regs)
 {
-	struct irqaction * action = *(irq + irq_action);
-
-	kstat.interrupts[irq]++;
+	struct irqaction * action;
+	unsigned int cpu_irq;
+	
+	cpu_irq = irq & NR_IRQS;
+	action = *(cpu_irq + irq_action);
+	kstat.interrupts[cpu_irq]++;
 	while (action) {
 		action->handler(irq, action->dev_id, regs);
 		action = action->next;
@@ -284,7 +241,7 @@
  */
 asmlinkage void do_fast_IRQ(int irq)
 {
-	kstat.interrupts[irq]++;
+	kstat.interrupts[irq&NR_IRQS]++;
 	printk("Got FAST_IRQ number %04lx\n", (long unsigned int) irq);
 	return;
 }
@@ -292,17 +249,20 @@
 /* Fast IRQ's on the Sparc can only have one routine attached to them,
  * thus no sharing possible.
  */
-int request_fast_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
+int request_fast_irq(unsigned int irq,
+		     void (*handler)(int, void *, struct pt_regs *),
 		     unsigned long irqflags, const char *devname)
 {
 	struct irqaction *action;
 	unsigned long flags;
-
-	if(irq > 14)
+	unsigned int cpu_irq;
+	
+	cpu_irq = irq & NR_IRQS;
+	if(cpu_irq > 14)
 		return -EINVAL;
 	if(!handler)
 		return -EINVAL;
-	action = *(irq + irq_action);
+	action = *(cpu_irq + irq_action);
 	if(action) {
 		if(action->flags & SA_SHIRQ)
 			panic("Trying to register fast irq when already shared.\n");
@@ -315,20 +275,32 @@
 
 	save_flags(flags); cli();
 
-	action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
-
+	/* If this is flagged as statically allocated then we use our
+	 * private struct which is never freed.
+	 */
+	if (irqflags & SA_STATIC_ALLOC)
+	    if (static_irq_count < MAX_STATIC_ALLOC)
+		action = &static_irqaction[static_irq_count++];
+	    else
+		printk("Fast IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
+		       irq, devname);
+	
+	if (action == NULL)
+	    action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
+						 GFP_KERNEL);
+	
 	if (!action) { 
 		restore_flags(flags);
 		return -ENOMEM;
 	}
 
 	/* Dork with trap table if we get this far. */
-	sparc_ttable[SP_TRAP_IRQ1+(irq-1)].inst_one =
+	sparc_ttable[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one =
 		SPARC_BRANCH((unsigned long) handler,
 			     (unsigned long) &sparc_ttable[SP_TRAP_IRQ1+(irq-1)].inst_one);
-	sparc_ttable[SP_TRAP_IRQ1+(irq-1)].inst_two = SPARC_RD_PSR_L0;
-	sparc_ttable[SP_TRAP_IRQ1+(irq-1)].inst_three = SPARC_NOP;
-	sparc_ttable[SP_TRAP_IRQ1+(irq-1)].inst_four = SPARC_NOP;
+	sparc_ttable[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = SPARC_RD_PSR_L0;
+	sparc_ttable[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_NOP;
+	sparc_ttable[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
 
 	action->handler = handler;
 	action->flags = irqflags;
@@ -336,24 +308,28 @@
 	action->name = devname;
 	action->dev_id = NULL;
 
-	*(irq + irq_action) = action;
+	*(cpu_irq + irq_action) = action;
 
+	enable_irq(irq);
 	restore_flags(flags);
 	return 0;
 }
 
-int request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
+int request_irq(unsigned int irq,
+		void (*handler)(int, void *, struct pt_regs *),
 		unsigned long irqflags, const char * devname, void *dev_id)
 {
 	struct irqaction * action, *tmp = NULL;
 	unsigned long flags;
-
-	if(irq > 14)
+	unsigned int cpu_irq;
+	
+	cpu_irq = irq & NR_IRQS;
+	if(cpu_irq > 14)
 		return -EINVAL;
 
 	if (!handler)
 	    return -EINVAL;
-	action = *(irq + irq_action);
+	action = *(cpu_irq + irq_action);
 	if (action) {
 		if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
 			for (tmp = action; tmp->next; tmp = tmp->next);
@@ -367,8 +343,20 @@
 	}
 
 	save_flags(flags); cli();
-	action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
 
+	/* If this is flagged as statically allocated then we use our
+	 * private struct which is never freed.
+	 */
+	if (irqflags & SA_STATIC_ALLOC)
+	    if (static_irq_count < MAX_STATIC_ALLOC)
+		action = &static_irqaction[static_irq_count++];
+	    else
+		printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",irq, devname);
+	
+	if (action == NULL)
+	    action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
+						 GFP_KERNEL);
+	
 	if (!action) { 
 		restore_flags(flags);
 		return -ENOMEM;
@@ -384,7 +372,7 @@
 	if (tmp)
 		tmp->next = action;
 	else
-		*(irq + irq_action) = action;
+		*(cpu_irq + irq_action) = action;
 
 	enable_irq(irq);
 	restore_flags(flags);
@@ -404,65 +392,33 @@
   return 0;
 }
 
-void sun4c_init_IRQ(void)
-{
-	struct linux_prom_registers int_regs[2];
-	int ie_node;
-
-	ie_node = prom_searchsiblings (prom_getchild(prom_root_node),
-				       "interrupt-enable");
-	if(ie_node == 0)
-		panic("Cannot find /interrupt-enable node");
-	/* Depending on the "address" property is bad news... */
-	prom_getproperty(ie_node, "reg", (char *) int_regs, sizeof(int_regs));
-	interrupt_enable = (char *) sparc_alloc_io(int_regs[0].phys_addr, 0,
-						   int_regs[0].reg_size,
-						   "sun4c_interrupts",
-						   int_regs[0].which_io, 0x0);
-	*interrupt_enable = (SUN4C_INT_ENABLE);
-	sti();
-}
-
-void sun4m_init_IRQ(void)
-{
-	int ie_node;
-
-	struct linux_prom_registers int_regs[PROMREG_MAX];
-	int num_regs;
-
-	cli();
-	if((ie_node = prom_searchsiblings(prom_getchild(prom_root_node), "obio")) == 0 ||
-	   (ie_node = prom_getchild (ie_node)) == 0 ||
-	   (ie_node = prom_searchsiblings (ie_node, "interrupt")) == 0)
-		panic("Cannot find /obio/interrupt node\n");
-	num_regs = prom_getproperty(ie_node, "reg", (char *) int_regs,
-				    sizeof(int_regs));
-	num_regs = (num_regs/sizeof(struct linux_prom_registers));
-
-	/* Apply the obio ranges to these registers. */
-	prom_apply_obio_ranges(int_regs, num_regs);
-
-	/* Map the interrupt registers for all possible cpus. */
-	sun4m_interrupts = sparc_alloc_io(int_regs[0].phys_addr, 0,
-					  PAGE_SIZE*NCPUS, "interrupts_percpu",
-					  int_regs[0].which_io, 0x0);
-
-	/* Map the system interrupt control registers. */
-	sparc_alloc_io(int_regs[num_regs-1].phys_addr, 0,
-		       int_regs[num_regs-1].reg_size, "interrupts_system",
-		       int_regs[num_regs-1].which_io, 0x0);
-	sti();
-}
+/* djhr
+ * This could probably be made indirect too and assigned in the CPU
+ * bits of the code. That would be much nicer I think and would also
+ * fit in with the idea of being able to tune your kernel for your machine
+ * by removing unrequired machine and device support.
+ *
+ */
 
 void init_IRQ(void)
 {
+	extern void sun4c_init_IRQ( void );
+	extern void sun4m_init_IRQ( void );
+#if CONFIG_AP1000
+	extern void ap_init_IRQ(void);
+	ap_init_IRQ();
+	return;
+#endif
+    
 	switch(sparc_cpu_model) {
 	case sun4c:
 		sun4c_init_IRQ();
 		break;
+
 	case sun4m:
 		sun4m_init_IRQ();
 		break;
+
 	default:
 		prom_printf("Cannot initialize IRQ's on this Sun machine...");
 		break;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this