Index: linux/2.4/MAINTAINERS
diff -u linux/2.4/MAINTAINERS:1.1.1.11 linux/2.4/MAINTAINERS:1.1.1.11.2.1
--- linux/2.4/MAINTAINERS:1.1.1.11	Sat Mar 31 15:43:47 2001
+++ linux/2.4/MAINTAINERS	Sat Mar 31 16:41:00 2001
@@ -742,6 +742,12 @@
 L:	linux-x25@vger.kernel.org
 S:	Maintained
 
+LINUX FOR NCR VOYAGER
+P:	James Bottomley
+M:	J.E.J.Bottomley@HansenPartnership.com
+W:	http://www.hansenpartnership.com/voyager
+S:	Maintained
+
 LINUX FOR POWERPC
 P:	Cort Dougan
 M:	cort@fsmlabs.com
Index: linux/2.4/Documentation/Configure.help
diff -u linux/2.4/Documentation/Configure.help:1.1.1.11 linux/2.4/Documentation/Configure.help:1.1.1.11.2.1
--- linux/2.4/Documentation/Configure.help:1.1.1.11	Sat Mar 31 15:47:43 2001
+++ linux/2.4/Documentation/Configure.help	Sat Mar 31 16:41:00 2001
@@ -2621,6 +2621,16 @@
 
   Otherwise, say N.
 
+Support for the NCR Voyager Architecture
+CONFIG_VOYAGER
+  Voyager is a MCA based 32 way capable SMP architecture proprietary
+  to NCR Corp.  Machine classes 345x/35xx/51xx are voyager based.
+  
+  *** WARNING ***
+
+  If you do not specifically know you have a Voyager based machine,
+  say N here otherwise the kernel you build will not be bootable.
+
 SGI Visual Workstation support
 CONFIG_VISWS
   The SGI Visual Workstation series is an IA32-based workstation
Index: linux/2.4/Documentation/voyager.txt
diff -u /dev/null linux/2.4/Documentation/voyager.txt:1.1.12.1
--- /dev/null	Sun Apr 29 10:15:28 2001
+++ linux/2.4/Documentation/voyager.txt	Sat Mar 31 16:41:01 2001
@@ -0,0 +1,84 @@
+Running Linux on the Voyager Architecture
+=========================================
+
+For full details and current project status, see
+
+http://www.hansenpartnership.com/voyager
+
+The voyager architecture was designed by NCR in the mid 80s to be a
+fully SMP capable RAS computing architecture built around intel's 486
+chip set.  The voyager came in three levels of architectural
+sophistication: 3,4 and 5 --- 1 and 2 never made it out of prototype.
+The linux patches support only the Level 5 voyager architecture (any
+machine class 3435 and above).
+
+The Voyager Architecture
+------------------------
+
+Voyager machines consist of a Baseboard with a 386 diagnostic
+processor, a Power Supply Interface (PSI) a Primary and possibly
+Secondary Microchannel bus and between 2 and 20 voyager slots.  The
+voyager slots can be populated with memory and cpu cards (up to 4GB
+memory and from 1 486 to 32 Pentium Pro processors).  Internally, the
+voyager has a dual arbitrated system bus and a configuration and test
+bus (CAT).  The voyager bus speed is 40MHz.  Therefore (since all
+voyager cards are dual ported for each system bus) the maximum
+transfer rate is 320Mb/s but only if you have your slot configuration
+tuned (only memory cards can communicate with both busses at once, CPU
+cards utilise them one at a time).
+
+Voyager SMP
+-----------
+
+Since voyager was the first intel based SMP system, it is slightly
+more primitive than the Intel IO-APIC approach to SMP.  Voyager allows
+arbitrary interrupt routing (including processor affinity routing) of
+all 16 PC type interrupts.  However it does this by using a modified
+5259 master/slave chip set instead of an APIC bus.  Additionally,
+voyager supports Cross Processor Interrupts (CPI) equivalent to the
+APIC IPIs.  There are two routed voyager interrupt lines provided to
+each slot.
+
+Processor Cards
+---------------
+
+These come in single, dyadic and quad configurations (the quads are
+problematic--see later).  The maximum configuration is 8 quad cards
+for 32 way SMP.
+
+Quad Processors
+---------------
+
+Because voyager only supplies two interrupt lines to each Processor
+card, the Quad processors have to be configured (and Bootstrapped) in
+as a pair of Master/Slave processors.
+
+In fact, most Quad cards only accept one VIC interrupt line, so they
+have one interrupt handling processor (called the VIC extended
+processor) and three non-interrupt handling processors.
+
+Current Status
+--------------
+
+The System will boot on Mono, Dyad and Quad cards.  There was
+originally a Quad boot problem which has been fixed by proper gdt
+alignment in the initial boot loader.  If you still cannot get your
+voyager system to boot, email me at:
+
+<J.E.J.Bottomley@HansenPartnership.com>
+
+
+The Quad cards now support using the separate Quad CPI vectors instead
+of going through the VIC mailbox system.
+
+The Level 4 architecture (3430 and 3360 Machines) seems to work, as
+long as you specify memory size and don't expect any of the machine
+specific functions (reboot, power off etc.) to work.
+
+A Note About Mixed CPU Systems
+------------------------------
+
+Linux isn't designed to handle mixed CPU systems very well.  In order
+to get everything going you *must* make sure that your lowest
+capability CPU is used for booting.  Also, mixing CPU classes
+(e.g. 486 and 586) is really not going to work very well at all.
Index: linux/2.4/arch/i386/config.in
diff -u linux/2.4/arch/i386/config.in:1.1.1.8 linux/2.4/arch/i386/config.in:1.1.1.8.2.1
--- linux/2.4/arch/i386/config.in:1.1.1.8	Sat Mar 31 15:46:58 2001
+++ linux/2.4/arch/i386/config.in	Sat Mar 31 16:41:01 2001
@@ -173,12 +173,22 @@
 
 bool 'Networking support' CONFIG_NET
 bool 'SGI Visual Workstation support' CONFIG_VISWS
+
+if [ "$CONFIG_VISWS" != "y" ]; then
+   bool 'MCA support' CONFIG_MCA
+   if [ "$CONFIG_MCA" = "y" ]; then
+	bool '   Support for the NCR Voyager Architecture' CONFIG_VOYAGER
+   fi
+else
+   define_bool CONFIG_MCA n
+fi
+
 if [ "$CONFIG_VISWS" = "y" ]; then
    define_bool CONFIG_X86_VISWS_APIC y
    define_bool CONFIG_X86_LOCAL_APIC y
    define_bool CONFIG_PCI y
 else
-   if [ "$CONFIG_SMP" = "y" ]; then
+   if [ "$CONFIG_SMP" = "y" -a "$CONFIG_VOYAGER" != "y" ]; then
       define_bool CONFIG_X86_IO_APIC y
       define_bool CONFIG_X86_LOCAL_APIC y
    fi
@@ -200,12 +210,6 @@
 source drivers/pci/Config.in
 
 bool 'EISA support' CONFIG_EISA
-
-if [ "$CONFIG_VISWS" != "y" ]; then
-   bool 'MCA support' CONFIG_MCA
-else
-   define_bool CONFIG_MCA n
-fi
 
 bool 'Support for hot-pluggable devices' CONFIG_HOTPLUG
 
Index: linux/2.4/arch/i386/boot/setup.S
diff -u linux/2.4/arch/i386/boot/setup.S:1.1.1.7 linux/2.4/arch/i386/boot/setup.S:1.1.1.7.2.1
--- linux/2.4/arch/i386/boot/setup.S:1.1.1.7	Sat Mar 31 15:46:58 2001
+++ linux/2.4/arch/i386/boot/setup.S	Sat Mar 31 16:41:01 2001
@@ -444,6 +444,24 @@
 	movsb
 	popw	%ds
 no_mca:
+#ifdef CONFIG_VOYAGER
+	movb	$0xff, 0x40	# flag on config found
+	movb	$0xc0, %al
+	mov	$0xff, %ah
+	int	$0x15		# put voyager config info at es:di
+	jc	no_voyager
+	movw	$0x40, %si	# place voyager info in apm table
+	cld
+	movw	$7, %cx
+voyager_rep:
+	movb	%es:(%di), %al
+	movb	%al,(%si)
+	incw	%di
+	incw	%si
+	decw	%cx
+	jnz	voyager_rep
+no_voyager:	
+#endif
 # Check for PS/2 pointing device
 	movw	%cs, %ax			# aka SETUPSEG
 	subw	$DELTA_INITSEG, %ax		# aka INITSEG
@@ -881,6 +899,13 @@
 	ret
 
 # Descriptor tables
+
+##
+# NOTE:	On some CPUs, the GDT must be 8 byte aligned.  This is
+# true for the Voyager Quad CPU card which will not boot without
+# This directive.
+##
+	.align	8
 gdt:
 	.word	0, 0, 0, 0			# dummy
 	.word	0, 0, 0, 0			# unused
Index: linux/2.4/arch/i386/kernel/Makefile
diff -u linux/2.4/arch/i386/kernel/Makefile:1.1.1.5 linux/2.4/arch/i386/kernel/Makefile:1.1.1.5.2.1
--- linux/2.4/arch/i386/kernel/Makefile:1.1.1.5	Sat Mar 31 15:46:59 2001
+++ linux/2.4/arch/i386/kernel/Makefile	Sat Mar 31 16:41:02 2001
@@ -31,12 +31,17 @@
 endif
 
 obj-$(CONFIG_MCA)	+= mca.o
+obj-$(CONFIG_VOYAGER)	+= voyager.o voyager_cat.o
 obj-$(CONFIG_MTRR)	+= mtrr.o
 obj-$(CONFIG_X86_MSR)	+= msr.o
 obj-$(CONFIG_X86_CPUID)	+= cpuid.o
 obj-$(CONFIG_MICROCODE)	+= microcode.o
 obj-$(CONFIG_APM)	+= apm.o
+ifdef CONFIG_VOYAGER
+obj-$(CONFIG_SMP)	+= voyager_smp.o trampoline.o
+else
 obj-$(CONFIG_SMP)	+= smp.o smpboot.o trampoline.o
+endif
 obj-$(CONFIG_X86_LOCAL_APIC)	+= apic.o
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o mpparse.o
 obj-$(CONFIG_X86_VISWS_APIC)	+= visws_apic.o
Index: linux/2.4/arch/i386/kernel/i386_ksyms.c
diff -u linux/2.4/arch/i386/kernel/i386_ksyms.c:1.1.1.8 linux/2.4/arch/i386/kernel/i386_ksyms.c:1.1.1.8.2.1
--- linux/2.4/arch/i386/kernel/i386_ksyms.c:1.1.1.8	Sat Mar 31 15:47:00 2001
+++ linux/2.4/arch/i386/kernel/i386_ksyms.c	Sat Mar 31 16:41:02 2001
@@ -162,3 +162,9 @@
 #ifdef CONFIG_X86_PAE
 EXPORT_SYMBOL(empty_zero_page);
 #endif
+
+#ifdef CONFIG_VOYAGER
+/* need to export the mappings from physical to logical CPU */
+EXPORT_SYMBOL(__cpu_number_map);
+EXPORT_SYMBOL(__cpu_logical_map);
+#endif
Index: linux/2.4/arch/i386/kernel/i8259.c
diff -u linux/2.4/arch/i386/kernel/i8259.c:1.1.1.6 linux/2.4/arch/i386/kernel/i8259.c:1.1.1.6.2.1
--- linux/2.4/arch/i386/kernel/i8259.c:1.1.1.6	Sat Mar 31 15:47:00 2001
+++ linux/2.4/arch/i386/kernel/i8259.c	Sat Mar 31 16:41:02 2001
@@ -19,6 +19,9 @@
 #include <asm/pgtable.h>
 #include <asm/delay.h>
 #include <asm/desc.h>
+#ifdef CONFIG_VOYAGER
+#include <asm/voyager.h>
+#endif
 
 #include <linux/irq.h>
 
@@ -50,7 +53,7 @@
  */
 BUILD_16_IRQS(0x0)
 
-#ifdef CONFIG_X86_IO_APIC
+#if defined(CONFIG_X86_IO_APIC) || defined(CONFIG_VOYAGER)
 /*
  * The IO-APIC gives us many more interrupt sources. Most of these 
  * are unused but an SMP system is supposed to have enough memory ...
@@ -76,7 +79,7 @@
  * is no hardware IRQ pin equivalent for them, they are triggered
  * through the ICC by us (IPIs)
  */
-#ifdef CONFIG_SMP
+#if defined(CONFIG_SMP) && !defined(CONFIG_VOYAGER)
 BUILD_SMP_INTERRUPT(reschedule_interrupt,RESCHEDULE_VECTOR)
 BUILD_SMP_INTERRUPT(invalidate_interrupt,INVALIDATE_TLB_VECTOR)
 BUILD_SMP_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
@@ -107,7 +110,7 @@
 void (*interrupt[NR_IRQS])(void) = {
 	IRQLIST_16(0x0),
 
-#ifdef CONFIG_X86_IO_APIC
+#if defined(CONFIG_X86_IO_APIC) || defined(CONFIG_VOYAGER)
 			 IRQLIST_16(0x1), IRQLIST_16(0x2), IRQLIST_16(0x3),
 	IRQLIST_16(0x4), IRQLIST_16(0x5), IRQLIST_16(0x6), IRQLIST_16(0x7),
 	IRQLIST_16(0x8), IRQLIST_16(0x9), IRQLIST_16(0xa), IRQLIST_16(0xb),
@@ -456,6 +459,11 @@
 	}
 
 #ifdef CONFIG_SMP
+#ifdef CONFIG_VOYAGER
+
+	/* set up voyager SMP interrupts */
+	voyager_smp_intr_init();
+#else
 	/*
 	 * IRQ0 must be given a fixed assignment and initialized,
 	 * because it's used before the IO-APIC is set up.
@@ -482,6 +490,7 @@
 	/* IPI vectors for APIC spurious and error interrupts */
 	set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
 	set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
+#endif /* CONFIG_VOYAGER */
 #endif
 
 	/*
Index: linux/2.4/arch/i386/kernel/irq.c
diff -u linux/2.4/arch/i386/kernel/irq.c:1.1.1.8 linux/2.4/arch/i386/kernel/irq.c:1.1.1.8.2.2
--- linux/2.4/arch/i386/kernel/irq.c:1.1.1.8	Sat Mar 31 15:46:59 2001
+++ linux/2.4/arch/i386/kernel/irq.c	Sat Mar 31 18:37:54 2001
@@ -133,7 +133,7 @@
 
 	p += sprintf(p, "           ");
 	for (j=0; j<smp_num_cpus; j++)
-		p += sprintf(p, "CPU%d       ",j);
+		p += sprintf(p, "CPU%d       ", cpu_logical_map(j));
 	*p++ = '\n';
 
 	for (i = 0 ; i < NR_IRQS ; i++) {
@@ -160,7 +160,7 @@
 		p += sprintf(p, "%10u ",
 			nmi_count(cpu_logical_map(j)));
 	p += sprintf(p, "\n");
-#if CONFIG_SMP
+#if defined(CONFIG_SMP) && !defined(CONFIG_VOYAGER)
 	p += sprintf(p, "LOC: ");
 	for (j = 0; j < smp_num_cpus; j++)
 		p += sprintf(p, "%10u ",
Index: linux/2.4/arch/i386/kernel/process.c
diff -u linux/2.4/arch/i386/kernel/process.c:1.1.1.5 linux/2.4/arch/i386/kernel/process.c:1.1.1.5.16.1
--- linux/2.4/arch/i386/kernel/process.c:1.1.1.5	Thu Feb 22 18:05:51 2001
+++ linux/2.4/arch/i386/kernel/process.c	Sat Mar 31 16:41:02 2001
@@ -33,6 +33,9 @@
 #include <linux/reboot.h>
 #include <linux/init.h>
 #include <linux/mc146818rtc.h>
+#ifdef CONFIG_VOYAGER
+#include <asm/voyager.h>
+#endif
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -150,7 +153,9 @@
 
 __setup("idle=", idle_setup);
 
+#ifndef CONFIG_VOYAGER
 static long no_idt[2];
+#endif
 static int reboot_mode;
 static int reboot_thru_bios;
 
@@ -181,6 +186,7 @@
 
 __setup("reboot=", reboot_setup);
 
+#ifndef CONFIG_VOYAGER
 /* The following code and data reboots the machine by switching to real
    mode and jumping to the BIOS reset entry point, as if the CPU has
    really been reset.  The previous version asked the keyboard
@@ -241,6 +247,7 @@
 {
 	0xea, 0x00, 0x00, 0xff, 0xff		/*    ljmp  $0xffff,$0x0000  */
 };
+#endif /* CONFIG VOYAGER */
 
 static inline void kb_wait(void)
 {
@@ -260,6 +267,21 @@
 {
 	unsigned long flags;
 
+#ifdef CONFIG_VOYAGER
+	printk("Voyager Warm Restart\n");
+	kb_wait();
+	/* write magic values to the RTC to inform system that
+	 * shutdown is beginning */
+	outb(0x8f, 0x70);
+	outb(0x5 , 0x71);
+
+	udelay(50);
+	outb(0xfe,0x64);         /* pull reset low */
+	for(;;) {
+		asm("cli");
+		asm("hlt");
+	}
+#else
 	cli();
 
 	/* Write zero to CMOS register number 0x0f, which the BIOS POST
@@ -341,10 +363,14 @@
 	__asm__ __volatile__ ("ljmp $0x0008,%0"
 				:
 				: "i" ((void *) (0x1000 - sizeof (real_mode_switch) - 100)));
+#endif /* CONFIG_VOYAGER */
 }
 
 void machine_restart(char * __unused)
 {
+#ifdef CONFIG_VOYAGER
+	machine_real_restart(NULL, 0);
+#else
 #if CONFIG_SMP
 	/*
 	 * Stop all CPUs and turn off local APICs and the IO-APIC, so
@@ -372,16 +398,30 @@
 	}
 
 	machine_real_restart(jump_to_bios, sizeof(jump_to_bios));
+#endif /* CONFIG_VOYAGER */
 }
 
 void machine_halt(void)
 {
+#ifdef CONFIG_VOYAGER
+	/* treat a halt like a power off */
+	machine_power_off();
+#endif
 }
 
 void machine_power_off(void)
 {
+#ifdef CONFIG_VOYAGER
+#ifdef CONFIG_SMP
+	smp_call_function(smp_voyager_power_off, NULL, 1, 1);
+	smp_voyager_power_off(NULL);
+#else
+	voyager_power_off();
+#endif
+#else
 	if (pm_power_off)
 		pm_power_off();
+#endif
 }
 
 extern void show_trace(unsigned long* esp);
Index: linux/2.4/arch/i386/kernel/setup.c
diff -u linux/2.4/arch/i386/kernel/setup.c:1.1.1.11 linux/2.4/arch/i386/kernel/setup.c:1.1.1.11.2.1
--- linux/2.4/arch/i386/kernel/setup.c:1.1.1.11	Sat Mar 31 15:46:59 2001
+++ linux/2.4/arch/i386/kernel/setup.c	Sat Mar 31 16:41:02 2001
@@ -80,6 +80,9 @@
 #include <linux/config.h>
 #include <linux/init.h>
 #include <linux/apm_bios.h>
+#ifdef CONFIG_VOYAGER
+#include <asm/voyager.h>
+#endif
 #ifdef CONFIG_BLK_DEV_RAM
 #include <linux/blk.h>
 #endif
@@ -119,6 +122,9 @@
 unsigned int machine_id;
 unsigned int machine_submodel_id;
 unsigned int BIOS_revision;
+#ifdef CONFIG_VOYAGER
+struct voyager_bios_info voyager_bios_info;
+#endif
 unsigned int mca_pentium_flag;
 
 /*
@@ -158,7 +164,11 @@
 #define ALT_MEM_K (*(unsigned long *) (PARAM+0x1e0))
 #define E820_MAP_NR (*(char*) (PARAM+E820NR))
 #define E820_MAP    ((struct e820entry *) (PARAM+E820MAP))
+#ifdef CONFIG_VOYAGER
+#define VOYAGER_BIOS_INFO (*(struct voyager_bios_info *)(PARAM+0x40))
+#else
 #define APM_BIOS_INFO (*(struct apm_bios_info *) (PARAM+0x40))
+#endif
 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
 #define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0))
 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
@@ -455,6 +465,7 @@
  * thinkpad 560x, for example, does not cooperate with the memory
  * detection code.)
  */
+#ifndef CONFIG_VOYAGER
 static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
 {
 	/* Only one memory region (or negative)? Ignore it */
@@ -489,7 +500,7 @@
 	} while (biosmap++,--nr_map);
 	return 0;
 }
-
+#endif /* CONFIG_VOYAGER */
 /*
  * Do NOT EVER look at the BIOS memory size location.
  * It does not work on many machines.
@@ -498,6 +509,17 @@
 
 void __init setup_memory_region(void)
 {
+#ifdef CONFIG_VOYAGER
+	char *who = "Voyager-SUS";
+	__u32 addr, length;
+	int i;
+
+	e820.nr_map = 0;
+	for(i=0; voyager_memory_detect(i, &addr, &length); i++) {
+		add_memory_region(addr, length, E820_RAM);
+	}
+
+#else
 	char *who = "BIOS-e820";
 
 	/*
@@ -522,6 +544,7 @@
 		add_memory_region(0, LOWMEMSIZE(), E820_RAM);
 		add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
   	}
+#endif /* CONFIG_VOYAGER */
 	printk(KERN_INFO "BIOS-provided physical RAM map:\n");
 	print_memory_map(who);
 } /* setup_memory_region */
@@ -610,7 +633,6 @@
  	ROOT_DEV = to_kdev_t(ORIG_ROOT_DEV);
  	drive_info = DRIVE_INFO;
  	screen_info = SCREEN_INFO;
-	apm_info.bios = APM_BIOS_INFO;
 	if( SYS_DESC_TABLE.length != 0 ) {
 		MCA_bus = SYS_DESC_TABLE.table[3] &0x2;
 		machine_id = SYS_DESC_TABLE.table[0];
@@ -624,8 +646,34 @@
 	rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
 	rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
 #endif
+#ifdef CONFIG_VOYAGER
+	voyager_bios_info = VOYAGER_BIOS_INFO;
+	if(voyager_bios_info.len != 0xff) {
+		int class = (voyager_bios_info.class_1 << 8) 
+			| (voyager_bios_info.class_2 & 0xff);
+		int level;
+
+		printk("Voyager System detected.\n\tClass %x, Revision %d.%d\n",
+		       class, voyager_bios_info.major, 
+		       voyager_bios_info.minor);
+		if(class == VOYAGER_LEVEL4) 
+			level = 4;
+		else if(class < VOYAGER_LEVEL5_AND_ABOVE)
+			level = 3;
+		else
+			level = 5;
+		printk("\tArchitecture Level %d\n", level);
+		if(level < 5)
+			printk("\n**WARNING**: Voyager HAL only supports Level5 Architectures at the moment\n\n");
+	}
+	else {
+		printk("\n\n**WARNING**: No Voyager Subsystem Found\n");
+	}
+	
+#else
+	apm_info.bios = APM_BIOS_INFO;
+#endif /* CONFIG_VOYAGER */
 	setup_memory_region();
-
 	if (!MOUNT_ROOT_RDONLY)
 		root_mountflags &= ~MS_RDONLY;
 	init_mm.start_code = (unsigned long) &_text;
@@ -772,7 +820,7 @@
 	smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
 #endif
 
-#ifdef CONFIG_X86_IO_APIC
+#if defined(CONFIG_X86_IO_APIC) || defined (CONFIG_VOYAGER)
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
Index: linux/2.4/arch/i386/kernel/time.c
diff -u linux/2.4/arch/i386/kernel/time.c:1.1.1.6 linux/2.4/arch/i386/kernel/time.c:1.1.1.6.2.1
--- linux/2.4/arch/i386/kernel/time.c:1.1.1.6	Sat Mar 31 15:47:00 2001
+++ linux/2.4/arch/i386/kernel/time.c	Sat Mar 31 16:41:02 2001
@@ -58,6 +58,10 @@
 #include <asm/fixmap.h>
 #include <asm/cobalt.h>
 
+#ifdef CONFIG_VOYAGER
+#include <asm/voyager.h>
+#endif
+
 /*
  * for x86_do_profile()
  */
@@ -196,7 +200,16 @@
 	if( jiffies_t == jiffies_p ) {
 		if( count > count_p ) {
 			/* the nutcase */
-
+#if defined(CONFIG_VOYAGER) && defined(CONFIG_SMP)
+			/* can't read the ISR, just assume 1 tick
+                           overflow */
+			if(count > LATCH || count < 0) {
+				printk("VOYAGER PROBLEM: count is %ld, latch is %ld\n", count, LATCH);
+				count = LATCH;
+			}
+			count -= LATCH;
+#else
+ 
 			int i;
 
 			spin_lock(&i8259A_lock);
@@ -230,6 +243,7 @@
 				printk("do_slow_gettimeoffset(): hardware timer problem?\n");
 #endif
 			}
+#endif /* CONFIG_VOYAGER && CONFIG_SMP */
 		}
 	} else
 		jiffies_p = jiffies_t;
@@ -409,6 +423,9 @@
  * profiling, except when we simulate SMP mode on a uniprocessor
  * system, in that case we have to call the local interrupt handler.
  */
+#ifdef CONFIG_VOYAGER
+	voyager_timer_interrupt(regs);
+#else
 #ifndef CONFIG_X86_LOCAL_APIC
 	if (!user_mode(regs))
 		x86_do_profile(regs->eip);
@@ -416,6 +433,7 @@
 	if (!smp_found_config)
 		smp_local_timer_interrupt(regs);
 #endif
+#endif
 
 	/*
 	 * If we have an externally synchronized Linux clock, then update
@@ -644,6 +662,10 @@
  * to disk; this won't break the kernel, though, 'cuz we're
  * smart.  See arch/i386/kernel/apm.c.
  */
+#ifndef CONFIG_VOYAGER
+	/* For voyager, even if some of our CPUs have a TSC, they can
+	 * be driven by different clocks, so the TSCs will drift out
+	 * of sync.  It is much safer to use the slow gettimeoffset */
  	/*
  	 *	Firstly we have to do a CPU check for chips with
  	 * 	a potentially buggy TSC. At this point we haven't run
@@ -685,6 +707,7 @@
 			}
 		}
 	}
+#endif
 
 #ifdef CONFIG_VISWS
 	printk("Starting Cobalt Timer system clock\n");
Index: linux/2.4/arch/i386/kernel/voyager.c
diff -u /dev/null linux/2.4/arch/i386/kernel/voyager.c:1.1.12.1
--- /dev/null	Sun Apr 29 10:15:35 2001
+++ linux/2.4/arch/i386/kernel/voyager.c	Sat Mar 31 16:41:02 2001
@@ -0,0 +1,178 @@
+/* Copyright (C) 1999,2001 
+ *
+ * Author: J.E.J.Bottomley@HansenPartnership.com
+ *
+ * linux/arch/i386/kernel/voyager.c
+ *
+ * This file contains all the voyager specific routines for getting
+ * initialisation of the architecture to function.  For additional
+ * features see:
+ *
+ *	voyager_cat.c - Voyager CAT bus interface
+ *	voyager_smp.c - Voyager SMP hal (emulates linux smp.c)
+ */
+
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <asm/io.h>
+#include <asm/pgalloc.h>
+#include <asm/voyager.h>
+#include <asm/vic.h>
+
+#include <linux/irq.h>
+
+void
+voyager_system_interrupt(int cpl, void *dev_id, struct pt_regs *regs)
+{
+	printk("Voyager: detected system interrupt\n");
+}
+
+/* Routine to read information from the extended CMOS area */
+__u8
+voyager_extended_cmos_read(__u16 addr)
+{
+	outb(addr & 0xff, 0x74);
+	outb((addr >> 8) & 0xff, 0x75);
+	return inb(0x76);
+}
+
+/* internal definitions for the SUS Click Map of memory */
+
+#define CLICK_ENTRIES	16
+#define CLICK_SIZE	4096	/* click to byte conversion for Length */
+
+typedef struct ClickMap {
+	struct Entry {
+		__u32	Address;
+		__u32	Length;
+	} Entry[CLICK_ENTRIES];
+} ClickMap_t;
+
+
+/* This routine is pretty much an awful hack to read the bios clickmap by
+ * mapping it into page 0.  There are usually three regions in the map:
+ * 	Base Memory
+ * 	Extended Memory
+ *	zero length marker for end of map
+ *
+ * Returns are 0 for failure and 1 for success on extracting region.
+ */
+int __init
+voyager_memory_detect(int region, __u32 *start, __u32 *length)
+{
+	int i;
+	int retval = 0;
+	__u8 cmos[4];
+	ClickMap_t *map;
+	unsigned long map_addr;
+	unsigned long old;
+
+	if(region >= CLICK_ENTRIES) {
+		printk("Voyager: Illegal ClickMap region %d\n", region);
+		return 0;
+	}
+
+	for(i = 0; i < sizeof(cmos); i++)
+		cmos[i] = voyager_extended_cmos_read(VOYAGER_MEMORY_CLICKMAP + i);
+
+	map_addr = *(unsigned long *)cmos;
+
+	/* steal page 0 for this */
+	old = pg0[0];
+	pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
+	local_flush_tlb();
+	/* now clear everything out but page 0 */
+	map = (ClickMap_t *)(map_addr & (~PAGE_MASK));
+
+	/* zero length is the end of the clickmap */
+	if(map->Entry[region].Length != 0) {
+		*length = map->Entry[region].Length * CLICK_SIZE;
+		*start = map->Entry[region].Address;
+		retval = 1;
+	}
+
+	/* replace the mapping */
+	pg0[0] = old;
+	local_flush_tlb();
+	return retval;
+}
+
+void
+voyager_dump()
+{
+	/* get here via a sysrq */
+#ifdef CONFIG_SMP
+	voyager_smp_dump();
+#endif
+}
+
+/* voyager specific handling code for timer interrupts.  Used to hand
+ * off the timer tick to the SMP code, since the VIC doesn't have an
+ * internal timer (The QIC does, but that's another story). */
+void
+voyager_timer_interrupt(struct pt_regs *regs)
+{
+	if((jiffies & 0x3ff) == 0) {
+
+		/* There seems to be something flaky in either
+		 * hardware or software that is resetting the timer 0
+		 * count to something much higher than it should be
+		 * This seems to occur in the boot sequence, just
+		 * before root is mounted.  Therefore, every 10
+		 * seconds or so, we sanity check the timer zero count
+		 * and kick it back to where it should be.
+		 *
+		 * FIXME: This is the most awful hack yet seen.  I
+		 * should work out exactly what is interfering with
+		 * the timer count settings early in the boot sequence
+		 * and swiftly introduce it to something sharp and
+		 * pointy.  */
+		__u16 val;
+		extern spinlock_t i8253_lock;
+
+		spin_lock(&i8253_lock);
+		
+		outb_p(0x00, 0x43);
+		val = inb_p(0x40);
+		val |= inb(0x40) << 8;
+		spin_unlock(&i8253_lock);
+
+		if(val > LATCH) {
+			printk("\nVOYAGER: countdown timer value too high (%d), resetting\n\n", val);
+			spin_lock(&i8253_lock);
+			outb(0x34,0x43);
+			outb_p(LATCH & 0xff , 0x40);	/* LSB */
+			outb(LATCH >> 8 , 0x40);	/* MSB */
+			spin_unlock(&i8253_lock);
+		}
+	}
+#ifdef CONFIG_SMP
+	smp_vic_timer_interrupt(regs);
+#endif
+}
+
+void
+voyager_power_off(void)
+{
+		int port;
+
+	printk("VOYAGER Power Off\n");
+
+	__cli();
+
+	/* enable the voyager Configuration Space */
+        outb((inb(0x96) & 0xf0) | 0x8, 0x96);
+	/* the port for the power off flag is an offset from the
+           floating base */
+	port = inb(0x99) * 0x100 + 0x21;
+	/* set the power off flag */
+	outb(inb(port) | 0x1, port);
+	/* and wait for it to happen */
+	for(;;)
+		__asm("hlt");
+}
Index: linux/2.4/arch/i386/kernel/voyager_cat.c
diff -u /dev/null linux/2.4/arch/i386/kernel/voyager_cat.c:1.1.12.1
--- /dev/null	Sun Apr 29 10:15:35 2001
+++ linux/2.4/arch/i386/kernel/voyager_cat.c	Sat Mar 31 16:41:02 2001
@@ -0,0 +1,908 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
+
+/* Copyright (C) 1999,2001
+ *
+ * Author: J.E.J.Bottomley@HansenPartnership.com
+ *
+ * linux/arch/i386/kernel/voyager_cat.c
+ *
+ * This file contains all the logic for manipulating the CAT bus
+ * in a level 5 machine.
+ *
+ * The CAT bus is a serial configuration and test bus.  Its primary
+ * uses are to probe the initial configuration of the system and to
+ * diagnose error conditions when a system interrupt occurs.  The low
+ * level interface is fairly primitive, so most of this file consists
+ * of bit shift manipulations to send and receive packets on the
+ * serial bus */
+
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <linux/smp.h>
+#include <asm/voyager.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <asm/io.h>
+
+#ifdef VOYAGER_CAT_DEBUG
+#define CDEBUG(x)	printk x
+#else
+#define CDEBUG(x)
+#endif
+
+/* the CAT command port */
+#define CAT_CMD		(sspb + 0xe)
+/* the CAT data port */
+#define CAT_DATA	(sspb + 0xd)
+
+/* the internal cat functions */
+static void cat_pack(__u8 *msg, __u16 start_bit, __u8 *data, 
+		     __u16 num_bits);
+static void cat_unpack(__u8 *msg, __u16 start_bit, __u8 *data,
+		       __u16 num_bits);
+static void cat_build_header(__u8 *header, const __u16 len, 
+			     const __u16 smallest_reg_bits,
+			     const __u16 longest_reg_bits);
+static int cat_sendinst(voyager_module_t *modp, voyager_asic_t *asicp,
+			__u8 reg, __u8 op);
+static int cat_getdata(voyager_module_t *modp, voyager_asic_t *asicp,
+		       __u8 reg, __u8 *value);
+static int cat_shiftout(__u8 *data, __u16 data_bytes, __u16 header_bytes,
+			__u8 pad_bits);
+static int cat_write(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
+		     __u8 value);
+static int cat_read(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
+		    __u8 *value);
+static int cat_subread(voyager_module_t *modp, voyager_asic_t *asicp,
+		       __u16 offset, __u16 len, void *buf);
+static int cat_senddata(voyager_module_t *modp, voyager_asic_t *asicp,
+			__u8 reg, __u8 value);
+static int cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp);
+static int cat_connect(voyager_module_t *modp, voyager_asic_t *asicp);
+
+static inline const char *
+cat_module_name(int module_id)
+{
+	switch(module_id) {
+	case 0x10:
+		return "Processor Slot 0";
+	case 0x11:
+		return "Processor Slot 1";
+	case 0x12:
+		return "Processor Slot 2";
+	case 0x13:
+		return "Processor Slot 4";
+	case 0x14:
+		return "Memory Slot 0";
+	case 0x15:
+		return "Memory Slot 1";
+	case 0x18:
+		return "Primary Microchannel";
+	case 0x19:
+		return "Secondary Microchannel";
+	case 0x1a:
+		return "Power Supply Interface";
+	case 0x1c:
+		return "Processor Slot 5";
+	case 0x1d:
+		return "Processor Slot 6";
+	case 0x1e:
+		return "Processor Slot 7";
+	case 0x1f:
+		return "Processor Slot 8";
+	default:
+		return "Unknown Module";
+	}
+}
+
+static int sspb = 0;
+
+voyager_module_t *voyager_cat_list;
+
+/* the I/O port assignments for the VIC and QIC */
+static struct resource vic_res = {
+	"Voyager Interrupt Controller", 0xFC00, 0xFC6F };
+static struct resource qic_res = {
+	"Quad Interrupt Controller", 0xFC70, 0xFCFF };
+
+/* This function is used to pack a data bit stream inside a message.
+ * It writes num_bits of the data buffer in msg starting at start_bit.
+ * Note: This function assumes that any unused bit in the data stream
+ * is set to zero so that the ors will work correctly */
+#define BITS_PER_BYTE 8
+static void
+cat_pack(__u8 *msg, const __u16 start_bit, __u8 *data, const __u16 num_bits)
+{
+	/* compute initial shift needed */
+	const __u16 offset = start_bit % BITS_PER_BYTE;
+	__u16 len = num_bits / BITS_PER_BYTE;
+	__u16 byte = start_bit / BITS_PER_BYTE;
+	__u16 residue = (num_bits % BITS_PER_BYTE) + offset;
+	int i;
+
+	/* adjust if we have more than a byte of residue */
+	if(residue >= BITS_PER_BYTE) {
+		residue -= BITS_PER_BYTE;
+		len++;
+	}
+
+	/* clear out the bits.  We assume here that if len==0 then
+	 * residue >= offset.  This is always true for the catbus
+	 * operations */
+	msg[byte] &= 0xff << (BITS_PER_BYTE - offset); 
+	msg[byte++] |= data[0] >> offset;
+	if(len == 0)
+		return;
+	for(i = 1; i < len; i++)
+		msg[byte++] = (data[i-1] << (BITS_PER_BYTE - offset))
+			| (data[i] >> offset);
+	if(residue != 0) {
+		__u8 mask = 0xff >> residue;
+		__u8 last_byte = data[i-1] << (BITS_PER_BYTE - offset)
+			| (data[i] >> offset);
+		
+		last_byte &= ~mask;
+		msg[byte] &= mask;
+		msg[byte] |= last_byte;
+	}
+	return;
+}
+/* unpack the data again (same arguments as cat_pack()). data buffer
+ * must be zero populated.
+ *
+ * Function: given a message string move to start_bit and copy num_bits into
+ * data (starting at bit 0 in data).
+ */
+static void
+cat_unpack(__u8 *msg, const __u16 start_bit, __u8 *data, const __u16 num_bits)
+{
+	/* compute initial shift needed */
+	const __u16 offset = start_bit % BITS_PER_BYTE;
+	__u16 len = num_bits / BITS_PER_BYTE;
+	const __u8 last_bits = num_bits % BITS_PER_BYTE;
+	__u16 byte = start_bit / BITS_PER_BYTE;
+	int i;
+
+	if(last_bits != 0)
+		len++;
+
+	/* special case: want < 8 bits from msg and we can get it from
+	 * a single byte of the msg */
+	if(len == 0 && BITS_PER_BYTE - offset >= num_bits) {
+		data[0] = msg[byte] << offset;
+		data[0] &= 0xff >> (BITS_PER_BYTE - num_bits);
+		return;
+	}
+	for(i = 0; i < len; i++) {
+		/* this annoying if has to be done just in case a read of
+		 * msg one beyond the array causes a panic */
+		if(offset != 0) {
+			data[i] = msg[byte++] << offset;
+			data[i] |= msg[byte] >> (BITS_PER_BYTE - offset);
+		}
+		else {
+			data[i] = msg[byte++];
+		}
+	}
+	/* do we need to truncate the final byte */
+	if(last_bits != 0) {
+		data[i-1] &= 0xff << (BITS_PER_BYTE - last_bits);
+	}
+	return;
+}
+
+static void
+cat_build_header(__u8 *header, const __u16 len, const __u16 smallest_reg_bits,
+		 const __u16 longest_reg_bits)
+{
+	int i;
+	__u16 start_bit = (smallest_reg_bits - 1) % BITS_PER_BYTE;
+	__u8 *last_byte = &header[len - 1];
+
+	if(start_bit == 0)
+		start_bit = 1;	/* must have at least one bit in the hdr */
+	
+	for(i=0; i < len; i++)
+		header[i] = 0;
+
+	for(i = start_bit; i > 0; i--)
+		*last_byte = ((*last_byte) << 1) + 1;
+
+}
+
+static int
+cat_sendinst(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg, __u8 op)
+{
+	__u8 parity, inst, inst_buf[4] = { 0 };
+	__u8 iseq[VOYAGER_MAX_SCAN_PATH], hseq[VOYAGER_MAX_REG_SIZE];
+	__u16 ibytes, hbytes, padbits;
+	int i;
+	
+	/* 
+	 * Parity is the parity of the register number + 1 (READ_REGISTER
+	 * and WRITE_REGISTER always add '1' to the number of bits == 1)
+	 */
+	parity = (__u8)(1 + (reg & 0x01) +
+	         ((__u8)(reg & 0x02) >> 1) +
+	         ((__u8)(reg & 0x04) >> 2) +
+	         ((__u8)(reg & 0x08) >> 3)) % 2;
+
+	inst = ((parity << 7) | (reg << 2) | op);
+
+	outb(VOYAGER_CAT_IRCYC, CAT_CMD);
+	if(!modp->scan_path_connected) {
+		if(asicp->asic_id != VOYAGER_CAT_ID) {
+			printk("**WARNING***: cat_sendinst has disconnected scan path not to CAT asic\n");
+			return 1;
+		}
+		outb(VOYAGER_CAT_HEADER, CAT_DATA);
+		outb(inst, CAT_DATA);
+		if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
+			CDEBUG(("VOYAGER CAT: cat_sendinst failed to get CAT_HEADER\n"));
+			return 1;
+		}
+		return 0;
+	}
+	ibytes = modp->inst_bits / BITS_PER_BYTE;
+	if((padbits = modp->inst_bits % BITS_PER_BYTE) != 0) {
+		padbits = BITS_PER_BYTE - padbits;
+		ibytes++;
+	}
+	hbytes = modp->largest_reg / BITS_PER_BYTE;
+	if(modp->largest_reg % BITS_PER_BYTE)
+		hbytes++;
+	CDEBUG(("cat_sendinst: ibytes=%d, hbytes=%d\n", ibytes, hbytes));
+	/* initialise the instruction sequence to 0xff */
+	for(i=0; i < ibytes + hbytes; i++)
+		iseq[i] = 0xff;
+	cat_build_header(hseq, hbytes, modp->smallest_reg, modp->largest_reg);
+	cat_pack(iseq, modp->inst_bits, hseq, hbytes * BITS_PER_BYTE);
+	inst_buf[0] = inst;
+	inst_buf[1] = 0xFF >> (modp->largest_reg % BITS_PER_BYTE);
+	cat_pack(iseq, asicp->bit_location, inst_buf, asicp->ireg_length);
+#ifdef VOYAGER_CAT_DEBUG
+	printk("ins = 0x%x, iseq: ", inst);
+	for(i=0; i< ibytes + hbytes; i++)
+		printk("0x%x ", iseq[i]);
+	printk("\n");
+#endif
+	if(cat_shiftout(iseq, ibytes, hbytes, padbits)) {
+		CDEBUG(("VOYAGER CAT: cat_sendinst: cat_shiftout failed\n"));
+		return 1;
+	}
+	CDEBUG(("CAT SHIFTOUT DONE\n"));
+	return 0;
+}
+
+static int
+cat_getdata(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg, 
+	    __u8 *value)
+{
+	if(!modp->scan_path_connected) {
+		if(asicp->asic_id != VOYAGER_CAT_ID) {
+			CDEBUG(("VOYAGER CAT: ERROR: cat_getdata to CAT asic with scan path connected\n"));
+			return 1;
+		}
+		if(reg > VOYAGER_SUBADDRHI) 
+			outb(VOYAGER_CAT_RUN, CAT_CMD);
+		outb(VOYAGER_CAT_DRCYC, CAT_CMD);
+		outb(VOYAGER_CAT_HEADER, CAT_DATA);
+		*value = inb(CAT_DATA);
+		outb(0xAA, CAT_DATA);
+		if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
+			CDEBUG(("cat_getdata: failed to get VOYAGER_CAT_HEADER\n"));
+			return 1;
+		}
+		return 0;
+	}
+	else {
+		__u16 sbits = modp->num_asics -1 + asicp->ireg_length;
+		__u16 sbytes = sbits / BITS_PER_BYTE;
+		__u16 tbytes;
+		__u8 string[VOYAGER_MAX_SCAN_PATH], trailer[VOYAGER_MAX_REG_SIZE];
+		__u8 padbits;
+		int i;
+		
+		outb(VOYAGER_CAT_DRCYC, CAT_CMD);
+
+		if((padbits = sbits % BITS_PER_BYTE) != 0) {
+			padbits = BITS_PER_BYTE - padbits;
+			sbytes++;
+		}
+		tbytes = asicp->ireg_length / BITS_PER_BYTE;
+		if(asicp->ireg_length % BITS_PER_BYTE)
+			tbytes++;
+		CDEBUG(("cat_getdata: tbytes = %d, sbytes = %d, padbits = %d\n",
+			tbytes,	sbytes, padbits));
+		cat_build_header(trailer, tbytes, 1, asicp->ireg_length);
+
+		
+		for(i = tbytes - 1; i >= 0; i--) {
+			outb(trailer[i], CAT_DATA);
+			string[sbytes + i] = inb(CAT_DATA);
+		}
+
+		for(i = sbytes - 1; i >= 0; i--) {
+			outb(0xaa, CAT_DATA);
+			string[i] = inb(CAT_DATA);
+		}
+		*value = 0;
+		cat_unpack(string, padbits + (tbytes * BITS_PER_BYTE) + asicp->asic_location, value, asicp->ireg_length);
+#ifdef VOYAGER_CAT_DEBUG
+		printk("value=0x%x, string: ", *value);
+		for(i=0; i< tbytes+sbytes; i++)
+			printk("0x%x ", string[i]);
+		printk("\n");
+#endif
+		
+		/* sanity check the rest of the return */
+		for(i=0; i < tbytes; i++) {
+			__u8 input = 0;
+
+			cat_unpack(string, padbits + (i * BITS_PER_BYTE), &input, BITS_PER_BYTE);
+			if(trailer[i] != input) {
+				CDEBUG(("cat_getdata: failed to sanity check rest of ret(%d) 0x%x != 0x%x\n", i, input, trailer[i]));
+				return 1;
+			}
+		}
+		CDEBUG(("cat_getdata DONE\n"));
+		return 0;
+	}
+}
+
+static int
+cat_shiftout(__u8 *data, __u16 data_bytes, __u16 header_bytes, __u8 pad_bits)
+{
+	int i;
+	
+	for(i = data_bytes + header_bytes - 1; i >= header_bytes; i--)
+		outb(data[i], CAT_DATA);
+
+	for(i = header_bytes - 1; i >= 0; i--) {
+		__u8 header = 0;
+		__u8 input;
+
+		outb(data[i], CAT_DATA);
+		input = inb(CAT_DATA);
+		CDEBUG(("cat_shiftout: returned 0x%x\n", input));
+		cat_unpack(data, ((data_bytes + i) * BITS_PER_BYTE) - pad_bits,
+			   &header, BITS_PER_BYTE);
+		if(input != header) {
+			CDEBUG(("VOYAGER CAT: cat_shiftout failed to return header 0x%x != 0x%x\n", input, header));
+			return 1;
+		}
+	}
+	return 0;
+}
+
+static int
+cat_senddata(voyager_module_t *modp, voyager_asic_t *asicp, 
+	     __u8 reg, __u8 value)
+{
+	outb(VOYAGER_CAT_DRCYC, CAT_CMD);
+	if(!modp->scan_path_connected) {
+		if(asicp->asic_id != VOYAGER_CAT_ID) {
+			CDEBUG(("VOYAGER CAT: ERROR: scan path disconnected when asic != CAT\n"));
+			return 1;
+		}
+		outb(VOYAGER_CAT_HEADER, CAT_DATA);
+		outb(value, CAT_DATA);
+		if(inb(CAT_DATA) != VOYAGER_CAT_HEADER) {
+			CDEBUG(("cat_senddata: failed to get correct header response to sent data\n"));
+			return 1;
+		}
+		if(reg > VOYAGER_SUBADDRHI) {
+			outb(VOYAGER_CAT_RUN, CAT_CMD);
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			outb(VOYAGER_CAT_RUN, CAT_CMD);
+		}
+		
+		return 0;
+	}
+	else {
+		__u16 hbytes = asicp->ireg_length / BITS_PER_BYTE;
+		__u16 dbytes = (modp->num_asics - 1 + asicp->ireg_length)/BITS_PER_BYTE;
+		__u8 padbits, dseq[VOYAGER_MAX_SCAN_PATH], 
+			hseq[VOYAGER_MAX_REG_SIZE];
+		int i;
+
+		if((padbits = (modp->num_asics - 1 
+			       + asicp->ireg_length) % BITS_PER_BYTE) != 0) {
+			padbits = BITS_PER_BYTE - padbits;
+			dbytes++;
+		}
+		if(asicp->ireg_length % BITS_PER_BYTE)
+			hbytes++;
+		
+		cat_build_header(hseq, hbytes, 1, asicp->ireg_length);
+		
+		for(i = 0; i < dbytes + hbytes; i++)
+			dseq[i] = 0xff;
+		CDEBUG(("cat_senddata: dbytes=%d, hbytes=%d, padbits=%d\n",
+			dbytes, hbytes, padbits));
+		cat_pack(dseq, modp->num_asics - 1 + asicp->ireg_length,
+			 hseq, hbytes * BITS_PER_BYTE);
+		cat_pack(dseq, asicp->asic_location, &value, 
+			 asicp->ireg_length);
+#ifdef VOYAGER_CAT_DEBUG
+		printk("dseq ");
+		for(i=0; i<hbytes+dbytes; i++) {
+			printk("0x%x ", dseq[i]);
+		}
+		printk("\n");
+#endif
+		return cat_shiftout(dseq, dbytes, hbytes, padbits);
+	}
+}
+
+static int
+cat_write(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
+	 __u8 value)
+{
+	if(cat_sendinst(modp, asicp, reg, VOYAGER_WRITE_CONFIG))
+		return 1;
+	return cat_senddata(modp, asicp, reg, value);
+}
+
+static int
+cat_read(voyager_module_t *modp, voyager_asic_t *asicp, __u8 reg,
+	 __u8 *value)
+{
+	if(cat_sendinst(modp, asicp, reg, VOYAGER_READ_CONFIG))
+		return 1;
+	return cat_getdata(modp, asicp, reg, value);
+}
+
+static int
+cat_subaddrsetup(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
+		 __u16 len)
+{
+	__u8 val;
+
+	if(len > 1) {
+		/* set auto increment */
+		__u8 newval;
+		
+		if(cat_read(modp, asicp, VOYAGER_AUTO_INC_REG, &val)) {
+			CDEBUG(("cat_subaddrsetup: read of VOYAGER_AUTO_INC_REG failed\n"));
+			return 1;
+		}
+		CDEBUG(("cat_subaddrsetup: VOYAGER_AUTO_INC_REG = 0x%x\n", val));
+		newval = val | VOYAGER_AUTO_INC;
+		if(newval != val) {
+			if(cat_write(modp, asicp, VOYAGER_AUTO_INC_REG, val)) {
+				CDEBUG(("cat_subaddrsetup: write to VOYAGER_AUTO_INC_REG failed\n"));
+				return 1;
+			}
+		}
+	}
+	if(cat_write(modp, asicp, VOYAGER_SUBADDRLO, (__u8)(offset &0xff))) {
+		CDEBUG(("cat_subaddrsetup: write to SUBADDRLO failed\n"));
+		return 1;
+	}
+	if(asicp->subaddr > VOYAGER_SUBADDR_LO) {
+		if(cat_write(modp, asicp, VOYAGER_SUBADDRHI, (__u8)(offset >> 8))) {
+			CDEBUG(("cat_subaddrsetup: write to SUBADDRHI failed\n"));
+			return 1;
+		}
+		cat_read(modp, asicp, VOYAGER_SUBADDRHI, &val);
+		CDEBUG(("cat_subaddrsetup: offset = %d, hi = %d\n", offset, val));
+	}
+	cat_read(modp, asicp, VOYAGER_SUBADDRLO, &val);
+	CDEBUG(("cat_subaddrsetup: offset = %d, lo = %d\n", offset, val));
+	return 0;
+}
+		
+static int
+cat_subwrite(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
+	    __u16 len, void *buf)
+{
+	int i, retval;
+
+	/* FIXME: need special actions for VOYAGER_CAT_ID here */
+	if(asicp->asic_id == VOYAGER_CAT_ID) {
+		CDEBUG(("cat_subwrite: ATTEMPT TO WRITE TO CAT ASIC\n"));
+		return 1;
+	}
+		
+	if((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
+		CDEBUG(("cat_write: cat_subaddrsetup FAILED\n"));
+		return retval;
+	}
+	
+	if(cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_WRITE_CONFIG)) {
+		CDEBUG(("cat_write: cat_sendinst FAILED\n"));
+		return 1;
+	}
+	for(i = 0; i < len; i++) {
+		if(cat_senddata(modp, asicp, 0xFF, ((__u8 *)buf)[i])) {
+			CDEBUG(("cat_subwrite: cat_sendata element at %d FAILED\n", i));
+			return 1;
+		}
+	}
+	return 0;
+}
+static int
+cat_subread(voyager_module_t *modp, voyager_asic_t *asicp, __u16 offset,
+	    __u16 len, void *buf)
+{
+	int i, retval;
+
+	if((retval = cat_subaddrsetup(modp, asicp, offset, len)) != 0) {
+		CDEBUG(("cat_read: cat_subaddrsetup FAILED\n"));
+		return retval;
+	}
+
+	if(cat_sendinst(modp, asicp, VOYAGER_SUBADDRDATA, VOYAGER_READ_CONFIG)) {
+		CDEBUG(("cat_subread: cat_sendinst failed\n"));
+		return 1;
+	}
+	for(i = 0; i < len; i++) {
+		if(cat_getdata(modp, asicp, 0xFF,
+			       &((__u8 *)buf)[i])) {
+			CDEBUG(("cat_subread: cat_getdata element %d failed\n", i));
+			return 1;
+		}
+	}
+	return 0;
+}
+
+
+/* buffer for storing EPROM data read in during initialisation */
+static __initdata __u8 eprom_buf[0xFFFF];
+static voyager_module_t *voyager_initial_module;
+
+void
+voyager_cat_init(void)
+{
+	voyager_module_t **modpp = &voyager_initial_module;
+	voyager_asic_t **asicpp;
+	voyager_asic_t *qabc_asic = NULL;
+	int i, j;
+	unsigned long qic_addr = 0;
+	__u8 qabc_data[0x20];
+	__u8 num_submodules, val;
+	voyager_eprom_hdr_t *eprom_hdr = (voyager_eprom_hdr_t *)&eprom_buf[0];
+
+	/* clear the processor counts */
+	voyager_extended_vic_processors = 0;
+	voyager_quad_processors = 0;
+
+	printk("VOYAGER: beginning CAT bus probe\n");
+	/* set up the SuperSet Port Block which tells us where the
+	 * CAT communication port is */
+	sspb = inb(VOYAGER_SSPB_RELOCATION_PORT) * 0x100;
+	VDEBUG(("VOYAGER DEBUG: sspb = 0x%x\n", sspb));
+
+	for(i = VOYAGER_MIN_MODULE;
+	    i <= VOYAGER_MAX_MODULE; i++) {
+		__u8 input;
+		int asic;
+		__u16 eprom_size;
+		__u16 sp_offset;
+
+		outb(VOYAGER_CAT_DESELECT, VOYAGER_CAT_CONFIG_PORT);
+		outb(i, VOYAGER_CAT_CONFIG_PORT);
+
+		/* check the presence of the module */
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		outb(VOYAGER_CAT_IRCYC, CAT_CMD);
+		outb(VOYAGER_CAT_HEADER, CAT_DATA);
+		/* stream series of alternating 1's and 0's to stimulate
+		 * response */
+		outb(0xAA, CAT_DATA);
+		input = inb(CAT_DATA);
+		outb(VOYAGER_CAT_END, CAT_CMD);
+		if(input != VOYAGER_CAT_HEADER) {
+			continue;
+		}
+		CDEBUG(("VOYAGER DEBUG: found module id 0x%x, %s\n", i,
+			cat_module_name(i)));
+		*modpp = kmalloc(sizeof(voyager_module_t), GFP_KERNEL); /*&voyager_module_storage[cat_count++];*/
+		if(*modpp == NULL) {
+			printk("**WARNING** kmalloc failure in cat_init\n");
+			continue;
+		}
+		memset(*modpp, 0, sizeof(voyager_module_t));
+		/* need temporary asic for cat_subread.  It will be
+		 * filled in correctly later */
+		(*modpp)->asic = kmalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count];*/
+		if((*modpp)->asic == NULL) {
+			printk("**WARNING** kmalloc failure in cat_init\n");
+			continue;
+		}
+		memset((*modpp)->asic, 0, sizeof(voyager_asic_t));
+		(*modpp)->asic->asic_id = VOYAGER_CAT_ID;
+		(*modpp)->asic->subaddr = VOYAGER_SUBADDR_HI;
+		(*modpp)->module_addr = i;
+		(*modpp)->scan_path_connected = 0;
+		if(i == 0x1a /* PSI */) {
+			/* Exception leg for modules with no EEPROM */
+			printk("Module \"%s\"\n", cat_module_name(i));
+			continue;
+		}
+			       
+		CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		cat_disconnect(*modpp, (*modpp)->asic);
+		if(cat_subread(*modpp, (*modpp)->asic,
+			       VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
+			       &eprom_size)) {
+			printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i);
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+		if(eprom_size > sizeof(eprom_buf)) {
+			printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x.  Need %d\n", i, eprom_size);
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+		outb(VOYAGER_CAT_END, CAT_CMD);
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, eprom_size));
+		if(cat_subread(*modpp, (*modpp)->asic, 0, 
+			       eprom_size, eprom_buf)) {
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+		outb(VOYAGER_CAT_END, CAT_CMD);
+		printk("Module \"%s\", version 0x%x, tracer 0x%x, asics %d\n",
+		       cat_module_name(i), eprom_hdr->version_id,
+		       *((__u32 *)eprom_hdr->tracer),  eprom_hdr->num_asics);
+		(*modpp)->ee_size = eprom_hdr->ee_size;
+		(*modpp)->num_asics = eprom_hdr->num_asics;
+		asicpp = &((*modpp)->asic);
+		sp_offset = eprom_hdr->scan_path_offset;
+		/* All we really care about are the Quad cards.  We
+                 * identify them because they are in a processor slot
+                 * and have only four asics */
+		if((i < 0x10 || (i>=0x14 && i < 0x1c) || i>0x1f)) {
+			modpp = &((*modpp)->next);
+			continue;
+		}
+		/* Now we know it's in a processor slot, does it have
+		 * a quad baseboard submodule */
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODPRESENT,
+			 &num_submodules);
+		/* lowest two bits, active low */
+		num_submodules = ~(0xfc | num_submodules);
+		CDEBUG(("VOYAGER CAT: %d submodules present\n", num_submodules));
+		if(num_submodules == 0) {
+			/* fill in the dyadic extended processors */
+			__u8 cpu = i & 0x07;
+
+			printk("Module \"%s\": Dyadic Processor Card\n",
+			       cat_module_name(i));
+			voyager_extended_vic_processors |= (1<<cpu);
+			cpu += 4;
+			voyager_extended_vic_processors |= (1<<cpu);
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+
+		/* now we want to read the asics on the first submodule,
+		 * which should be the quad base board */
+
+		cat_read(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, &val);
+		CDEBUG(("cat_init: SUBMODSELECT value = 0x%x\n", val));
+		val = (val & 0x7c) | VOYAGER_QUAD_BASEBOARD;
+		cat_write(*modpp, (*modpp)->asic, VOYAGER_SUBMODSELECT, val);
+
+		outb(VOYAGER_CAT_END, CAT_CMD);
+			 
+
+		CDEBUG(("cat_init: Reading eeprom for module 0x%x at offset %d\n", i, VOYAGER_XSUM_END_OFFSET));
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		cat_disconnect(*modpp, (*modpp)->asic);
+		if(cat_subread(*modpp, (*modpp)->asic,
+			       VOYAGER_XSUM_END_OFFSET, sizeof(eprom_size),
+			       &eprom_size)) {
+			printk("**WARNING**: Voyager couldn't read EPROM size for module 0x%x\n", i);
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+		if(eprom_size > sizeof(eprom_buf)) {
+			printk("**WARNING**: Voyager insufficient size to read EPROM data, module 0x%x.  Need %d\n", i, eprom_size);
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+		outb(VOYAGER_CAT_END, CAT_CMD);
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		CDEBUG(("cat_init: module 0x%x, eeprom_size %d\n", i, eprom_size));
+		if(cat_subread(*modpp, (*modpp)->asic, 0, 
+			       eprom_size, eprom_buf)) {
+			outb(VOYAGER_CAT_END, CAT_CMD);
+			continue;
+		}
+		outb(VOYAGER_CAT_END, CAT_CMD);
+		/* Now do everything for the QBB submodule 1 */
+		(*modpp)->ee_size = eprom_hdr->ee_size;
+		(*modpp)->num_asics = eprom_hdr->num_asics;
+		asicpp = &((*modpp)->asic);
+		sp_offset = eprom_hdr->scan_path_offset;
+		/* get rid of the dummy CAT asic and read the real one */
+		kfree((*modpp)->asic);
+		for(asic=0; asic < (*modpp)->num_asics; asic++) {
+			int j;
+			voyager_asic_t *asicp = *asicpp 
+				= kmalloc(sizeof(voyager_asic_t), GFP_KERNEL); /*&voyager_asic_storage[asic_count++];*/
+			voyager_sp_table_t *sp_table;
+			voyager_at_t *asic_table;
+			voyager_jtt_t *jtag_table;
+
+			if(asicp == NULL) {
+				printk("**WARNING** kmalloc failure in cat_init\n");
+				continue;
+			}
+			memset(asicp, 0, sizeof(voyager_asic_t));
+			asicpp = &(asicp->next);
+			asicp->asic_location = asic;
+			sp_table = (voyager_sp_table_t *)(eprom_buf + sp_offset);
+			asicp->asic_id = sp_table->asic_id;
+			asic_table = (voyager_at_t *)(eprom_buf + sp_table->asic_data_offset);
+			for(j=0; j<4; j++)
+				asicp->jtag_id[j] = asic_table->jtag_id[j];
+			jtag_table = (voyager_jtt_t *)(eprom_buf + asic_table->jtag_offset);
+			asicp->ireg_length = jtag_table->ireg_len;
+			asicp->bit_location = (*modpp)->inst_bits;
+			(*modpp)->inst_bits += asicp->ireg_length;
+			if(asicp->ireg_length > (*modpp)->largest_reg)
+				(*modpp)->largest_reg = asicp->ireg_length;
+			if (asicp->ireg_length < (*modpp)->smallest_reg ||
+			    (*modpp)->smallest_reg == 0)
+				(*modpp)->smallest_reg = asicp->ireg_length;
+			CDEBUG(("asic 0x%x, ireg_length=%d, bit_location=%d\n",
+				asicp->asic_id, asicp->ireg_length,
+				asicp->bit_location));
+			if(asicp->asic_id == VOYAGER_QUAD_QABC) {
+				CDEBUG(("VOYAGER CAT: QABC ASIC found\n"));
+				qabc_asic = asicp;
+			}
+			sp_offset += sizeof(voyager_sp_table_t);
+		}
+		CDEBUG(("Module inst_bits = %d, largest_reg = %d, smallest_reg=%d\n",
+			(*modpp)->inst_bits, (*modpp)->largest_reg,
+			(*modpp)->smallest_reg));
+		/* OK, now we have the QUAD ASICs set up, use them.
+		 * we need to:
+		 *
+		 * 1. Find the Memory area for the Quad CPIs.
+		 * 2. Find the Extended VIC processor
+		 * 3. Configure a second extended VIC processor (This
+		 *    cannot be done for the 51xx.
+		 * */
+		outb(VOYAGER_CAT_RUN, CAT_CMD);
+		cat_connect(*modpp, (*modpp)->asic);
+		CDEBUG(("CAT CONNECTED!!\n"));
+		cat_subread(*modpp, qabc_asic, 0, sizeof(qabc_data), qabc_data);
+		qic_addr = qabc_data[5] << 8;
+		qic_addr = (qic_addr | qabc_data[6]) << 8;
+		qic_addr = (qic_addr | qabc_data[7]) << 8;
+		printk("Module \"%s\": Quad Processor Card; CPI 0x%lx, SET=0x%x\n",
+		       cat_module_name(i), qic_addr, qabc_data[8]);
+#if 0				/* plumbing fails---FIXME */
+		if((qabc_data[8] & 0xf0) == 0) {
+			/* FIXME: 32 way 8 CPU slot monster cannot be
+			 * plumbed this way---need to check for it */
+
+			printk("Plumbing second Extended Quad Processor\n");
+			/* second VIC line hardwired to Quad CPU 1 */
+			qabc_data[8] |= 0x20;
+			cat_subwrite(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
+#ifdef VOYAGER_CAT_DEBUG
+			/* verify plumbing */
+			cat_subread(*modpp, qabc_asic, 8, 1, &qabc_data[8]);
+			if((qabc_data[8] & 0xf0) == 0) {
+				CDEBUG(("PLUMBING FAILED: 0x%x\n", qabc_data[8]));
+			}
+#endif
+		}
+#endif
+
+		{
+			struct resource *res = kmalloc(sizeof(struct resource),GFP_KERNEL);
+			memset(res, 0, sizeof(struct resource));
+			res->name = kmalloc(128, GFP_KERNEL);
+			sprintf((char *)res->name, "Voyager %s Quad CPI", cat_module_name(i));
+			res->start = qic_addr;
+			res->end = qic_addr + 0x3ff;
+			request_resource(&iomem_resource, res);
+		}
+
+		qic_addr = (unsigned long)ioremap(qic_addr, 0x400);
+				
+		for(j = 0; j < 4; j++) {
+			__u8 cpu = (i & 0x07) + j*4;
+			if( (qabc_data[8] & (1<<j)) ||
+			    (qabc_data[8] & (1<<(j+4))) ) {
+				voyager_extended_vic_processors |= (1<<cpu);
+			}
+			voyager_quad_processors |= (1<<cpu);
+			voyager_quad_cpi_addr[cpu] = (struct voyager_qic_cpi *)
+				(qic_addr+(j<<8));
+			CDEBUG(("CPU%d: CPI address 0x%lx\n", cpu,
+				(unsigned long)voyager_quad_cpi_addr[cpu]));
+		}
+		outb(VOYAGER_CAT_END, CAT_CMD);
+
+		
+		
+		*asicpp = NULL;
+		modpp = &((*modpp)->next);
+	}
+	*modpp = NULL;
+	printk("CAT Bus Initialisation finished: extended procs 0x%x, quad procs 0x%x\n", voyager_extended_vic_processors, voyager_quad_processors);
+	request_resource(&ioport_resource, &vic_res);
+	if(voyager_quad_processors)
+		request_resource(&ioport_resource, &qic_res);
+}
+
+int
+voyager_cat_readb(__u8 module, __u8 asic, int reg)
+{
+	return 0;
+}
+
+static int
+cat_disconnect(voyager_module_t *modp, voyager_asic_t *asicp) 
+{
+	__u8 val;
+	int err = 0;
+
+	if(!modp->scan_path_connected)
+		return 0;
+	if(asicp->asic_id != VOYAGER_CAT_ID) {
+		CDEBUG(("cat_disconnect: ASIC is not CAT\n"));
+		return 1;
+	}
+	err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
+	if(err) {
+		CDEBUG(("cat_disconnect: failed to read SCANPATH\n"));
+		return err;
+	}
+	val &= VOYAGER_DISCONNECT_ASIC;
+	err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
+	if(err) {
+		CDEBUG(("cat_disconnect: failed to write SCANPATH\n"));
+		return err;
+	}
+	outb(VOYAGER_CAT_END, CAT_CMD);
+	outb(VOYAGER_CAT_RUN, CAT_CMD);
+	modp->scan_path_connected = 0;
+
+	return 0;
+}
+
+static int
+cat_connect(voyager_module_t *modp, voyager_asic_t *asicp) 
+{
+	__u8 val;
+	int err = 0;
+
+	if(modp->scan_path_connected)
+		return 0;
+	if(asicp->asic_id != VOYAGER_CAT_ID) {
+		CDEBUG(("cat_connect: ASIC is not CAT\n"));
+		return 1;
+	}
+
+	err = cat_read(modp, asicp, VOYAGER_SCANPATH, &val);
+	if(err) {
+		CDEBUG(("cat_connect: failed to read SCANPATH\n"));
+		return err;
+	}
+	val |= VOYAGER_CONNECT_ASIC;
+	err = cat_write(modp, asicp, VOYAGER_SCANPATH, val);
+	if(err) {
+		CDEBUG(("cat_connect: failed to write SCANPATH\n"));
+		return err;
+	}
+	outb(VOYAGER_CAT_END, CAT_CMD);
+	outb(VOYAGER_CAT_RUN, CAT_CMD);
+	modp->scan_path_connected = 1;
+
+	return 0;
+}
Index: linux/2.4/arch/i386/kernel/voyager_smp.c
diff -u /dev/null linux/2.4/arch/i386/kernel/voyager_smp.c:1.1.12.1
--- /dev/null	Sun Apr 29 10:15:35 2001
+++ linux/2.4/arch/i386/kernel/voyager_smp.c	Sat Mar 31 16:41:02 2001
@@ -0,0 +1,1845 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
+
+/* Copyright (C) 1999,2001
+ *
+ * Author: J.E.J.Bottomley@HansenPartnership.com
+ *
+ * linux/arch/i386/kernel/voyager_smp.c
+ *
+ * This file provides all the same external entries as smp.c but uses
+ * the voyager hal to provide the functionality
+ */
+#include <linux/config.h>
+#include <linux/mm.h>
+#include <linux/kernel_stat.h>
+#include <linux/delay.h>
+#include <linux/mc146818rtc.h>
+#include <linux/smp_lock.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <asm/desc.h>
+#include <asm/voyager.h>
+#include <asm/vic.h>
+#include <asm/pgalloc.h>
+#include <asm/mtrr.h>
+#include <asm/msr.h>
+
+#include <linux/irq.h>
+
+/* The global kernel spinlock */
+spinlock_t kernel_flag = SPIN_LOCK_UNLOCKED;
+
+/* TLB state -- visible externally, indexed physically */
+struct tlb_state cpu_tlbstate[NR_CPUS] = {[0 ... NR_CPUS-1] = { &init_mm, 0 }};
+
+/* CPU IRQ affinity -- set to all ones initially */
+static unsigned long cpu_irq_affinity[NR_CPUS] = { [0 ... NR_CPUS-1]  = ~0UL };
+
+/* Set when the idlers are all forked - Set in main.c but not actually
+ * used by any other parts of the kernel */
+int smp_threads_ready = 0;
+
+/* per CPU data structure (for /proc/cpuinfo et al), visible externally
+ * indexed physically */
+struct cpuinfo_x86 cpu_data[NR_CPUS];
+
+/* physical ID of the CPU used to boot the system */
+unsigned char boot_cpu_id;
+
+/* which logical number maps to which CPU */
+volatile int __cpu_logical_map[NR_CPUS];
+
+/* which physical CPU maps to which logical number */
+volatile int __cpu_number_map[NR_CPUS];
+
+/* The memory line addresses for the Quad CPIs */
+struct voyager_qic_cpi *voyager_quad_cpi_addr[NR_CPUS];
+
+/* The masks for the Extended VIC processors, filled in by cat_init */
+__u32 voyager_extended_vic_processors = 0;
+
+/* The mask for the Quad Processors (both extended and non-extended) */
+__u32 voyager_quad_processors = 0;
+
+/* Total count of live CPUs, used in process.c to display
+ * the CPU information and in irq.c for the per CPU irq
+ * activity count.  Finally exported by i386_ksyms.c */
+int smp_num_cpus = 1;
+static int voyager_extended_cpus = 1;
+
+/* Have we found an SMP box - used by time.c to do the profiling
+   interrupt for timeslicing; do not set to 1 until the per CPU timer
+   interrupt is active */
+int smp_found_config = 0;
+
+/* Used for the invalidate map that's also checked in the spinlock */
+volatile unsigned long smp_invalidate_needed;
+
+/* Bitmask of currently online CPUs - used by setup.c for
+   /proc/cpuinfo, visible externally but still physical */
+unsigned long cpu_online_map = 0;
+
+/* Bitmask of CPUs present in the system - exported by i386_syms.c, used
+ * by scheduler but indexed physically */
+unsigned long cpu_present_map = 0;
+
+/* estimate of time used to flush the SMP-local cache - used in
+ * processor affinity calculations */
+cycles_t cacheflush_time = 0;
+
+/* The internal functions */
+static void send_CPI(__u32 cpuset, __u8 cpi);
+static void ack_CPI(__u8 cpi);
+static int ack_QIC_CPI(__u8 cpi);
+static void ack_VIC_CPI(__u8 cpi);
+static void send_CPI_allbutself(__u8 cpi);
+static void enable_vic_irq(unsigned int irq);
+static void disable_vic_irq(unsigned int irq);
+static unsigned int startup_vic_irq(unsigned int irq);
+static void enable_local_vic_irq(unsigned int irq);
+static void disable_local_vic_irq(unsigned int irq);
+static void before_handle_vic_irq(unsigned int irq);
+static void after_handle_vic_irq(unsigned int irq);
+static void set_vic_irq_affinity(unsigned int irq, unsigned long mask);
+static void ack_vic_irq(unsigned int irq);
+static void vic_enable_cpi(void);
+static void do_boot_cpu(__u8 cpuid);
+static void do_quad_bootstrap(void);
+
+int hard_smp_processor_id(void);
+
+/* Inline functions */
+static inline void
+send_one_QIC_CPI(__u8 cpu, __u8 cpi)
+{
+	voyager_quad_cpi_addr[cpu]->qic_cpi[cpi].cpi =
+		(smp_processor_id() << 16) + cpi;
+}
+
+static inline void
+send_QIC_CPI(__u32 cpuset, __u8 cpi)
+{
+	int i;
+
+	for(i=0; i<smp_num_cpus; i++) {
+		__u8 cpu = __cpu_logical_map[i];
+
+		if(cpuset & (1<<cpu)) {
+#ifdef VOYAGER_DEBUG
+			if(!(cpu_online_map & (1<<cpu)))
+				VDEBUG(("CPU%d sending cpi %d to CPU%d not in cpu_online_map\n", hard_smp_processor_id(), cpi, cpu));
+#endif
+			send_one_QIC_CPI(cpu, cpi - QIC_CPI_OFFSET);
+		}
+	}
+}
+
+static inline void
+send_one_CPI(__u8 cpu, __u8 cpi)
+{
+	if(voyager_quad_processors & (1<<cpu))
+		send_one_QIC_CPI(cpu, cpi - QIC_CPI_OFFSET);
+	else
+		send_CPI(1<<cpu, cpi);
+}
+
+static inline void
+send_CPI_allbutself(__u8 cpi)
+{
+	__u8 cpu = smp_processor_id();
+	__u32 mask = (cpu_online_map & (~(1<<cpu)));
+	send_CPI(mask, cpi);
+}
+
+static inline int
+is_cpu_quad(void)
+{
+	__u8 cpumask = inb(VIC_PROC_WHO_AM_I);
+	return ((cpumask & QUAD_IDENTIFIER) == QUAD_IDENTIFIER);
+}
+
+static inline int
+is_cpu_extended(void)
+{
+	__u8 cpu = hard_smp_processor_id();
+
+	return(voyager_extended_vic_processors & (1<<cpu));
+}
+
+
+static inline void
+ack_CPI(__u8 cpi)
+{
+	switch(cpi) {
+	case VIC_CPU_BOOT_CPI:
+		if(is_cpu_quad() && !is_cpu_extended())
+			ack_QIC_CPI(cpi);
+		else
+			ack_VIC_CPI(cpi);
+		break;
+	case VIC_SYS_INT:
+	case VIC_CMN_INT: 
+		if(is_cpu_quad())
+			ack_QIC_CPI(cpi);
+		else
+			ack_VIC_CPI(cpi);
+		break;
+	default:
+		printk("VOYAGER ERROR: CPI%d is in common CPI code\n", cpi);
+		break;
+	}
+}
+
+/* local variables */
+
+/* The VIC IRQ descriptors -- these look almost identical to the
+ * 8259 IRQs except that masks and things must be kept per processor
+ */
+static struct hw_interrupt_type vic_irq_type = {
+	"VIC-level",
+	startup_vic_irq,	/* startup */
+	disable_vic_irq,	/* shutdown */
+	enable_vic_irq,		/* enable */
+	disable_vic_irq,	/* disable */
+	before_handle_vic_irq,	/* ack */
+	after_handle_vic_irq,	/* end */
+	set_vic_irq_affinity,	/* affinity */
+};
+
+/* used to count up as CPUs are brought on line (starts at 0) */
+static int cpucount = 0;
+
+/* steal a page from the bottom of memory for the trampoline and
+ * squirrel its address away here.  This will be in kernel virtual
+ * space */
+static __u32 trampoline_base;
+
+/* The per cpu profile stuff - used in smp_local_timer_interrupt */
+static unsigned int prof_multiplier[NR_CPUS] = { 1, };
+static unsigned int prof_old_multiplier[NR_CPUS] = { 1, };
+static unsigned int prof_counter[NR_CPUS] = { 1, };
+
+/* the map used to check if a CPU has booted */
+static __u32 cpu_booted_map;
+
+/* the synchronize flag used to hold all secondary CPUs spinning in
+ * a tight loop until the boot sequence is ready for them */
+static atomic_t smp_commenced = ATOMIC_INIT(0);
+
+/* The per processor IRQ masks (these are usually kept in sync) */
+static __u16 vic_irq_mask[NR_CPUS];
+
+/* the list of IRQs to be enabled by the VIC_ENABLE_IRQ_CPI */
+static __u16 vic_irq_enable_mask[NR_CPUS] = { 0 };
+
+/* Lock for enable/disable of VIC interrupts */
+static spinlock_t vic_irq_lock = SPIN_LOCK_UNLOCKED;
+
+/* The boot processor is correctly set up in PC mode when it 
+ * comes up, but the secondaries need their master/slave 8259
+ * pairs initializing correctly */
+
+/* Interrupt counters (per cpu) and total - used to try to
+ * even up the interrupt handling routines */
+static long vic_intr_total = 0;
+static long vic_intr_count[NR_CPUS] = { 0 };
+static unsigned long vic_tick[NR_CPUS] = { 0 };
+
+/* Since we can only use CPI0, we fake all the other CPIs */
+static __u32 vic_cpi_mailbox[NR_CPUS];
+
+/* debugging routine to read the isr of the cpu's pic */
+static inline __u16
+vic_read_isr(void)
+{
+	__u16 isr;
+
+	outb(0x0b, 0xa0);
+	isr = inb(0xa0) << 8;
+	outb(0x0b, 0x20);
+	isr |= inb(0x20);
+
+	return isr;
+}
+
+static __init void
+qic_setup(void)
+{
+	if(!is_cpu_quad()) {
+		/* not a quad, no setup */
+		return;
+	}
+	outb(0xff, QIC_MASK_REGISTER0);
+	outb(QIC_CPI_ENABLE, QIC_MASK_REGISTER1);
+	if(is_cpu_extended()) {
+		/* the QIC duplicate of the VIC base register */
+		outb(VIC_DEFAULT_CPI_BASE, QIC_VIC_CPI_BASE_REGISTER);
+		outb(QIC_DEFAULT_CPI_BASE, QIC_CPI_BASE_REGISTER);
+
+		/* FIXME: should set up the QIC timer and memory parity
+		 * error vectors here */
+	}
+}
+
+static __init void
+vic_setup_pic(void)
+{
+	outb(1, VIC_REDIRECT_REGISTER_1);
+	/* clear the claim registers for dynamic routing */
+	outb(0, VIC_CLAIM_REGISTER_0);
+	outb(0, VIC_CLAIM_REGISTER_1);
+
+	outb(0, VIC_PRIORITY_REGISTER);
+	/* Set the Primary and Secondary Microchannel vector
+	 * bases to be the same as the ordinary interrupts
+	 *
+	 * FIXME: This would be more efficient using separate
+	 * vectors. */
+	outb(FIRST_EXTERNAL_VECTOR, VIC_PRIMARY_MC_BASE);
+	outb(FIRST_EXTERNAL_VECTOR, VIC_SECONDARY_MC_BASE);
+	/* Now initiallise the master PIC belonging to this CPU by
+	 * sending the four ICWs */
+
+	/* ICW1: level triggered, ICW4 needed */
+	outb(0x19, 0x20);
+
+	/* ICW2: vector base */
+	outb(FIRST_EXTERNAL_VECTOR, 0x21);
+
+	/* ICW3: slave at line 2 */
+	outb(0x04, 0x21);
+
+	/* ICW4: 8086 mode */
+	outb(0x01, 0x21);
+
+	/* now the same for the slave PIC */
+
+	/* ICW1: level trigger, ICW4 needed */
+	outb(0x19, 0xA0);
+
+	/* ICW2: slave vector base */
+	outb(FIRST_EXTERNAL_VECTOR + 8, 0xA1);
+	
+	/* ICW3: slave ID */
+	outb(0x02, 0xA1);
+
+	/* ICW4: 8086 mode */
+	outb(0x01, 0xA1);
+}
+
+static void
+do_quad_bootstrap(void)
+{
+	if(is_cpu_quad() && is_cpu_extended()) {
+		int i;
+		unsigned long flags;
+		__u8 cpuid = hard_smp_processor_id();
+
+		__save_flags(flags);
+		__cli();
+
+		for(i = 0; i<4; i++) {
+			/* FIXME: this would be >>3 &0x7 on the 32 way */
+			if(((cpuid >> 2) & 0x03) == i)
+				/* don't lower our own mask! */
+				continue;
+
+			/* masquerade as local Quad CPU */
+			outb(QIC_CPUID_ENABLE | i, QIC_PROCESSOR_ID);
+			/* enable the startup CPI */
+			outb(QIC_BOOT_CPI_MASK, QIC_MASK_REGISTER1);
+			/* restore cpu id */
+			outb(0, QIC_PROCESSOR_ID);
+		}
+		__restore_flags(flags);
+	}
+}
+
+
+/* Set up all the basic stuff: read the SMP config and make all the
+ * SMP information reflect only the boot cpu.  All others will be
+ * brought on-line later. */
+void __init 
+find_smp_config(void)
+{
+	boot_cpu_id = hard_smp_processor_id();
+
+	printk("VOYAGER SMP: Boot cpu is %d\n", boot_cpu_id);
+	/* The boot CPU must be extended */
+	voyager_extended_vic_processors = 1<<boot_cpu_id;
+	/* set up everything for just this CPU, we can alter
+	 * this as we start the other CPUs later */
+	/* now get the CPU disposition from the extended CMOS */
+	cpu_present_map = voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK);
+	cpu_present_map |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 1) << 8;
+	cpu_present_map |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 2) << 16;
+	cpu_present_map |= voyager_extended_cmos_read(VOYAGER_PROCESSOR_PRESENT_MASK + 3) << 24;
+	printk("VOYAGER SMP: cpu_present_map = 0x%lx\n", cpu_present_map);
+	/* Here we set up the VIC to enable SMP */
+	/* enable the CPIs by writing the base vector to their register */
+	outb(VIC_DEFAULT_CPI_BASE, VIC_CPI_BASE_REGISTER);
+	outb(1, VIC_REDIRECT_REGISTER_1);
+	/* set the claim registers for static routing --- Boot CPU gets
+	 * all interrupts untill all other CPUs started */
+	outb(0xff, VIC_CLAIM_REGISTER_0);
+	outb(0xff, VIC_CLAIM_REGISTER_1);
+	/* Set the Primary and Secondary Microchannel vector
+	 * bases to be the same as the ordinary interrupts
+	 *
+	 * FIXME: This would be more efficient using separate
+	 * vectors. */
+	outb(FIRST_EXTERNAL_VECTOR, VIC_PRIMARY_MC_BASE);
+	outb(FIRST_EXTERNAL_VECTOR, VIC_SECONDARY_MC_BASE);
+
+	/* Finally tell the firmware that we're driving */
+	outb(inb(VOYAGER_SUS_IN_CONTROL_PORT) | VOYAGER_IN_CONTROL_FLAG,
+	     VOYAGER_SUS_IN_CONTROL_PORT);
+
+}
+
+/*
+ *	The bootstrap kernel entry code has set these up. Save them
+ *	for a given CPU, id is physical */
+void __init
+smp_store_cpu_info(int id)
+{
+	struct cpuinfo_x86 *c=&cpu_data[id];
+
+	*c = boot_cpu_data;
+	c->pte_quick = 0;
+	c->pmd_quick = 0;
+	c->pgd_quick = 0;
+	c->pgtable_cache_sz = 0;
+	identify_cpu(c);
+}
+
+/* set up the trampoline and return the physical address of the code */
+static __u32 __init
+setup_trampoline(void)
+{
+	/* these two are global symbols in trampoline.S */
+	extern __u8 trampoline_end[];
+	extern __u8 trampoline_data[];
+
+	memcpy((__u8 *)trampoline_base, trampoline_data,
+	       trampoline_end - trampoline_data);
+	return virt_to_phys((__u8 *)trampoline_base);
+}
+
+/* Routine initially called when a non-boot CPU is brought online */
+int __init
+start_secondary(void *unused)
+{
+	__u8 cpuid = hard_smp_processor_id();
+	/* external functions not defined in the headers */
+	extern void calibrate_delay(void);
+	extern int cpu_idle(void);
+
+	cpu_init();
+
+	/* OK, we're in the routine */
+	ack_CPI(VIC_CPU_BOOT_CPI);
+
+	/* setup the 8259 master slave pair belonging to this CPU ---
+         * we won't actually receive any until the boot CPU
+         * relinquishes it's static routing mask */
+	vic_setup_pic();
+
+	qic_setup();
+
+	if(is_cpu_quad() && !is_cpu_extended()) {
+		/* clear the boot CPI */
+		__u8 dummy;
+
+		dummy = voyager_quad_cpi_addr[cpuid]->qic_cpi[VIC_CPU_BOOT_CPI].cpi;
+		printk("read dummy %d\n", dummy);
+	}
+
+	/* lower the mask to receive CPIs */
+	vic_enable_cpi();
+
+	VDEBUG(("VOYAGER SMP: CPU%d, stack at about %p\n", cpuid, &cpuid));
+
+	/* enable interrupts */
+	sti();
+
+	/* get our bogomips */
+	calibrate_delay();
+
+	/* save our processor parameters */
+	smp_store_cpu_info(cpuid);
+
+	/* if we're a quad, we may need to bootstrap other CPUs */
+	do_quad_bootstrap();
+
+	VDEBUG(("VOYAGER DEBUG LOGICAL CPU%d, PHYS CPU%d: set cpu_booted_map going into spin\n",
+		__cpu_number_map[cpuid], __cpu_logical_map[cpucount]));
+
+	/* signal that we're done */
+	cpu_booted_map = 1;
+
+	while(!atomic_read(&smp_commenced))
+		rep_nop();
+
+	local_flush_tlb();
+	
+	return cpu_idle();
+}
+
+static int __init
+fork_by_hand(void)
+{
+	struct pt_regs regs;
+	/* don't care about the eip and regs settings since we'll
+	 * never reschedule the forked task. */
+	return do_fork(CLONE_VM|CLONE_PID, 0, &regs, 0);
+}
+
+
+/* Routine to kick start the given CPU and wait for it to report ready
+ * (or timeout in startup).  When this routine returns, the requested
+ * CPU is either fully running and configured or known to be dead.
+ *
+ * We call this routine sequentially 1 CPU at a time, so no need for
+ * locking */
+
+static void __init
+do_boot_cpu(__u8 cpu)
+{
+	struct task_struct *idle;
+	int timeout;
+	unsigned long flags;
+	int quad_boot = (1<<cpu) & voyager_quad_processors 
+		& ~voyager_extended_vic_processors;
+
+	/* For the 486, we can't use the 4Mb page table trick, so
+	 * must map a region of memory */
+#ifdef CONFIG_M486
+	int i;
+	unsigned long *page_table_copies = (unsigned long *)
+		__get_free_page(GFP_KERNEL);
+#endif
+	pgd_t orig_swapper_pg_dir0;
+
+	/* This is an area in head.S which was used to set up the
+	 * initial kernel stack.  We need to alter this to give the
+	 * booting CPU a new stack (taken from its idle process) */
+	extern struct {
+		__u8 *esp;
+		unsigned short ss;
+	} stack_start;
+	/* This is the format of the CPI IDT gate (in real mode) which
+	 * we're hijacking to boot the CPU */
+	union 	IDTFormat {
+		struct seg {
+			__u16	Offset;
+			__u16	Segment;
+		} idt;
+		__u32 val;
+	} hijack_source;
+
+	__u32 *hijack_vector;
+	__u32 start_phys_address = setup_trampoline();
+
+	/* There's a clever trick to this: The linux trampoline is
+	 * compiled to begin at absolute location zero, so make the
+	 * address zero but have the data segment selector compensate
+	 * for the actual address */
+	hijack_source.idt.Offset = start_phys_address & 0x000F;
+	hijack_source.idt.Segment = (start_phys_address >> 4) & 0xFFFF;
+
+	cpucount++;
+	if(fork_by_hand() < 0)
+		panic("failed fork for CPU%d", cpu);
+
+	idle = init_task.prev_task;
+	if (!idle)
+		panic("No idle process for CPU %d", cpu);
+	idle->processor = cpu;
+	__cpu_logical_map[cpucount] = cpu;
+	__cpu_number_map[cpu] = cpucount;
+	idle->has_cpu = 1; /* we schedule the first task manually */
+	idle->thread.eip = (unsigned long) start_secondary;
+	del_from_runqueue(idle);
+	unhash_process(idle);
+	/* init_tasks (in sched.c) is indexed logically */
+	init_tasks[cpucount] = idle;
+	stack_start.esp = (1024 + PAGE_SIZE + (__u8 *)idle);
+	/* Note: Don't modify initial ss override */
+	VDEBUG(("VOYAGER SMP: Booting CPU%d at 0x%lx[%x:%x], stack %p\n", cpu, 
+		(unsigned long)hijack_source.val, hijack_source.idt.Segment,
+		hijack_source.idt.Offset, stack_start.esp));
+	/* set the original swapper_pg_dir[0] to map 0 to 4Mb transparently
+	 * (so that the booting CPU can find start_32 */
+	orig_swapper_pg_dir0 = swapper_pg_dir[0];
+#ifdef CONFIG_M486
+	if(page_table_copies == NULL)
+		panic("No free memory for 486 page tables\n");
+	for(i = 0; i < PAGE_SIZE/sizeof(unsigned long); i++)
+		page_table_copies[i] = (i * PAGE_SIZE) 
+			| _PAGE_RW | _PAGE_USER | _PAGE_PRESENT;
+
+	((unsigned long *)swapper_pg_dir)[0] = 
+		((virt_to_phys(page_table_copies)) & PAGE_MASK)
+		| _PAGE_RW | _PAGE_USER | _PAGE_PRESENT;
+#else
+	((unsigned long *)swapper_pg_dir)[0] = 0x102007;
+#endif
+
+	if(quad_boot) {
+		printk("CPU %d: non extended Quad boot\n", cpu);
+		hijack_vector = (__u32 *)phys_to_virt((VIC_CPU_BOOT_CPI + QIC_DEFAULT_CPI_BASE)*4);
+		*hijack_vector = hijack_source.val;
+	} else {
+		printk("CPU%d: extended VIC boot\n", cpu);
+		hijack_vector = (__u32 *)phys_to_virt((VIC_CPU_BOOT_CPI + VIC_DEFAULT_CPI_BASE)*4);
+		*hijack_vector = hijack_source.val;
+		/* VIC errata, may also receive interrupt at this address */
+		hijack_vector = (__u32 *)phys_to_virt((VIC_CPU_BOOT_ERRATA_CPI + VIC_DEFAULT_CPI_BASE)*4);
+		*hijack_vector = hijack_source.val;
+	}
+	/* All non-boot CPUs start with interrupts fully masked.  Need
+	 * to lower the mask of the CPI we're about to send.  We do
+	 * this in the VIC by masquerading as the processor we're
+	 * about to boot and lowering its interrupt mask */
+	__save_flags(flags);
+	__cli();
+	if(quad_boot) {
+		send_one_QIC_CPI(cpu, VIC_CPU_BOOT_CPI);
+	} else {
+		outb(VIC_CPU_MASQUERADE_ENABLE | cpu, VIC_PROCESSOR_ID);
+		/* here we're altering registers belonging to `cpu' */
+		
+		outb(VIC_BOOT_INTERRUPT_MASK, 0x21);
+		/* now go back to our original identity */
+		outb(boot_cpu_id, VIC_PROCESSOR_ID);
+
+		/* and boot the CPU */
+
+		send_CPI((1<<cpu), VIC_CPU_BOOT_CPI);
+	}
+	cpu_booted_map = 0;
+	__restore_flags(flags);
+
+	/* now wait for it to become ready (or timeout) */
+	for(timeout = 0; timeout < 50000; timeout++) {
+		if(cpu_booted_map)
+			break;
+		udelay(100);
+	}
+	/* reset the page table */
+	swapper_pg_dir[0] = orig_swapper_pg_dir0;
+	local_flush_tlb();
+#ifdef CONFIG_M486
+	free_page((unsigned long)page_table_copies);
+#endif
+	  
+	if(cpu_booted_map) {
+		__cpu_number_map[cpu] = cpucount;
+		__cpu_logical_map[cpucount] = cpu;
+
+		VDEBUG(("CPU%d: Booted successfully, back in CPU %d\n",
+			cpu, smp_processor_id()));
+	
+		printk("CPU%d: ", cpu);
+		print_cpu_info(&cpu_data[cpu]);
+		cpu_online_map |= (1<<cpu);
+	}
+	else {
+		__cpu_number_map[cpu] = -1;
+		__cpu_logical_map[cpucount] = -1;
+		printk("CPU%d FAILED TO BOOT: ", cpu);
+		if (*((volatile unsigned char *)phys_to_virt(start_phys_address))==0xA5)
+			printk("Stuck.\n");
+		else
+			printk("Not responding.\n");
+		
+		cpucount--;
+	}
+}
+
+void __init
+smp_boot_cpus(void)
+{
+	int i;
+
+	/* CAT BUS initialisation must be done after the memory */
+	voyager_cat_init();
+
+	/* now that the cat has probed the Voyager System Bus, sanity
+	 * check the cpu map */
+	if( ((voyager_quad_processors | voyager_extended_vic_processors)
+	     & cpu_present_map) != cpu_present_map) {
+		/* should panic */
+		printk("\n\n***WARNING*** Sanity check of CPU present map FAILED\n");
+	}
+
+	/* this sets up the idle task to run on the current cpu */
+	smp_num_cpus = 1;
+	voyager_extended_cpus = 1;
+	current->processor = boot_cpu_id;
+	for(i=0; i<NR_CPUS; i++) {
+		__cpu_logical_map[i] = -1;
+		__cpu_number_map[i] = -1;
+		prof_counter[i] = 1;
+		prof_old_multiplier[i] = 1;
+		prof_multiplier[i] = 1;
+		cpu_irq_affinity[i] = ~0;
+	}
+	__cpu_logical_map[0] = boot_cpu_id;
+	__cpu_number_map[boot_cpu_id] = 0;
+	global_irq_holder = boot_cpu_id;
+	cpu_online_map = (1<<boot_cpu_id);
+	init_idle();
+
+	smp_store_cpu_info(boot_cpu_id);
+	printk("CPU%d: ", boot_cpu_id);
+	print_cpu_info(&cpu_data[boot_cpu_id]);
+
+	if(is_cpu_quad()) {
+		/* booting on a Quad CPU */
+		printk("VOYAGER SMP: Boot CPU is Quad\n");
+		qic_setup();
+		do_quad_bootstrap();
+	}
+
+	/* enable our own CPIs */
+	vic_enable_cpi();
+	
+	/* loop over all the extended VIC CPUs and boot them.  The 
+	 * Quad CPUs must be bootstrapped by their extended VIC cpu */
+	for(i = 0; i < NR_CPUS; i++) {
+		if( i == boot_cpu_id || ((1<<i) & (cpu_present_map) ) == 0)
+			continue;
+		do_boot_cpu(i);
+		/* This udelay seems to be needed for the Quad boots
+		 * don't remove unless you know what you're doing */
+		udelay(1000);
+	}
+	/* we could compute the total bogomips here, but why bother? */
+	smp_num_cpus = cpucount + 1;
+	voyager_extended_cpus = 0;
+	for(i=0; i < smp_num_cpus; i++) {
+		__u8 cpu = __cpu_logical_map[i];
+		if((1<<cpu) & voyager_extended_vic_processors) {
+			voyager_extended_cpus++;
+		}
+	}
+	printk("VOYAGER: Extended (interrupt handling CPUs): %d, non-extended: %d\n", voyager_extended_cpus, smp_num_cpus - voyager_extended_cpus);
+	/* that's it, switch to symmetric mode */
+	outb(0, VIC_PRIORITY_REGISTER);
+	outb(0, VIC_CLAIM_REGISTER_0);
+	outb(0, VIC_CLAIM_REGISTER_1);
+	
+	VDEBUG(("VOYAGER SMP: Booted with %d CPUs\n", smp_num_cpus));
+
+	zap_low_mappings();
+}
+
+void __init
+smp_commence(void)
+{
+	VDEBUG(("VOYAGER SMP: Releasing all secondaries from spin\n"));
+
+	atomic_set(&smp_commenced, 1);
+}
+
+/* Reload the secondary CPUs task structure (this function does not
+ * return ) */
+void __init 
+initialize_secondary(void)
+{
+	struct thread_struct * p = &current->thread;
+
+	/*
+	 * We don't actually need to load the full TSS,
+	 * basically just the stack pointer and the eip.
+	 */
+
+	asm volatile(
+		"movl %0,%%esp\n\t"
+		"jmp *%1"
+		:
+		:"r" (p->esp),"r" (p->eip));
+}
+
+/* handle a Voyager SYS_INT -- If we don't, the base board will
+ * panic the system.
+ *
+ * System interrupts occur because some problem was detected on the
+ * various busses.  To find out what you have to probe all the
+ * hardware via the CAT bus.  FIXME: At the moment we do nothing. */
+asmlinkage void
+smp_vic_sys_interrupt(void)
+{
+	ack_CPI(VIC_SYS_INT);
+	printk("Voyager SYSTEM INTERRUPT\n");
+}
+
+/* Handle a voyager CMN_INT; These interrupts occur either because of
+ * a system status change or because a single bit memory error
+ * occurred.  FIXME: At the moment, ignore all this. */
+asmlinkage void
+smp_vic_cmn_interrupt(void)
+{
+	ack_CPI(VIC_CMN_INT);
+	printk("Voyager COMMON INTERRUPT\n");
+}
+
+/*
+ * Reschedule call back. Nothing to do, all the work is done
+ * automatically when we return from the interrupt.  */
+asmlinkage void
+smp_reschedule_interrupt(void)
+{
+	/* do nothing */
+}
+
+static struct mm_struct * flush_mm;
+static unsigned long flush_va;
+static spinlock_t tlbstate_lock = SPIN_LOCK_UNLOCKED;
+#define FLUSH_ALL	0xffffffff
+
+/*
+ * We cannot call mmdrop() because we are in interrupt context, 
+ * instead update mm->cpu_vm_mask.
+ */
+static void inline 
+leave_mm (unsigned long cpu)
+{
+	if (cpu_tlbstate[cpu].state == TLBSTATE_OK)
+		BUG();
+	clear_bit(cpu,  &cpu_tlbstate[cpu].active_mm->cpu_vm_mask);
+}
+
+
+/*
+ * Invalidate call-back
+ */
+asmlinkage void 
+smp_invalidate_interrupt(void)
+{
+	__u8 cpu = smp_processor_id();
+
+	if(!test_bit(cpu, &smp_invalidate_needed))
+		return;
+	/* This will flood messages.  Don't uncomment unless you see
+	 * Problems with cross cpu invalidation
+	VDEBUG(("VOYAGER SMP: CPU%d received INVALIDATE_CPI\n",
+		smp_processor_id()));
+	*/
+
+	if (flush_mm == cpu_tlbstate[cpu].active_mm) {
+		if (cpu_tlbstate[cpu].state == TLBSTATE_OK) {
+			if (flush_va == FLUSH_ALL)
+				local_flush_tlb();
+			else
+				__flush_tlb_one(flush_va);
+		} else
+			leave_mm(cpu);
+	}
+	clear_bit(cpu, &smp_invalidate_needed);
+}
+
+/* All the new flush operations for 2.4 */
+
+
+/* This routine is called with a physical cpu mask */
+static void
+flush_tlb_others (unsigned long cpumask, struct mm_struct *mm,
+						unsigned long va)
+{
+	int stuck = 50000;
+
+	if (!cpumask)
+		BUG();
+	if ((cpumask & cpu_online_map) != cpumask)
+		BUG();
+	if (cpumask & (1 << smp_processor_id()))
+		BUG();
+	if (!mm)
+		BUG();
+
+	spin_lock(&tlbstate_lock);
+	
+	flush_mm = mm;
+	flush_va = va;
+	atomic_set_mask(cpumask, &smp_invalidate_needed);
+	/*
+	 * We have to send the CPI only to
+	 * CPUs affected.
+	 */
+	send_CPI(cpumask, VIC_INVALIDATE_CPI);
+
+	while (smp_invalidate_needed) {
+		if(--stuck == 0) {
+			printk("***WARNING*** Stuck doing invalidate CPI (CPU%d)\n", smp_processor_id());
+			break;
+		}
+	}
+
+	/* Uncomment only to debug invalidation problems
+	VDEBUG(("VOYAGER SMP: Completed invalidate CPI (CPU%d)\n", cpu));
+	*/
+
+	flush_mm = NULL;
+	flush_va = 0;
+	spin_unlock(&tlbstate_lock);
+}
+
+void
+flush_tlb_current_task(void)
+{
+	struct mm_struct *mm = current->mm;
+	unsigned long cpu_mask = mm->cpu_vm_mask & ~(1 << smp_processor_id());
+
+	local_flush_tlb();
+	if (cpu_mask)
+		flush_tlb_others(cpu_mask, mm, FLUSH_ALL);
+}
+
+
+void
+flush_tlb_mm (struct mm_struct * mm)
+{
+	unsigned long cpu_mask = mm->cpu_vm_mask & ~(1 << smp_processor_id());
+
+	if (current->active_mm == mm) {
+		if (current->mm)
+			local_flush_tlb();
+		else
+			leave_mm(smp_processor_id());
+	}
+	if (cpu_mask)
+		flush_tlb_others(cpu_mask, mm, FLUSH_ALL);
+}
+
+void flush_tlb_page(struct vm_area_struct * vma, unsigned long va)
+{
+	struct mm_struct *mm = vma->vm_mm;
+	unsigned long cpu_mask = mm->cpu_vm_mask & ~(1 << smp_processor_id());
+
+	if (current->active_mm == mm) {
+		if(current->mm)
+			__flush_tlb_one(va);
+		 else
+		 	leave_mm(smp_processor_id());
+	}
+
+	if (cpu_mask)
+		flush_tlb_others(cpu_mask, mm, va);
+}
+
+/* enable the requested IRQs */
+asmlinkage void
+smp_enable_irq_interrupt(void)
+{
+	__u8 irq;
+	__u8 cpu = smp_processor_id();
+
+	VDEBUG(("VOYAGER SMP: CPU%d enabling irq mask 0x%x\n", cpu,
+	       vic_irq_enable_mask[cpu]));
+
+	spin_lock(&vic_irq_lock);
+	for(irq = 0; irq < 16; irq++) {
+		if(vic_irq_enable_mask[cpu] & (1<<irq))
+			enable_local_vic_irq(irq);
+	}
+	vic_irq_enable_mask[cpu] = 0;
+	spin_unlock(&vic_irq_lock);
+}
+	
+/*
+ *	CPU halt call-back
+ */
+static void
+smp_stop_cpu_function(void *dummy)
+{
+	VDEBUG(("VOYAGER SMP: CPU%d is STOPPING\n", smp_processor_id()));
+	clear_bit(smp_processor_id(), &cpu_online_map);
+	__cli();
+	for(;;)
+	       __asm__("hlt");
+}
+
+static spinlock_t call_lock = SPIN_LOCK_UNLOCKED;
+
+struct call_data_struct {
+	void (*func) (void *info);
+	void *info;
+	volatile __u32 started;
+	volatile __u32 finished;
+	int wait;
+};
+
+static struct call_data_struct * call_data;
+
+/* execute a thread on a new CPU.  The function to be called must be
+ * previously set up.  This is used to schedule a function for
+ * execution on all CPU's - set up the function then broadcast a
+ * function_interrupt CPI to come here on each CPU */
+asmlinkage void
+smp_call_function_interrupt(void)
+{
+	void (*func) (void *info) = call_data->func;
+	void *info = call_data->info;
+	/* must take copy of wait because call_data may be replaced
+	 * unless the function is waiting for us to finish */
+	int wait = call_data->wait;
+	__u8 cpu = smp_processor_id();
+
+	/*
+	 * Notify initiating CPU that I've grabbed the data and am
+	 * about to execute the function
+	 */
+	if(!test_and_clear_bit(cpu, &call_data->started)) {
+		/* If the bit wasn't set, this could be a replay */
+		printk(KERN_WARNING "VOYAGER SMP: CPU %d received call funtion with no call pending\n", cpu);
+		return;
+	}
+	/*
+	 * At this point the info structure may be out of scope unless wait==1
+	 */
+	(*func)(info);
+	if (wait)
+		clear_bit(cpu, &call_data->finished);
+}
+
+/* Call this function on all CPUs using the function_interrupt above 
+    <func> The function to run. This must be fast and non-blocking.
+    <info> An arbitrary pointer to pass to the function.
+    <retry> If true, keep retrying until ready.
+    <wait> If true, wait until function has completed on other CPUs.
+    [RETURNS] 0 on success, else a negative status code. Does not return until
+    remote CPUs are nearly ready to execute <<func>> or are or have executed.
+*/
+int
+smp_call_function (void (*func) (void *info), void *info, int retry,
+		   int wait)
+{
+	struct call_data_struct data;
+	__u32 mask = cpu_online_map;
+
+	mask &= ~(1<<smp_processor_id());
+
+	if (!mask)
+		return 0;
+
+	data.func = func;
+	data.info = info;
+	data.started = mask;
+	data.wait = wait;
+	if (wait)
+		data.finished = mask;
+
+	spin_lock_bh(&call_lock);
+	call_data = &data;
+	/* Send a message to all other CPUs and wait for them to respond */
+	send_CPI_allbutself(VIC_CALL_FUNCTION_CPI);
+
+	/* Wait for response */
+	while (data.started)
+		barrier();
+
+	if (wait)
+		while (data.finished)
+			barrier();
+	spin_unlock_bh(&call_lock);
+
+	return 0;
+}
+
+/* Sorry about the name.  In an APIC based system, the APICs
+ * themselves are programmed to send a timer interrupt.  This is used
+ * by linux to reschedule the processor.  Voyager doesn't have this,
+ * so we use the system clock to interrupt one processor, which in
+ * turn, broadcasts a timer CPI to all the others --- we receive that
+ * CPI here.  We don't use this actually for counting so losing
+ * ticks doesn't matter 
+ *
+ * FIXME: For those CPU's which actually have a local APIC, we could
+ * try to use it to trigger this interrupt instead of having to
+ * broadcast the timer tick.  Unfortunately, all my pentium DYADs have
+ * no local APIC, so I can't do this */
+asmlinkage void 
+smp_apic_timer_interrupt(struct pt_regs * regs)
+{
+	smp_local_timer_interrupt(regs);
+}
+
+/* All of the QUAD interrupt GATES */
+asmlinkage void
+smp_qic_timer_interrupt(struct pt_regs *regs)
+{
+	ack_QIC_CPI(QIC_TIMER_CPI);
+	smp_local_timer_interrupt(regs);
+}
+
+asmlinkage void
+smp_qic_invalidate_interrupt(void)
+{
+	ack_QIC_CPI(QIC_INVALIDATE_CPI);
+	smp_invalidate_interrupt();
+}
+
+asmlinkage void
+smp_qic_reschedule_interrupt(void)
+{
+	ack_QIC_CPI(QIC_RESCHEDULE_CPI);
+	smp_reschedule_interrupt();
+}
+
+asmlinkage void
+smp_qic_enable_irq_interrupt(void)
+{
+	ack_QIC_CPI(QIC_ENABLE_IRQ_CPI);
+	smp_enable_irq_interrupt();
+}
+
+asmlinkage void
+smp_qic_call_function_interrupt(void)
+{
+	ack_QIC_CPI(QIC_CALL_FUNCTION_CPI);
+	smp_call_function_interrupt();
+}
+
+asmlinkage void
+smp_vic_cpi_interrupt(struct pt_regs *regs)
+{
+	__u8 cpu = smp_processor_id();
+
+	if(is_cpu_quad())
+		ack_QIC_CPI(VIC_CPI_LEVEL0);
+	else
+		ack_VIC_CPI(VIC_CPI_LEVEL0);
+
+	if(test_and_clear_bit(VIC_TIMER_CPI, &vic_cpi_mailbox[cpu]))
+		smp_local_timer_interrupt(regs);
+	if(test_and_clear_bit(VIC_INVALIDATE_CPI, &vic_cpi_mailbox[cpu]))
+		smp_invalidate_interrupt();
+	if(test_and_clear_bit(VIC_RESCHEDULE_CPI, &vic_cpi_mailbox[cpu]))
+		smp_reschedule_interrupt();
+	if(test_and_clear_bit(VIC_ENABLE_IRQ_CPI, &vic_cpi_mailbox[cpu]))
+		smp_enable_irq_interrupt();
+	if(test_and_clear_bit(VIC_CALL_FUNCTION_CPI, &vic_cpi_mailbox[cpu]))
+		smp_call_function_interrupt();
+}
+
+static inline void
+do_flush_tlb_all_local(void)
+{
+	unsigned long cpu = smp_processor_id();
+
+	__flush_tlb_all();
+	if (cpu_tlbstate[cpu].state == TLBSTATE_LAZY)
+		leave_mm(cpu);
+}
+
+
+static void
+flush_tlb_all_function(void* info)
+{
+	do_flush_tlb_all_local();
+}
+
+/* flush the TLB of every active CPU in the system */
+void
+flush_tlb_all(void)
+{
+	smp_call_function (flush_tlb_all_function, 0, 1, 1);
+
+	do_flush_tlb_all_local();
+}
+
+/* used to set up the trampoline for other CPUs when the memory manager
+ * is sorted out */
+void __init
+smp_alloc_memory(void)
+{
+	trampoline_base = (__u32)alloc_bootmem_low_pages(PAGE_SIZE);
+	if(__pa(trampoline_base) >= 0x93000)
+		BUG();
+}
+
+/* send a reschedule CPI to one CPU by physical CPU number*/
+void
+smp_send_reschedule(int cpu)
+{
+	send_one_CPI(cpu, VIC_RESCHEDULE_CPI);
+}
+
+
+int
+hard_smp_processor_id(void)
+{
+	__u8 i;
+	__u8 cpumask = inb(VIC_PROC_WHO_AM_I);
+	if((cpumask & QUAD_IDENTIFIER) == QUAD_IDENTIFIER)
+		return cpumask & 0x1F;
+
+	for(i = 0; i < 8; i++) {
+		if(cpumask & (1<<i))
+			return i;
+	}
+	printk("** WARNING ** Illegal cpuid returned by VIC: %d", cpumask);
+	return 0;
+}
+
+/* broadcast a halt to all other CPUs */
+void
+smp_send_stop(void)
+{
+	smp_call_function(smp_stop_cpu_function, NULL, 1, 1);
+}
+
+/* this function is triggered in time.c when a clock tick fires
+ * we need to re-broadcast the tick to all CPUs */
+void
+smp_vic_timer_interrupt(struct pt_regs *regs)
+{
+	send_CPI_allbutself(VIC_TIMER_CPI);
+	smp_local_timer_interrupt(regs);
+}
+
+/* local (per CPU) timer interrupt.  It does both profiling and
+ * process statistics/rescheduling.
+ *
+ * We do profiling in every local tick, statistics/rescheduling
+ * happen only every 'profiling multiplier' ticks. The default
+ * multiplier is 1 and it can be changed by writing the new multiplier
+ * value into /proc/profile.
+ */
+void
+smp_local_timer_interrupt(struct pt_regs * regs)
+{
+	int user = user_mode(regs);
+	int cpu = smp_processor_id();
+	long weight;
+	/*
+	 * The profiling function is SMP safe. (nothing can mess
+	 * around with "current", and the profiling counters are
+	 * updated with atomic operations). This is especially
+	 * useful with a profiling multiplier != 1
+	 */
+	if (!user)
+		x86_do_profile(regs->eip);
+
+	if (--prof_counter[cpu] <= 0) {
+		/*
+		 * The multiplier may have changed since the last time we got
+		 * to this point as a result of the user writing to
+		 * /proc/profile. In this case we need to adjust the APIC
+		 * timer accordingly.
+		 *
+		 * Interrupts are already masked off at this point.
+		 */
+		prof_counter[cpu] = prof_multiplier[cpu];
+		if (prof_counter[cpu] != prof_old_multiplier[cpu]) {
+			/* FIXME: need to update the vic timer tick here */
+			prof_old_multiplier[cpu] = prof_counter[cpu];
+		}
+
+#ifdef CONFIG_SMP
+		update_process_times(user);
+#endif
+	}
+	if( ((1<<cpu) & voyager_extended_vic_processors) == 0)
+		/* only extended VIC processors participate in
+		 * interrupt distribution */
+		return;
+
+	/*
+	 * We take the 'long' return path, and there every subsystem
+	 * grabs the apropriate locks (kernel lock/ irq lock).
+	 *
+	 * we might want to decouple profiling from the 'long path',
+	 * and do the profiling totally in assembly.
+	 *
+	 * Currently this isn't too much of an issue (performance wise),
+	 * we can take more than 100K local irqs per second on a 100 MHz P5.
+	 */
+
+	if((++vic_tick[cpu] & 0x7) != 0)
+		return;
+	/* get here every 16 ticks (about every 1/6 of a second) */
+
+	/* Change our priority to give someone else a chance at getting
+         * the IRQ. The algorithm goes like this:
+	 *
+	 * In the VIC, the dynamically routed interrupt is always
+	 * handled by the lowest priority eligible (i.e. receiving
+	 * interrupts) CPU.  If >1 eligible CPUs are equal lowest, the
+	 * lowest processor number gets it.
+	 *
+	 * The priority of a CPU is controlled by a special per-CPU
+	 * VIC priority register which is 3 bits wide 0 being lowest
+	 * and 7 highest priority..
+	 *
+	 * Therefore we subtract the average number of interrupts from
+	 * the number we've fielded.  If this number is negative, we
+	 * lower the activity count and if it is positive, we raise
+	 * it.
+	 *
+	 * I'm afraid this still leads to odd looking interrupt counts:
+	 * the totals are all roughly equal, but the individual ones
+	 * look rather skewed.
+	 *
+	 * FIXME: This algorithm is total crap when mixed with SMP
+	 * affinity code since we now try to even up the interrupt
+	 * counts when an affinity binding is keeping them on a
+	 * particular CPU*/
+	weight = (vic_intr_count[cpu]*voyager_extended_cpus
+		  - vic_intr_total) >> 4;
+	weight += 4;
+	if(weight > 7)
+		weight = 7;
+	if(weight < 0)
+		weight = 0;
+	
+	outb((__u8)weight, VIC_PRIORITY_REGISTER);
+
+#ifdef VOYAGER_DEBUG
+	if((vic_tick[cpu] & 0xFFF) == 0) {
+		/* print this message roughly every 25 secs */
+		printk("VOYAGER SMP: vic_tick[%d] = %lu, weight = %ld\n",
+		       cpu, vic_tick[cpu], weight);
+	}
+#endif
+}
+
+/* setup the profiling timer */
+int 
+setup_profiling_timer(unsigned int multiplier)
+{
+	int i;
+
+	if ( (!multiplier))
+		return -EINVAL;
+
+	/* 
+	 * Set the new multiplier for each CPU. CPUs don't start using the
+	 * new values until the next timer interrupt in which they do process
+	 * accounting.
+	 */
+	for (i = 0; i < NR_CPUS; ++i)
+		prof_multiplier[i] = multiplier;
+
+	return 0;
+}
+
+
+/* initialise the voyager interrupt gates 
+ *
+ * This uses the macros in irq.h to set up assembly jump gates.  The
+ * calls are then redirected to the same routine with smp_ prefixed */
+BUILD_SMP_INTERRUPT(vic_sys_interrupt, VIC_SYS_INT)
+BUILD_SMP_INTERRUPT(vic_cmn_interrupt, VIC_CMN_INT)
+BUILD_SMP_TIMER_INTERRUPT(vic_cpi_interrupt, VIC_CPI_LEVEL0);
+
+/* do all the QIC interrupts */
+BUILD_SMP_TIMER_INTERRUPT(qic_timer_interrupt, QIC_TIMER_CPI);
+BUILD_SMP_INTERRUPT(qic_invalidate_interrupt, QIC_INVALIDATE_CPI);
+BUILD_SMP_INTERRUPT(qic_reschedule_interrupt, QIC_RESCHEDULE_CPI);
+BUILD_SMP_INTERRUPT(qic_enable_irq_interrupt, QIC_ENABLE_IRQ_CPI);
+BUILD_SMP_INTERRUPT(qic_call_function_interrupt, QIC_CALL_FUNCTION_CPI);
+
+/*  The CPIs are handled in the per cpu 8259s, so they must be
+ *  enabled to be received: FIX: enabling the CPIs in the early
+ *  boot sequence interferes with bug checking; enable them later
+ *  on in smp_init */
+#define VIC_SET_GATE(cpi, vector) \
+	set_intr_gate((cpi) + VIC_DEFAULT_CPI_BASE, (vector))
+#define QIC_SET_GATE(cpi, vector) \
+	set_intr_gate((cpi) + QIC_DEFAULT_CPI_BASE, (vector))
+
+void __init
+voyager_smp_intr_init(void)
+{
+	int i;
+
+	/* initialize the per cpu irq mask to all disabled */
+	for(i = 0; i < NR_CPUS; i++)
+		vic_irq_mask[i] = 0xFFFF;
+
+	VIC_SET_GATE(VIC_CPI_LEVEL0, vic_cpi_interrupt);
+
+	VIC_SET_GATE(VIC_SYS_INT, vic_sys_interrupt);
+	VIC_SET_GATE(VIC_CMN_INT, vic_cmn_interrupt);
+
+	QIC_SET_GATE(QIC_TIMER_CPI, qic_timer_interrupt);
+	QIC_SET_GATE(QIC_INVALIDATE_CPI, qic_invalidate_interrupt);
+	QIC_SET_GATE(QIC_RESCHEDULE_CPI, qic_reschedule_interrupt);
+	QIC_SET_GATE(QIC_ENABLE_IRQ_CPI, qic_enable_irq_interrupt);
+	QIC_SET_GATE(QIC_CALL_FUNCTION_CPI, qic_call_function_interrupt);
+	
+
+	/* now put the VIC descriptor into the first 48 IRQs 
+	 *
+	 * This is for later: first 16 correspond to PC IRQs; next 16
+	 * are Primary MC IRQs and final 16 are Secondary MC IRQs */
+	for(i = 0; i < 48; i++)
+		irq_desc[i].handler = &vic_irq_type;
+}
+
+/* send a CPI at level cpi to a set of cpus in cpuset (set 1 bit per
+ * processor to recieve CPI */
+static void
+send_CPI(__u32 cpuset, __u8 cpi)
+{
+	int i;
+	__u32 quad_cpuset = (cpuset & voyager_quad_processors);
+
+	if(cpi < VIC_START_FAKE_CPI) {
+		/* fake CPI are only used for booting, so send to the 
+		 * extended quads as well---Quads must be VIC booted */
+		outb((__u8)(cpuset), VIC_CPI_Registers[cpi]);
+		return;
+	}
+	if(quad_cpuset)
+		send_QIC_CPI(quad_cpuset, cpi);
+	cpuset &= ~quad_cpuset;
+	cpuset &= 0xff;		/* only first 8 CPUs vaild for VIC CPI */
+	if(cpuset == 0)
+		return;
+	for(i = 0; i < smp_num_cpus; i++) {
+		__u8 cpu = __cpu_logical_map[i];
+		if(cpuset & (1<<cpu))
+			set_bit(cpi, &vic_cpi_mailbox[cpu]);
+	}
+	if(cpuset)
+		outb((__u8)cpuset, VIC_CPI_Registers[VIC_CPI_LEVEL0]);
+}
+
+/* Acknowlege receipt of CPI in the QIC, clear in QIC hardware and
+ * set the cache line to shared by reading it.
+ *
+ * DON'T make this inline otherwise the cache line read will be
+ * optimised away
+ * */
+static int
+ack_QIC_CPI(__u8 cpi) {
+	__u8 cpu = hard_smp_processor_id();
+
+	outb(1<<cpi, QIC_INTERRUPT_CLEAR1);
+	return voyager_quad_cpi_addr[cpu]->qic_cpi[cpi].cpi;
+}
+
+/* Acknowledge receipt of CPI in the VIC (essentially an EOI) */
+static void
+ack_VIC_CPI(__u8 cpi)
+{
+#ifdef VOYAGER_DEBUG
+	unsigned long flags;
+	__u16 isr;
+	__u8 cpu = smp_processor_id();
+
+	__save_flags(flags);
+	__cli();
+	isr = vic_read_isr();
+	if((isr & (1<<(cpi &7))) == 0) {
+		printk("VOYAGER SMP: CPU%d lost CPI%d\n", cpu, cpi);
+	}
+#endif
+	/* send specific EOI; the two system interrupts have
+	 * bit 4 set for a separate vector but behave as the
+	 * corresponding 3 bit intr */
+	outb_p(0x60|(cpi & 7),0x20);
+
+#ifdef VOYAGER_DEBUG
+	if((vic_read_isr() & (1<<(cpi &7))) != 0) {
+		printk("VOYAGER SMP: CPU%d still asserting CPI%d\n", cpu, cpi);
+	}
+	__restore_flags(flags);
+#endif
+}
+
+/* cribbed with thanks from irq.c */
+#define __byte(x,y) 	(((unsigned char *)&(y))[x])
+#define cached_21(cpu)	(__byte(0,vic_irq_mask[cpu]))
+#define cached_A1(cpu)	(__byte(1,vic_irq_mask[cpu]))
+
+static unsigned int
+startup_vic_irq(unsigned int irq)
+{
+	enable_vic_irq(irq);
+
+	return 0;
+}
+
+/* The enable and disable routines.  This is where we run into
+ * conflicting architectural philosophy.  Fundamentally, the voyager
+ * architecture does not expect to have to disable interrupts globally
+ * (the IRQ controllers belong to each CPU).  The processor masquerade
+ * which is used to start the system shouldn't be used in a running OS
+ * since it will cause great confusion if two separate CPUs drive to
+ * the same IRQ controller (I know, I've tried it).
+ *
+ * The solution is a variant on the NCR lazy SPL design:
+ *
+ * 1) To disable an interrupt, do nothing (other than set the
+ *    IRQ_DISABLED flag).  This dares the interrupt actually to arrive.
+ *
+ * 2) If the interrupt dares to come in, raise the local mask against
+ *    it (this will result in all the CPU masks being raised
+ *    eventually).
+ *
+ * 3) To enable the interrupt, lower the mask on the local CPU and
+ *    broadcast an Interrupt enable CPI which causes all other CPUs to
+ *    adjust their masks accordingly.  */
+
+static void
+enable_vic_irq(unsigned int irq)
+{
+	int i;
+	/* linux doesn't to processor-irq affinity, so enable on
+	 * all CPUs we know about */
+	__u8 cpu = smp_processor_id();
+	__u16 mask = (1<<irq);
+	__u32 processorList = 0;
+	unsigned long flags;
+
+	VDEBUG(("VOYAGER: enable_vic_irq(%d) CPU%d affinity 0x%lx\n",
+		irq, cpu, cpu_irq_affinity[cpu]));
+	spin_lock_irqsave(&vic_irq_lock, flags);
+	for(i = 0; i < smp_num_cpus; i++) {
+		__u8 real_cpu = __cpu_logical_map[i];
+		if(!(voyager_extended_vic_processors & (1<<real_cpu)))
+			continue;
+		if(!(cpu_irq_affinity[real_cpu] & mask)) {
+			/* irq has no affinity for this CPU, ignore */
+			continue;
+		}
+		if(real_cpu == cpu) {
+			enable_local_vic_irq(irq);
+		}
+		else if(vic_irq_mask[real_cpu] & mask) {
+			vic_irq_enable_mask[real_cpu] |= mask;
+			processorList |= (1<<real_cpu);
+		}
+	}
+	spin_unlock_irqrestore(&vic_irq_lock, flags);
+	if(processorList)
+		send_CPI(processorList, VIC_ENABLE_IRQ_CPI);
+}
+
+static void
+disable_vic_irq(unsigned int irq)
+{
+	/* lazy disable, do nothing */
+}
+
+static void
+enable_local_vic_irq(unsigned int irq)
+{
+	__u8 cpu = smp_processor_id();
+	__u16 mask = ~(1 << irq);
+	__u16 old_mask = vic_irq_mask[cpu];
+
+	vic_irq_mask[cpu] &= mask;
+	if(vic_irq_mask[cpu] == old_mask)
+		return;
+
+	VDEBUG(("VOYAGER DEBUG: Enabling irq %d in hardware on CPU %d\n",
+		irq, cpu));
+
+	if (irq & 8) {
+		outb_p(cached_A1(cpu),0xA1);
+		(void)inb_p(0xA1);
+	}
+	else {
+		outb_p(cached_21(cpu),0x21);
+		(void)inb_p(0x21);
+	}
+}
+
+static void
+disable_local_vic_irq(unsigned int irq)
+{
+	__u8 cpu = smp_processor_id();
+	__u16 mask = (1 << irq);
+	__u16 old_mask = vic_irq_mask[cpu];
+
+	vic_irq_mask[cpu] |= mask;
+	if(old_mask == vic_irq_mask[cpu])
+		return;
+
+	VDEBUG(("VOYAGER DEBUG: Disabling irq %d in hardware on CPU %d\n",
+		irq, cpu));
+
+	if (irq & 8) {
+		outb_p(cached_A1(cpu),0xA1);
+		(void)inb_p(0xA1);
+	}
+	else {
+		outb_p(cached_21(cpu),0x21);
+		(void)inb_p(0x21);
+	}
+}
+
+/* The VIC is level triggered, so the ack can only be issued after the
+ * interrupt completes.  However, we do Voyager lazy interrupt
+ * handling here: It is an extremely expensive operation to mask an
+ * interrupt in the vic, so we merely set a flag (IRQ_DISABLED).  If
+ * this interrupt actually comes in, then we mask and ack here to push
+ * the interrupt off to another CPU */
+static void
+before_handle_vic_irq(unsigned int irq)
+{
+	irq_desc_t *desc = irq_desc + irq;
+	__u8 cpu = smp_processor_id();
+
+	spin_lock(&vic_irq_lock);
+	vic_intr_total++;
+	vic_intr_count[cpu]++;
+
+	if(!(cpu_irq_affinity[cpu] & (1<<irq))) {
+		/* The irq is not in our affinity mask, push it off
+		 * onto another CPU */
+		VDEBUG(("VOYAGER DEBUG: affinity triggered disable of irq %d on cpu %d\n",
+			irq, cpu));
+		disable_local_vic_irq(irq);
+		/* set IRQ_INPROGRESS to prevent the handler in irq.c from
+		 * actually calling the interrupt routine */
+		desc->status |= IRQ_REPLAY | IRQ_INPROGRESS;
+	} else if(desc->status & IRQ_DISABLED) {
+		/* Damn, the interrupt actually arrived, do the lazy
+		 * disable thing. The interrupt routine in irq.c will
+		 * not handle a IRQ_DISABLED interrupt, so nothing more
+		 * need be done here */
+		VDEBUG(("VOYAGER DEBUG: lazy disable of irq %d on CPU %d\n",
+			irq, cpu));
+		disable_local_vic_irq(irq);
+		desc->status |= IRQ_REPLAY;
+	} else {
+		desc->status &= ~IRQ_REPLAY;
+	}
+
+	spin_unlock(&vic_irq_lock);
+}
+
+/* Finish the VIC interrupt: basically mask */
+static void
+after_handle_vic_irq(unsigned int irq)
+{
+	irq_desc_t *desc = irq_desc + irq;
+
+	spin_lock(&vic_irq_lock);
+	{
+		unsigned int status = desc->status & ~IRQ_INPROGRESS;
+#ifdef VOYAGER_DEBUG
+		__u16 isr;
+#endif
+
+		desc->status = status;
+		if ((status & IRQ_DISABLED))
+			disable_local_vic_irq(irq);
+#ifdef VOYAGER_DEBUG
+		/* DEBUG: before we ack, check what's in progress */
+		isr = vic_read_isr();
+		if((isr & (1<<irq) && !(status & IRQ_REPLAY)) == 0) {
+			int i;
+			__u8 cpu = smp_processor_id();
+
+			printk("VOYAGER SMP: CPU%d lost interrupt %d\n",
+			       cpu, irq);
+			for(i = 0; i < smp_num_cpus; i++) {
+				__u8 real_cpu = __cpu_logical_map[i];
+
+				outb(VIC_CPU_MASQUERADE_ENABLE | real_cpu,
+				     VIC_PROCESSOR_ID);
+				isr = vic_read_isr();
+				if(isr & (1<<irq)) {
+					printk("VOYAGER SMP: CPU%d ack irq %d\n",
+					       real_cpu, irq);
+					ack_vic_irq(irq);
+				}
+				outb(cpu, VIC_PROCESSOR_ID);
+			}
+		}
+#endif /* VOYAGER_DEBUG */
+		/* as soon as we ack, the interrupt is eligible for
+		 * receipt by another CPU so everything must be in
+		 * order here  */
+		ack_vic_irq(irq);
+		if(status & IRQ_REPLAY) {
+			/* replay is set if we disable the interrupt
+			 * in the before_handle_vic_irq() routine, so
+			 * clear the in progress bit here to allow the
+			 * next CPU to handle this correctly */
+			desc->status &= ~(IRQ_REPLAY | IRQ_INPROGRESS);
+		}
+#ifdef VOYAGER_DEBUG
+		isr = vic_read_isr();
+		if((isr & (1<<irq)) != 0)
+			printk("VOYAGER SMP: after_handle_vic_irq() after ack irq=%d, isr=0x%x\n",
+			       irq, isr);
+#endif /* VOYAGER_DEBUG */
+	}
+	spin_unlock(&vic_irq_lock);
+
+	/* All code after this point is out of the main path - the IRQ
+	 * may be intercepted by another CPU if reasserted */
+}
+
+
+/* Linux processor - interrupt affinity manipulations.
+ *
+ * For each processor, we maintain a 32 bit irq affinity mask.
+ * Initially it is set to all 1's so every processor accepts every
+ * interrupt.  In this call, we change the processor's affinity mask:
+ *
+ * Change from enable to disable:
+ *
+ * If the interrupt ever comes in to the processor, we will disable it
+ * and ack it to push it off to another CPU, so just accept the mask here.
+ *
+ * Change from disable to enable:
+ *
+ * change the mask and then do an interrupt enable CPI to re-enable on
+ * the selected processors */
+
+void
+set_vic_irq_affinity(unsigned int irq, unsigned long mask) 
+{
+	/* Only extended processors handle interrupts */
+	unsigned long real_mask = mask & voyager_extended_vic_processors;
+	unsigned long irq_mask = (1<<irq);
+	int i;
+	
+	if(mask == 0)
+		/* can't have no cpu's to accept the interrupt -- extremely
+		 * bad things will happen */
+		return;
+
+	if(irq == 0)
+		/* can't change the affinity of the timer IRQ.  This
+		 * is due to the constraint in the voyager
+		 * architecture that the CPI also comes in on and IRQ
+		 * line and we have chosen IRQ0 for this.  If you
+		 * raise the mask on this interrupt, the processor
+		 * will no-longer be able to accept VIC CPIs */
+		return;
+
+	if(irq >= 32) 
+		/* You can only have 32 interrupts in a voyager system
+		 * (and 32 only if you have a secondary microchannel
+		 * bus) */
+		return;
+
+	for(i = 0; i < smp_num_cpus; i++) {
+		__u8 cpu = __cpu_logical_map[i];
+		unsigned long cpu_mask = (1<<cpu);
+		
+		if(cpu_mask & real_mask) {
+			/* enable the interrupt for this cpu */
+			cpu_irq_affinity[cpu] |= irq_mask;
+		} else {
+			/* disable the interrupt for this cpu */
+			cpu_irq_affinity[cpu] &= ~irq_mask;
+		}
+	}
+	/* this is magic, we now have the correct affinity maps, so
+	 * enable the interrupt.  This will send an enable CPI to
+	 * those cpu's who need to enable it in their local masks,
+	 * causing them to correct for the new affinity . If the
+	 * interrupt is currently globally disabled, it will simply be
+	 * disabled again as it comes in (voyager lazy disable).  If
+	 * the affinity map is tightened to disable the interrupt on a
+	 * cpu, it will be pushed off when it comes in */
+	enable_vic_irq(irq);
+}
+
+static void
+ack_vic_irq(unsigned int irq)
+{
+	if (irq & 8) {
+		outb(0x62,0x20);	/* Specific EOI to cascade */
+		outb(0x60|(irq & 7),0xA0);
+	} else {
+		outb(0x60 | (irq & 7),0x20);
+	}
+}
+
+/* enable the CPIs.  In the VIC, the CPIs are delivered by the 8259
+ * but are not vectored by it.  This means that the 8259 mask must be
+ * lowered to receive them */
+static __init void
+vic_enable_cpi(void)
+{
+	__u8 cpu = smp_processor_id();
+	
+	/* just take a copy of the current mask (nop for boot cpu) */
+	vic_irq_mask[cpu] = vic_irq_mask[boot_cpu_id];
+
+	enable_local_vic_irq(VIC_CPI_LEVEL0);
+	enable_local_vic_irq(VIC_CPI_LEVEL1);
+
+	if(is_cpu_quad()) {
+		outb(0xFF, QIC_MASK_REGISTER0);
+		outb(QIC_CPI_ENABLE, QIC_MASK_REGISTER1);
+		VDEBUG(("VOYAGER SMP: QIC ENABLE CPI: CPU%d: MASK 0x%x\n",
+			cpu, QIC_CPI_ENABLE));
+	}
+
+	VDEBUG(("VOYAGER SMP: ENABLE CPI: CPU%d: MASK 0x%x\n",
+		cpu, vic_irq_mask[cpu]));
+}
+
+void
+voyager_smp_dump()
+{
+	int i;
+	__u8 old_cpu = smp_processor_id();
+
+	/* dump the interrupt masks of each processor */
+	for(i = 0; i < smp_num_cpus; i++) {
+		__u16 imr, isr, irr;
+		unsigned long flags;
+		__u8 cpu = __cpu_logical_map[i];
+
+		__save_flags(flags);
+		__cli();
+		outb(VIC_CPU_MASQUERADE_ENABLE | cpu, VIC_PROCESSOR_ID);
+		imr = (inb(0xa1) << 8) | inb(0x21);
+		outb(0x0a, 0xa0);
+		irr = inb(0xa0) << 8;
+		outb(0x0a, 0x20);
+		irr |= inb(0x20);
+		outb(0x0b, 0xa0);
+		isr = inb(0xa0) << 8;
+		outb(0x0b, 0x20);
+		isr |= inb(0x20);
+		outb(old_cpu, VIC_PROCESSOR_ID);
+		__restore_flags(flags);
+		printk("\tCPU%d: mask=0x%x, IMR=0x%x, IRR=0x%x, ISR=0x%x\n",
+		       cpu, vic_irq_mask[cpu], imr, irr, isr);
+#if 0
+		/* These lines are put in to try to unstick an un ack'd irq */
+		if(isr != 0) {
+			int irq;
+			for(irq=0; irq<16; irq++) {
+				if(isr & (1<<irq)) {
+					printk("\tCPU%d: ack irq %d\n",
+					       cpu, irq);
+					__save_flags(flags);
+					__cli();
+					outb(VIC_CPU_MASQUERADE_ENABLE | cpu,
+					     VIC_PROCESSOR_ID);
+					ack_vic_irq(irq);
+					outb(old_cpu, VIC_PROCESSOR_ID);
+					__restore_flags(flags);
+				}
+			}
+		}
+#endif
+	}
+}
+
+void
+smp_voyager_power_off(void *dummy)
+{
+	if(smp_processor_id() == boot_cpu_id) 
+		voyager_power_off();
+	else
+		smp_stop_cpu_function(NULL);
+}
Index: linux/2.4/drivers/char/sysrq.c
diff -u linux/2.4/drivers/char/sysrq.c:1.1.1.8 linux/2.4/drivers/char/sysrq.c:1.1.1.8.2.1
--- linux/2.4/drivers/char/sysrq.c:1.1.1.8	Sat Mar 31 15:45:27 2001
+++ linux/2.4/drivers/char/sysrq.c	Sat Mar 31 16:41:02 2001
@@ -26,6 +26,10 @@
 
 #include <asm/ptrace.h>
 
+#ifdef CONFIG_VOYAGER
+#include <asm/voyager.h>
+#endif
+
 extern void wakeup_bdflush(int);
 extern void reset_vc(unsigned int);
 extern struct list_head super_blocks;
@@ -78,6 +82,12 @@
 			printk("Keyboard mode set to XLATE\n");
 		}
 		break;
+#ifdef CONFIG_VOYAGER
+	case 'c':
+		printk("VOYAGER DUMP\n");
+		voyager_dump();
+		break;
+#endif /* CONFIG_VOYAGER */
 #ifdef CONFIG_VT
 	case 'k':					    /* K -- SAK */
 		printk("SAK\n");
Index: linux/2.4/drivers/scsi/53c7,8xx.c
diff -u linux/2.4/drivers/scsi/53c7,8xx.c:1.1.1.6 linux/2.4/drivers/scsi/53c7,8xx.c:1.1.1.6.2.1
--- linux/2.4/drivers/scsi/53c7,8xx.c:1.1.1.6	Sat Mar 31 15:45:45 2001
+++ linux/2.4/drivers/scsi/53c7,8xx.c	Sat Mar 31 16:41:02 2001
@@ -236,6 +236,7 @@
 #include <linux/time.h>
 #include <linux/blk.h>
 #include <linux/init.h>
+#include <linux/mca.h>
 #include <linux/spinlock.h>
 
 #include "scsi.h"
@@ -268,6 +269,8 @@
 static int NCR53c8xx_dsa_len;
 static void NCR53c7x0_intr(int irq, void *dev_id, struct pt_regs * regs);
 static void do_NCR53c7x0_intr(int irq, void *dev_id, struct pt_regs * regs);
+static void do_q720_intr(int irq, void *dev_id, struct pt_regs * regs);
+
 static int ncr_halt (struct Scsi_Host *host);
 static void intr_phase_mismatch (struct Scsi_Host *host, struct NCR53c7x0_cmd 
     *cmd);
@@ -448,6 +451,8 @@
  * and chip numbers.  
  */
 
+#ifndef CONFIG_MCA
+
 static struct {
     unsigned short pci_device_id;
     int chip;
@@ -468,9 +473,6 @@
 
 #define NPCI_CHIP_IDS (sizeof (pci_chip_ids) / sizeof(pci_chip_ids[0]))
 
-#define ROUNDUP(adr,type)	\
-  ((void *) (((long) (adr) + sizeof(type) - 1) & ~(sizeof(type) - 1)))
-
 /* 
  * Forced detection and autoprobe code for various hardware.  Currently, 
  * entry points for these are not included in init/main.c because if the 
@@ -508,6 +510,20 @@
 #define OVERRIDE_LIMIT commandline_current
 #endif
 
+#endif /* CONFIG_MCA */
+
+#ifdef CONFIG_MCA
+struct q720_table {
+    int			base;
+    struct q720_table	*next;
+};
+
+static struct q720_table *q720_table = NULL;
+#endif /* CONFIG_MCA */
+
+#define ROUNDUP(adr,type)	\
+  ((void *) (((long) (adr) + sizeof(type) - 1) & ~(sizeof(type) - 1)))
+
 /*
  * Function: issue_to_cmd
  *
@@ -558,6 +574,7 @@
 
 static void 
 internal_setup(int board, int chip, char *str, int *ints) {
+#ifndef CONFIG_MCA
     unsigned char pci;		/* Specifies a PCI override, with bus, device,
 				   function */
 
@@ -595,6 +612,7 @@
     } else {
 	printk ("53c7,7x0.c:internal_setup() : too many overrides\n");
     }
+#endif
 }
 
 /*
@@ -898,6 +916,18 @@
 	expected_clock = hostdata->scsi_clock = 40000000;
 	expected_id = 7;
     	break;
+    case NCR_Q720:
+	/* this is wide, but not yet supported as such */
+   	hostdata->dstat_sir_intr = NCR53c8x0_dstat_sir_intr;
+    	hostdata->init_save_regs = NULL;
+    	hostdata->dsa_fixup = NCR53c8xx_dsa_fixup;
+    	hostdata->init_fixup = NCR53c8x0_init_fixup;
+    	hostdata->soft_reset = NCR53c8x0_soft_reset;
+	hostdata->run_tests = NCR53c8xx_run_tests;
+/* Is the SCSI clock ever anything else on these chips? */
+	expected_clock = hostdata->scsi_clock = 40000000;
+	expected_id = 7;
+    	break;
     default:
 	printk ("scsi%d : chip type of %d is not supported yet, detaching.\n",
 	    host->host_no, hostdata->chip);
@@ -1029,6 +1059,7 @@
      */
     if (hostdata->chip / 100 == 8)  {
 	expected_ccf = clock_to_ccf (expected_clock);
+	NCR53c7x0_write8(SCNTL3_REG_800, 0x33);
 	hostdata->saved_scntl3 = NCR53c7x0_read8(SCNTL3_REG_800);
 	ccf = hostdata->saved_scntl3 & SCNTL3_800_CCF_MASK;
 	if (expected_ccf != -1 && ccf != expected_ccf && !ccf) {
@@ -1109,11 +1140,13 @@
 	search->irq == host->irq && search != host); search=search->next);
 
     if (!search) {
-#ifdef __powerpc__
-	if (request_irq(host->irq, do_NCR53c7x0_intr, SA_SHIRQ, "53c7,8xx", NULL)) 
-#else
-	if (request_irq(host->irq, do_NCR53c7x0_intr, SA_INTERRUPT, "53c7,8xx", NULL))
+	int ret =
+#ifdef CONFIG_MCA
+	  (hostdata->chip == NCR_Q720) ?
+	    request_irq(host->irq, do_q720_intr, SA_INTERRUPT, "Q720", NULL) :
 #endif
+	    request_irq(host->irq, do_NCR53c7x0_intr, SA_INTERRUPT, "53c7,8xx", NULL);
+	if (ret)
 	  {
 	  
 	  
@@ -1138,9 +1171,13 @@
 	scsi_unregister (host);
     	return -1;
     } else {
-	if (host->io_port)  {
-	    host->n_io_port = 128;
-	    request_region (host->io_port, host->n_io_port, "ncr53c7,8xx");
+	if (host->io_port) {
+	    if(hostdata->chip == NCR_Q720) {
+		host->n_io_port = 0x80;
+	    } else {
+		host->n_io_port = 112;
+		request_region (host->io_port, host->n_io_port, "ncr53c7,8xx");
+	    }
 	}
     }
     
@@ -1187,7 +1224,7 @@
 
     switch (chip) {
     case 825:
-    case 820:
+    case NCR_Q720:
     case 815:
     case 810:
 	schedule_size = (tpnt->can_queue + 1) * 8 /* JUMP instruction size */;
@@ -1208,7 +1245,7 @@
     else 
     	printk(", dma %d\n", dma);
 
-    if ((chip / 100 == 8) && !pci_valid) 
+    if ((chip / 100 == 8) && chip != NCR_Q720) 
 	printk ("scsi-ncr53c7,8xx : for better reliability and performance, please use the\n" 
 		"        PCI override instead.\n"
 		"	 Syntax : ncr53c8{10,15,20,25}=pci,<bus>,<device>,<function>\n"
@@ -1293,12 +1330,16 @@
      */
 
     if (base) {
-	instance->base = (unsigned long) base;
 	/* Check for forced I/O mapping */
     	if (!(options & OPTION_IO_MAPPED)) {
 	    options |= OPTION_MEMORY_MAPPED;
 	    ok = 1;
 	}
+	/*
+	base = ioremap(base, 0x100);
+	*/
+	printk("ncr53c7,8xx: remapped ram base to 0x%x\n", base);
+	instance->base = (unsigned char *) (unsigned long) base;
     } else {
 	options &= ~OPTION_MEMORY_MAPPED;
     }
@@ -1363,7 +1404,7 @@
     return NCR53c7x0_init(instance);
 }
 
-
+#ifndef CONFIG_MCA
 /* 
  * Function : static int ncr_pci_init(Scsi_Host_Template *tpnt, int board, 
  *	int chip, int bus, int device_fn, long long options)
@@ -1511,7 +1552,7 @@
     return normal_init (tpnt, board, chip, (int) base, io_port, 
 	(int) irq, DMA_NONE, 1, bus, device_fn, options);
 }
-
+#endif /* CONFIG_MCA */
 
 /* 
  * Function : int NCR53c7xx_detect(Scsi_Host_Template *tpnt)
@@ -1529,13 +1570,131 @@
 int __init 
 NCR53c7xx_detect(Scsi_Host_Template *tpnt){
     int i;
+    int count = 0;			/* Number of boards detected */
+#ifdef CONFIG_MCA
+    int slot, pos[4];
+#else
     int current_override;
-    int count;			/* Number of boards detected */
     unsigned char pci_bus, pci_device_fn;
     static short pci_index=0;	/* Device index to PCI BIOS calls */
+#endif
 
     tpnt->proc_name = "ncr53c7xx";
 
+#ifdef CONFIG_MCA
+    if((slot = mca_find_adapter(0x01ba, 0)) != MCA_NOTFOUND) {
+	int iobase, irq;
+	unsigned int rambase;
+
+	pos[0] = mca_read_stored_pos(slot, 2);
+	pos[1] = mca_read_stored_pos(slot, 3);
+	pos[2] = mca_read_stored_pos(slot, 4);
+	pos[3] = mca_read_stored_pos(slot, 5);
+
+	iobase = (pos[2] & 0xfd) << 8;
+	rambase = ((pos[1] & 0xf0) << 9) + 0xC0000;
+	switch((pos[0] & 0xd0) >> 6) {
+	case 2:
+	    irq = 11;
+	    break;
+	case 3:
+	    irq = 14;
+	    break;
+	default:
+	    printk("D700: Illegal interrupt\n");
+	    irq = 0;
+	    break;
+	}
+	
+	normal_init(tpnt, BOARD_GENERIC, 70066, rambase + 0x200, 
+		    iobase + 0x200,
+		    irq, DMA_NONE, 0, 0, 0, 0);
+	count ++;
+    }
+    else if((slot = mca_find_adapter(0x0720, 0)) != MCA_NOTFOUND) {
+	int iobase, irq;
+	unsigned int rambase;
+	struct q720_table *new_table;
+
+	pos[0] = mca_read_stored_pos(slot, 2);
+	pos[1] = mca_read_stored_pos(slot, 3);
+	pos[2] = mca_read_stored_pos(slot, 4);
+	pos[3] = mca_read_stored_pos(slot, 5);
+	
+	iobase = (0xf8 & pos[0]) << 8;
+	irq = pos[3] &0x0f; 
+	rambase = ((0x7e & pos[2]) << 20);
+	rambase += (pos[2] & 0x80) ? 0xF8000000 : 0xB8000000;
+	mca_set_adapter_name(slot, "NCR Q720 SCSI Quad Host Adapter");
+	printk(KERN_INFO "NCR Q720 in slot %d\n", slot);
+	/* set up card register region */
+	request_region((u32)iobase, 64, "Q720");
+	
+	/* set up SIOP individual region */
+	request_region((u32)(iobase + 0x200), 0x80, "Q720");
+	/* reset the entire adapter */
+	outb(inb((u32)(iobase + 0xa)) | 0x10, (u32)(iobase + 0xa));
+	/* must wait 5us before touching board again */
+	udelay(5);
+	/* enable the adapter */
+	outb(inb((u32)(iobase + 2)) | 0x03, (u32)(iobase +2));
+	/* enable ram based mapping */
+	outb(inb((u32)(iobase +0xa)) | 0x01, (u32)(iobase +0xa));
+	/* enable ram - I/O mapping in lower 1k */
+	outb(inb((u32)(iobase +0x11)) | 0x20, (u32)(iobase + 0x11));
+	for(i = 0; i < 4; i++) {
+	    /* reset the SIOP */
+	    outb(iobase + 0x200 + 0x80*i + ISTAT_REG_800, ISTAT_10_SRST);
+	    udelay(5);
+	    outb(iobase + 0x200 + 0x80*i + ISTAT_REG_800, 0x00);
+	    /* clear the DMA FIFO */
+	    outb(inb(iobase + 0x200 + 0x80*i + CTEST3_REG_800) | CTEST3_800_CLF,
+		 iobase + 0x200 + CTEST3_REG_800);
+	    /* clear SCSI FIFO */
+	    outb(inb(iobase + 0x200 + 0x80*i + STEST3_REG_800) | STEST3_800_CSF,
+		 iobase + 0x200 + STEST3_REG_800);
+	}
+	printk(KERN_INFO "Q720: (vers %d) Adapter Specific regs, iobase=0x%x, rambase=0x%x: ", 
+	       (inb(iobase + 0x200 + CTEST3_REG_800) & 0xf0) >> 4,
+	       iobase, rambase);
+	/*
+	for(i=0; i<16; i++) 
+	    printk("0x%2x ", inb((u32)(iobase + i)));
+	*/
+	new_table = kmalloc(sizeof(struct q720_table), GFP_ATOMIC);
+	if(new_table != NULL) {
+	    new_table->base = iobase;
+	    new_table->next = q720_table;
+	    q720_table = new_table;
+	    for(i=0; i<4; i++) { /* 4 SIOPs per card */
+		__u8 id0 = inb((__u16)(iobase + 0x270 + 0x80*i));
+		/*
+		int j;
+		printk("\nQ720: SIOP%d: ", i);
+		for(j=0; j<4; j++) 
+		    printk("0x%2x ", inb((u32)(iobase + j +0x270 + 0x80*i)));
+		printk("\n");
+		*/
+		if(id0 & 0x20) {
+			printk(KERN_WARNING "Q720: SIOP%d: No differential support, skipping\n", i);
+			continue;
+		}
+		/* we use 8xx to signal a 720 chip since the 720 registers
+		 * behave like an 8xx and a lot of the register selection is
+		 * done by the chip/100 == 8 selector */
+		normal_init(tpnt, BOARD_GENERIC, NCR_Q720, 
+			    rambase + 0x200 + 0x80*i, 
+			    iobase + 0x200 + 0x80*i,
+			    irq, DMA_NONE, 0, 0, 0, 0);
+		count++;
+	    }
+	} else {
+	    printk("Q720: failed to malloc %d bytes for table\n", 
+		   sizeof(q720_table));
+	}
+    }
+
+#else
     for (current_override = count = 0; current_override < OVERRIDE_LIMIT; 
 	 ++current_override) {
 	 if (overrides[current_override].pci ? 
@@ -1569,6 +1728,7 @@
 		    pci_bus, pci_device_fn, /* no options */ 0))
 		    ++count;
     }
+#endif
     return count;
 }
 
@@ -1657,12 +1817,13 @@
     tmp = NCR53c7x0_read8(DMODE_REG_10);
     tmp &= (DMODE_800_ERL | DMODE_BL_MASK);
 
-    if (!(hostdata->options & OPTION_MEMORY_MAPPED)) {
+    if (!(hostdata->options & OPTION_MEMORY_MAPPED)
+	&& hostdata->chip != NCR_Q720) {
     	base = (u32) host->io_port;
     	memory_to_ncr = tmp|DMODE_800_DIOM;
     	ncr_to_memory = tmp|DMODE_800_SIOM;
     } else {
-    	base = virt_to_bus((void *)host->base);
+    	base = host->base;	/* currently bus physical -- may change */
 	memory_to_ncr = ncr_to_memory = tmp;
     }
 
@@ -4186,9 +4347,9 @@
 
     is_8xx_chip = ((unsigned) (hostdata->chip - 800)) < 100;
     if (is_8xx_chip) {
-    	sstat0_sist0 = NCR53c7x0_read8(SIST0_REG_800);
+    	sstat0_sist0 = NCR53c7x0_read8(SIST0_REG_800) & NCR53c7x0_read8(SIEN0_REG_800);
 	udelay(1);
-    	sist1 = NCR53c7x0_read8(SIST1_REG_800);
+    	sist1 = NCR53c7x0_read8(SIST1_REG_800) & NCR53c7x0_read8(SIEN1_REG_800);
     } else {
     	sstat0_sist0 = NCR53c7x0_read8(SSTAT0_REG);
     	sist1 = 0;
@@ -4360,6 +4521,22 @@
     spin_unlock_irqrestore(&io_request_lock, flags);
 }
 
+#ifdef CONFIG_MCA
+static void
+do_q720_intr(int irq, void *dev_id, struct pt_regs *regs) {
+    unsigned long flags;
+
+    if(q720_table == NULL || (inb(q720_table->base +0xd) & 0xf0) == 0xf0) {
+	/* SIOP0-3 hasn't interrupted */
+	return;
+    }
+    spin_lock_irqsave(&io_request_lock, flags);
+    NCR53c7x0_intr(irq, dev_id, regs);
+    spin_unlock_irqrestore(&io_request_lock, flags);
+  
+}
+#endif
+
 /*
  * Function : static void NCR53c7x0_intr (int irq, void *dev_id, struct pt_regs * regs)
  *
@@ -4530,8 +4707,9 @@
 		    interrupted = 1;
     	    	    hostdata->state = STATE_HALTED;
 
-		    if (NCR53c7x0_read8 ((hostdata->chip / 100) == 8 ?
-			SSTAT1_REG : SSTAT2_REG) & SSTAT2_FF_MASK) 
+		    if ((NCR53c7x0_read8 ((hostdata->chip / 100) == 8 ?
+					  SSTAT1_REG : SSTAT2_REG) 
+			 & SSTAT2_FF_MASK) && istat & ISTAT_SIP) 
 			printk ("scsi%d : SCSI FIFO not empty\n", 
 			    host->host_no);
 
@@ -4549,11 +4727,19 @@
 			cmd = (struct NCR53c7x0_cmd *) hostdata->curr;
 		    } else {
 			dsa = bus_to_virt(NCR53c7x0_read32(DSA_REG));
+			if(hostdata->options & OPTION_DEBUG_INTR) {
+			    printk("scsi%d : dsa = 0x%x\n", host->host_no, dsa);
+			}
 			for (cmd = (struct NCR53c7x0_cmd *) 
 			    hostdata->running_list; cmd &&
     	    	    	    (dsa + (hostdata->dsa_start / sizeof(u32))) != 
     	    	    	    	cmd->dsa;
-			    cmd = (struct NCR53c7x0_cmd *)(cmd->next));
+			     cmd = (struct NCR53c7x0_cmd *)(cmd->next)) {
+			    if(hostdata->options & OPTION_DEBUG_INTR) {
+			       printk("scsi%d : cmd (0x%x) : dsa 0x%x, pid %lu, id %d, lun %d\n", host->host_no, cmd, cmd->dsa, cmd->cmd->pid, (int) cmd->cmd->target, (int) cmd->cmd->lun);
+			       print_command(cmd->cmd->cmnd);
+			    }
+			} 
 		    }
 		    if (hostdata->options & OPTION_DEBUG_INTR) {
 			if (cmd) {
@@ -4562,7 +4748,8 @@
 				(int) cmd->cmd->lun);
 			    print_command (cmd->cmd->cmnd);
 			} else {
-			    printk("scsi%d : no active command\n", host->host_no);
+			    printk("scsi%d : no active command\n", 
+				   host->host_no);
 			}
 		    }
 		    if (istat & ISTAT_SIP) {
@@ -5011,7 +5198,7 @@
 	printk("scsi%d : %s : unexpected phase %s.\n",
 	     host->host_no, where ? where : "unknown location", 
 	     sbcl_to_phase(sbcl));
-	print_lots (host);
+	/*print_lots (host);*/
     /* Fall through to ACTION_ABORT */
     case ACTION_ABORT:
 	abort_connected (host);
@@ -5078,6 +5265,10 @@
      */
 
     if ((hostdata->chip / 100) == 8) {
+#ifdef CONFIG_MCA
+	printk("scsi%d: fault interrupt on MCA\n", host->host_no);
+	return;
+#else
 	save_flags (flags);
 	cli();
 	tmp = pcibios_read_config_word (hostdata->pci_bus, 
@@ -5099,6 +5290,7 @@
 		host->host_no, tmp);
 	    retry = NEVER;
 	}
+#endif /* CONFIG_MCA */
     }
 
 #ifndef notyet
@@ -5659,8 +5851,8 @@
     save_flags(flags);
     cli();
     ncr_halt (host);
-    print_lots (host);
-    dump_events (host, 30);
+    /*print_lots (host);*/
+    /*dump_events (host, 30);*/
     ncr_scsi_reset (host);
     for (tmp = nuke_list = return_outstanding_commands (host, 1 /* free */,
 	0 /* issue */ ); tmp; tmp = (Scsi_Cmnd *) tmp->SCp.buffer)
Index: linux/2.4/drivers/scsi/53c7,8xx.h
diff -u linux/2.4/drivers/scsi/53c7,8xx.h:1.1.1.4 linux/2.4/drivers/scsi/53c7,8xx.h:1.1.1.4.2.1
--- linux/2.4/drivers/scsi/53c7,8xx.h:1.1.1.4	Sat Mar 31 15:45:45 2001
+++ linux/2.4/drivers/scsi/53c7,8xx.h	Sat Mar 31 16:41:03 2001
@@ -1526,5 +1526,10 @@
 /* Paranoid people could use panic() here. */
 #define FATAL(host) shutdown((host));
 
+/* Extra defines for the NCR Q720 card */
+
+#define NCR_Q720	827	/* default chip id (must be > 800) */
+#define NCR_Q720_DEFAULT_SCNTL3	0x33
+
 #endif /* NCR53c7x0_C */
 #endif /* NCR53c7x0_H */
Index: linux/2.4/drivers/scsi/Config.in
diff -u linux/2.4/drivers/scsi/Config.in:1.1.1.6 linux/2.4/drivers/scsi/Config.in:1.1.1.6.2.2
--- linux/2.4/drivers/scsi/Config.in:1.1.1.6	Sat Mar 31 15:45:45 2001
+++ linux/2.4/drivers/scsi/Config.in	Sat Apr 14 13:25:05 2001
@@ -114,7 +114,10 @@
    fi
 fi
 dep_tristate 'NCR53c406a SCSI support' CONFIG_SCSI_NCR53C406A $CONFIG_SCSI
-dep_tristate 'NCR53c7,8xx SCSI support'  CONFIG_SCSI_NCR53C7xx $CONFIG_SCSI $CONFIG_PCI
+if [ "$CONFIG_MCA" = "y" ]; then
+	dep_tristate 'NCR Dual 700 MCA SCSI support' CONFIG_SCSI_NCR_D700 $CONFIG_SCSI
+fi
+dep_tristate 'NCR53c7,8xx SCSI support'  CONFIG_SCSI_NCR53C7xx $CONFIG_SCSI
 if [ "$CONFIG_SCSI_NCR53C7xx" != "n" ]; then
    bool '  always negotiate synchronous transfers' CONFIG_SCSI_NCR53C7xx_sync
    bool '  allow FAST-SCSI [10MHz]' CONFIG_SCSI_NCR53C7xx_FAST
Index: linux/2.4/drivers/scsi/Makefile
diff -u linux/2.4/drivers/scsi/Makefile:1.1.1.6 linux/2.4/drivers/scsi/Makefile:1.1.1.6.2.1
--- linux/2.4/drivers/scsi/Makefile:1.1.1.6	Sat Mar 31 15:45:40 2001
+++ linux/2.4/drivers/scsi/Makefile	Sat Apr 14 13:25:06 2001
@@ -71,6 +71,7 @@
 obj-$(CONFIG_SCSI_IN2000)	+= in2000.o
 obj-$(CONFIG_SCSI_GENERIC_NCR5380) += g_NCR5380.o
 obj-$(CONFIG_SCSI_NCR53C406A)	+= NCR53c406a.o
+obj-$(CONFIG_SCSI_NCR_D700)	+= NCR_D700.o
 obj-$(CONFIG_SCSI_SYM53C416)	+= sym53c416.o
 obj-$(CONFIG_SCSI_QLOGIC_FAS)	+= qlogicfas.o
 obj-$(CONFIG_SCSI_QLOGIC_ISP)	+= qlogicisp.o 
@@ -184,3 +185,10 @@
 sim710_u.h: sim710_d.h
 
 sim710.o : sim710_d.h
+
+NCR_D700_d.h: NCR_D700.scr script_asm.pl
+	$(PERL) -s script_asm.pl -ncr7x0_family < NCR_D700.scr
+	mv script.h NCR_D700_d.h
+	mv scriptu.h NCR_D700_u.h
+
+NCR_D700.o: NCR_D700_d.h
Index: linux/2.4/drivers/scsi/NCR_D700.c
diff -u /dev/null linux/2.4/drivers/scsi/NCR_D700.c:1.1.2.17
--- /dev/null	Sun Apr 29 10:16:33 2001
+++ linux/2.4/drivers/scsi/NCR_D700.c	Sun Apr 29 10:13:38 2001
@@ -0,0 +1,1448 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
+
+/* NCR Dual 700 MCA SCSI Driver
+ *
+ * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
+ */
+
+/* Notes:
+ *
+ * At the moment, this driver is extremely simple: it does no
+ * negotiation (so only uses async mode), doesn't allow disconnects
+ * and doesn't use tag queueing.
+ *
+ * The script for the 700 is modified for every current command.
+ * Scatter-Gather blocks are processed by constructing a special
+ * script fragment to move the block on the bus and jump to the next
+ * block or return to the script if this is the last block
+ *
+ * The script engine executes until the command is completed or an
+ * error occurs.  Only one command may be active in the processor at
+ * once, so all other commands which come in through queuecommand are
+ * returned to the mid-layer.
+ *
+ * TODO List:
+ *
+ * 1. Implement tag queueing.  Most complex of all since we now need a
+ *    much more multi-threaded approach to the script
+ *
+ * 2. Extract the SCSI ID from the voyager CMOS table (necessary to
+ *    support multi-host environments.
+ *
+ * 3. Implement statistics collecting for the proc fs.
+ *
+ * 4. modularise the driver so that the NCR_D700 makes use of a generic
+ *    53c700 driver (a bit like the network drivers use the 8390).
+ * */
+
+/* CHANGELOG 
+ *
+ * Version 1.0:
+ *
+ *   Initial release.  Fully functional except for procfs and tag
+ * command queueing.  Has only been tested on cards with 53c700-66
+ * chips and only single ended. Features are
+ *
+ * 1. Synchronous data transfers to offset 8 (limit of 700-66) and
+ *    100ns (10MHz) limit of SCSI-2
+ *
+ * 2. Disconnection and reselection
+ *
+ * Testing:
+ * 
+ *  I've only really tested this with the 700-66 chip, but have done
+ * soak tests in multi-device environments to verify that
+ * disconnections and reselections are being processed correctly.
+ * */
+
+#define NCR_D700_VERSION "1.0"
+
+#include <linux/config.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#include <linux/proc_fs.h>
+#include <linux/init.h>
+#include <linux/mca.h>
+#include <asm/dma.h>
+#include <asm/system.h>
+#include <asm/spinlock.h>
+#include <asm/io.h>
+#include <asm/pgtable.h>
+#include <asm/byteorder.h>
+#include <linux/blk.h>
+
+#ifdef MODULE
+#include <linux/module.h>
+#endif
+
+
+#include "scsi.h"
+#include "hosts.h"
+
+#include "NCR_D700.h"
+
+#ifndef CONFIG_MCA
+#error "NCR_D700 driver only compiles for MCA"
+#endif
+
+#ifdef NCR_D700_DEBUG
+#define STATIC
+#else
+#define STATIC static
+#endif
+
+#ifdef MODULE
+
+char *NCR_D700;			/* command line from insmod */
+
+MODULE_AUTHOR("James Bottomley");
+MODULE_DESCRIPTION("NCR Dual700 SCSI Driver");
+MODULE_PARM(NCR_D700, "s");
+
+#endif
+
+/* This is the script */
+#include "NCR_D700_d.h"
+
+
+static char *D700_phase[] = {
+	"",
+	"AFTER SELECTION",
+	"BEFORE CMD",
+	"AFTER CMD",
+	"AFTER STATUS",
+	"AFTER DATA IN",
+	"AFTER DATA OUT",
+	"DURING DATA IN",
+};
+
+static char *D700_condition[] = {
+	"",
+	"NOT MSG_OUT",
+	"UNEXPECTED PHASE",
+	"NOT MSG_IN",
+	"UNEXPECTED MSG",
+	"MSG_IN",
+	"SDTR_MSG RECEIVED",
+	"REJECT_MSG RECEIVED",
+	"DISCONNECT_MSG RECEIVED",
+	"MSG_OUT",
+	"DATA_IN",
+	
+};
+
+static char *D700_fatal_messages[] = {
+	"unexpected message after reselection",
+	"unexpected phase after sending IDENTIFY",
+	"still MSG_OUT after message injection",
+	"selected as target",
+	"not MSG_IN after selection",
+};
+
+static char *D700_SBCL_bits[] = {
+	"IO ",
+	"CD ",
+	"MSG ",
+	"ATN ",
+	"SEL ",
+	"BSY ",
+	"ACK ",
+	"REQ ",
+};
+
+static char *D700_SBCL_to_phase[] = {
+	"DATA_OUT",
+	"DATA_IN",
+	"CMD_OUT",
+	"STATE",
+	"ILLEGAL PHASE",
+	"ILLEGAL PHASE",
+	"MSG OUT",
+	"MSG IN",
+};
+
+static __u8 D700_SDTR_msg[] = {
+	0x01,			/* Extended message */
+	0x03,			/* Extended message Length */
+	0x01,			/* SDTR Extended message */
+	NCR_D700_MIN_PERIOD,
+	NCR_D700_MAX_OFFSET
+};
+
+static inline __u8
+D700_identify(int can_disconnect, __u8 lun)
+{
+	return IDENTIFY_BASE |
+		((can_disconnect) ? 0x40 : 0) |
+		(lun & NCR_D700_LUN_MASK);
+}
+
+/*
+ * Function : static int datapath_residual (Scsi_Host *host)
+ *
+ * Purpose : return residual data count of what's in the chip.
+ *
+ * Inputs : host - SCSI host
+ */
+
+static inline int
+D700_data_residual (struct Scsi_Host *host) {
+	int count, synchronous;
+	unsigned int ddir;
+	
+	count = ((inb(host->base + DFIFO_REG) & 0x7f) -
+		 (inl(host->base + DBC_REG) & 0x7f)) & 0x7f;
+	
+	synchronous = inb(host->base + SXFER_REG) & 0x0f;
+	
+	/* get the data direction */
+	ddir = inb(host->base + CTEST0_REG) & 0x01;
+
+	if (ddir) {
+		/* Receive */
+		if (synchronous) 
+			count += (inb(host->base + SSTAT2_REG) & 0xf0) >> 4;
+		else
+			if (inb(host->base + SSTAT1_REG) & SIDL_REG_FULL)
+				++count;
+	} else {
+		/* Send */
+		__u8 sstat = inb(host->base + SSTAT1_REG);
+		if (sstat & SODL_REG_FULL)
+			++count;
+		if (synchronous && (sstat & SODR_REG_FULL))
+			++count;
+	}
+	return count;
+}
+
+static inline void
+enable_selection_interrupt(struct Scsi_Host *host)
+{
+	outb(PHASE_MM_INT | SEL_TIMEOUT_INT | GROSS_ERR_INT | UX_DISC_INT
+	     | RST_INT | PAR_ERR_INT | SELECT_INT, host->base + SIEN_REG);
+}
+
+static inline void
+disable_selection_interrupt(struct Scsi_Host *host)
+{
+	outb(PHASE_MM_INT | SEL_TIMEOUT_INT | GROSS_ERR_INT | UX_DISC_INT
+	     | RST_INT | PAR_ERR_INT, host->base + SIEN_REG);
+}
+
+static inline char *
+sbcl_to_string(__u8 sbcl)
+{
+	int i;
+	static char ret[256];
+
+	ret[0]='\0';
+	for(i=0; i<8; i++) {
+		if((1<<i) & sbcl) 
+			strcat(ret, D700_SBCL_bits[i]);
+	}
+	strcat(ret, D700_SBCL_to_phase[sbcl & 0x07]);
+	return ret;
+}
+
+static inline __u8
+bitmap_to_number(__u8 bitmap)
+{
+	__u8 i;
+
+	for(i=0; i<8 && !(bitmap &(1<<i)); i++)
+		;
+	return i;
+}
+
+/* enter this routine with stat_lock held */
+STATIC struct D700_command_slot *
+find_empty_slot(struct D700_Host_Parameters *hostdata)
+{
+	int i;
+
+	for(i = 0; i < D700_COMMAND_SLOTS_PER_HOST; i++) {
+		if(hostdata->slots[i].state == D700_SLOT_FREE)
+			break;
+	}
+	if(i == D700_COMMAND_SLOTS_PER_HOST) 
+		return NULL;
+
+
+	/* NOTE: set the state to busy here, not queued, since this
+	 * indicates the slot is in use and cannot be run by the IRQ
+	 * finish routine.  If we cannot queue the command when it
+	 * is properly build, we then change to D700_SLOT_QUEUED */
+	hostdata->slots[i].state = D700_SLOT_BUSY;
+	hostdata->command_slot_count++;
+	
+	return &hostdata->slots[i];
+}
+
+STATIC void 
+free_slot(struct D700_command_slot *slot,
+	  struct D700_Host_Parameters *hostdata)
+{
+	if((slot->state & D700_SLOT_MASK) != D700_SLOT_MAGIC) {
+		printk(" SLOT %p is not MAGIC!!!\n", slot);
+	}
+	slot->resume_offset = 0;
+	slot->cmnd = NULL;
+	slot->state = D700_SLOT_FREE;
+	hostdata->command_slot_count--;
+}
+
+STATIC void
+save_for_reselection(struct D700_Host_Parameters *hostdata,
+		     Scsi_Cmnd *SCp, __u32 dsp)
+{
+	struct D700_command_slot *slot =
+		(struct D700_command_slot *)SCp->host_scribble;
+
+	slot->resume_offset = dsp;
+
+	hostdata->state = D700_HOST_FREE;
+	hostdata->cmd = NULL;
+	slot->temp = inl(SCp->host->base + TEMP_REG);
+}
+
+STATIC struct D700_command_slot *
+find_saved_command(struct D700_Host_Parameters *hostdata, __u8 pun, __u8 lun)
+{
+	int i;
+	struct D700_command_slot *slot = NULL;
+
+	for(i = 0; i < D700_COMMAND_SLOTS_PER_HOST; i++) {
+		if(hostdata->slots[i].state == D700_SLOT_FREE)
+			continue;
+		if(hostdata->slots[i].cmnd->target == pun &&
+		   hostdata->slots[i].cmnd->lun == lun) {
+			slot = &hostdata->slots[i];
+			break;
+		}
+	}
+	return slot;
+}
+
+/* This translates the SDTR message offset and period to a value
+ * which can be loaded into the SXFER_REG.
+ *
+ * NOTE: According to SCSI-2, the true transfer period is actually 
+ *       four times this period value (in ns) */
+STATIC inline __u8
+D700_offset_period_to_sxfer(__u8 offset, __u8 period)
+{
+	int XFERP;
+
+	XFERP = (period*4 * NCR_D700_CLOCK_MHZ)/1000 - 4;
+	if(offset > NCR_D700_MAX_OFFSET) {
+		printk(KERN_WARNING "D700: Offset %d exceeds maximum, setting to %d\n",
+		       offset, NCR_D700_MAX_OFFSET);
+		offset = NCR_D700_MAX_OFFSET;
+	}
+	if(XFERP < NCR_D700_MIN_XFERP) {
+		printk(KERN_WARNING "D700: XFERP %d is less than minium, setting to %d\n",
+		       XFERP,  NCR_D700_MIN_XFERP);
+		XFERP =  NCR_D700_MIN_XFERP;
+	}
+	return (offset & 0x0f) | (XFERP & 0x07)<<4;
+}
+	
+
+STATIC inline void
+D700_scsi_done(struct D700_Host_Parameters *hostdata,
+	       Scsi_Cmnd *SCp, int result)
+{
+	hostdata->state = D700_HOST_FREE;
+	hostdata->cmd = NULL;
+
+	if(SCp != NULL) {
+		struct D700_command_slot *slot = 
+			(struct D700_command_slot *)SCp->host_scribble;
+
+		if(SCp->cmnd[0] == REQUEST_SENSE && SCp->cmnd[6] == D700_INTERNAL_SENSE_MAGIC) {
+#ifdef NCR_D700_DEBUG
+			printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is",
+			       SCp, SCp->cmnd[7], result);
+			print_sense("D700", SCp);
+#endif
+			if(result == 0)
+				result = SCp->cmnd[7];
+		}
+			
+		free_slot(slot, hostdata);
+
+		SCp->host_scribble = NULL;
+		SCp->result = result;
+		SCp->scsi_done(SCp);
+		if(D700_get_depth(SCp->device) != 1) 
+			printk(KERN_ERR "Invalid depth in D700_scsi_done(): %d\n",
+			       D700_get_depth(SCp->device));
+		D700_set_depth(SCp->device, D700_get_depth(SCp->device) - 1);
+	} else {
+		printk(KERN_ERR "  SCSI DONE HAS NULL SCp\n");
+	}
+}
+
+
+STATIC void
+D700_internal_bus_reset(struct Scsi_Host *host)
+{
+	/* Bus reset */
+	outb(ASSERT_RST, host->base + SCNTL1_REG);
+	udelay(50);
+	outb(0, host->base + SCNTL1_REG);
+
+}
+
+STATIC void
+D700_chip_setup(struct Scsi_Host *host)
+{
+	outb(1 << host->this_id, host->base + SCID_REG);
+	outb(0, host->base + SBCL_REG);
+	outb(0, host->base + SXFER_REG);
+
+	outb(PHASE_MM_INT | SEL_TIMEOUT_INT | GROSS_ERR_INT | UX_DISC_INT
+	     | RST_INT | PAR_ERR_INT | SELECT_INT, host->base + SIEN_REG);
+
+	outb(ABORT_INT | INT_INST_INT | ILGL_INST_INT, host->base + DIEN_REG);
+	outb(BURST_LENGTH_8, host->base + DMODE_REG);
+	outb(FULL_ARBITRATION | PARITY | AUTO_ATN, host->base + SCNTL0_REG);
+	outb(LAST_DIS_ENBL | ENABLE_ACTIVE_NEGATION|GENERATE_RECEIVE_PARITY,
+	     host->base + CTEST8_REG);
+	outb(ENABLE_SELECT, host->base + SCNTL1_REG);
+	/* Set the synchronous SCSI divider to 1 so we drive the
+	 * synchronous command clock at 50MHz - the default Dual board
+	 * clock speed */
+	outb(1, host->base + SBCL_REG);
+	/* set the clock bits to 0 which is a divider of 2 so the
+	 * async frequency is exactly 25Mhz */ 
+	outb(0x00, host->base + DCNTL_REG);
+}
+
+STATIC void
+D700_chip_reset(struct Scsi_Host *host)
+{
+	/* Chip reset */
+	outb(SOFTWARE_RESET, host->base + DCNTL_REG);
+	udelay(100);
+
+	outb(0, host->base + DCNTL_REG);
+
+	mdelay(1000);
+
+	D700_chip_setup(host);
+}
+
+
+STATIC __u32
+process_script_interrupt(__u32 dsps, __u32 dsp, Scsi_Cmnd *SCp,
+			 struct Scsi_Host *host,
+			 struct D700_Host_Parameters *hostdata)
+{
+	__u32 resume_offset = 0;
+	__u8 pun = 0xff, lun=0xff;
+
+	if(SCp != NULL) {
+		pun = SCp->target;
+		lun = SCp->lun;
+	}
+
+	if(dsps == A_GOOD_STATUS_AFTER_STATUS) {
+		DEBUG(("  COMMAND COMPLETE, status=%02x\n",
+		       hostdata->status));
+		/* check for contingent allegiance contitions */
+		if(status_byte(hostdata->status) == CHECK_CONDITION ||
+		   status_byte(hostdata->status) == COMMAND_TERMINATED) {
+			struct D700_command_slot *slot =
+				(struct D700_command_slot *)SCp->host_scribble;
+
+			DEBUG(("  cmd %p has status %d, requesting sense\n",
+			       SCp, hostdata->status));
+			/* we can destroy the command here because the
+			 * contingent allegiance condition will cause a 
+			 * retry which will re-copy the command from the
+			 * saved data_cmnd */
+			SCp->cmnd[0] = REQUEST_SENSE;
+			SCp->cmnd[1] = (SCp->lun & 0x7) << 5;
+			SCp->cmnd[2] = 0;
+			SCp->cmnd[3] = 0;
+			SCp->cmnd[4] = sizeof(SCp->sense_buffer);
+			SCp->cmnd[5] = 0;
+			SCp->cmd_len = 6;
+			/* Here's a quiet hack: the REQUEST_SENSE command is
+			 * six bytes, so store a flag indicating that this
+			 * was an internal sense request and the original
+			 * status at the end of the command */
+			SCp->cmnd[6] = D700_INTERNAL_SENSE_MAGIC;
+			SCp->cmnd[7] = hostdata->status;
+			slot->SG[0].ins = SCRIPT_MOVE_DATA_IN | sizeof(SCp->sense_buffer);
+			slot->SG[0].pAddr = virt_to_bus(SCp->sense_buffer);
+			slot->SG[1].ins = SCRIPT_RETURN;
+			slot->SG[1].pAddr = 0;
+			slot->resume_offset = hostdata->pScript;
+			
+			/* queue the command for reissue */
+			slot->state = D700_SLOT_QUEUED;
+			hostdata->state = D700_HOST_FREE;
+			hostdata->cmd = NULL;
+		} else {
+			D700_scsi_done(hostdata, SCp, hostdata->status);
+		}
+	} else if(dsps == A_SDTR_MSG_BEFORE_CMD) {
+		__u8 period = hostdata->msgin[3];
+		__u8 offset = hostdata->msgin[4];
+
+		if(SCp == NULL || D700_is_flag_clear(SCp->device, D700_DEV_BEGIN_SYNC_NEGOTIATION)) {
+			/* SDTR message out of the blue, reject it */
+			printk(KERN_WARNING "scsi%d Unexpecet SDTR msg\n",
+			       host->host_no);
+			hostdata->msgout[0] = A_REJECT_MSG;
+			script_patch_16(hostdata->script, MessageCount, 1);
+			/* SendMsgOut returns, so set up the return
+			 * address */
+			outl(hostdata->pScript + Ent_SendCommand,
+			     host->base + TEMP_REG);
+			resume_offset = hostdata->pScript + Ent_SendMsgOut;
+		} else {
+			printk(KERN_INFO "scsi%d: (%d:%d) Synchronous at offset %d, period %dns\n",
+			       host->host_no, pun, lun,
+			       offset, period*4);
+			if(offset != 0 && period != 0)
+				D700_set_SXFER(SCp->device,
+					       D700_offset_period_to_sxfer(offset, period));
+			else 
+				D700_set_SXFER(SCp->device, 0);
+			
+			D700_set_flag(SCp->device, D700_DEV_NEGOTIATED_SYNC);
+			D700_clear_flag(SCp->device, D700_DEV_BEGIN_SYNC_NEGOTIATION);
+			
+			outb(D700_get_SXFER(SCp->device),
+			     host->base + SXFER_REG);
+			resume_offset = dsp;
+		}
+	} else if(dsps == A_REJECT_MSG_BEFORE_CMD) {
+		/* currently the only message we send is SDTR, so
+		 * mark the device as having negotiated async */
+		if(SCp != NULL && D700_is_flag_set(SCp->device, D700_DEV_BEGIN_SYNC_NEGOTIATION)) {
+			D700_set_SXFER(SCp->device, 0);
+			D700_set_flag(SCp->device, D700_DEV_NEGOTIATED_SYNC);
+			D700_clear_flag(SCp->device, D700_DEV_BEGIN_SYNC_NEGOTIATION);
+		}
+		resume_offset = dsp;
+	} else if((dsps & 0xfffff0f0) == A_UNEXPECTED_PHASE) {
+		__u8 i = (dsps & 0xf00) >> 8;
+
+		printk(KERN_ERR "scsi%d: (%d:%d), UNEXPECTED PHASE %s (%s)\n",
+		       host->host_no, pun, lun,
+		       D700_phase[i],
+		       sbcl_to_string(inb(host->base + SBCL_REG)));
+		printk("         len = %d, cmd =", SCp->cmd_len);
+		print_command(SCp->cmnd);
+
+		D700_internal_bus_reset(host);
+	} else if((dsps & 0xfffff000) == A_FATAL) {
+		int i = (dsps & 0xfff);
+
+		printk(KERN_ERR "scsi%d: (%d:%d) FATAL ERROR: %s\n",
+		       host->host_no, pun, lun, D700_fatal_messages[i]);
+		D700_internal_bus_reset(host);
+	} else if((dsps & 0xfffff0f0) == A_DISCONNECT) {
+#ifdef NCR_D700_DEBUG
+		__u8 i = (dsps & 0xf00) >> 8;
+
+		printk("scsi%d: (%d:%d), DISCONNECTED (%d) %s\n",
+		       host->host_no, pun, lun,
+		       i, D700_phase[i]);
+#endif
+		save_for_reselection(hostdata, SCp, dsp);
+
+	} else if(dsps == A_MSG_IN_AFTER_DATA_OUT 
+		  || dsps == A_MSG_IN_AFTER_DATA_IN) {
+		printk(KERN_ERR "scsi%d: (%d:%d) MSG AFTER DATA %02x!!\n",
+		       host->host_no, pun, lun, hostdata->msgin[0]);
+		D700_internal_bus_reset(host);
+	} else if(dsps == A_MSG_IN_AFTER_CMD) {
+		if(hostdata->msgin[0] != A_EXTENDED_MSG)
+			printk(KERN_ERR "scsi%d: (%d:%d) MSG after COMMAND %02x!!\n",
+			       host->host_no, pun, lun, hostdata->msgin[0]);
+		else
+			printk(KERN_ERR "scsi%d: (%d:%d) MSG after COMMAND %02x %02x %02x!!\n",
+			       host->host_no, pun, lun, hostdata->msgin[0],
+			       hostdata->msgin[1], hostdata->msgin[2]);
+		D700_internal_bus_reset(host);
+	} else if(dsps == A_RESELECTION_IDENTIFIED) {
+		__u8 lun = hostdata->msgin[0] & 0x1f;
+		struct D700_command_slot *slot;
+		__u8 reselection_id = hostdata->reselection_id;
+
+		hostdata->reselection_id = 0xff;
+		DEBUG(("scsi%d: (%d:%d) RESELECTED!\n",
+		       host->host_no, reselection_id, lun));
+		/* clear the reselection indicator */
+		slot = find_saved_command(hostdata, reselection_id, lun);
+		if(slot == NULL) {
+			printk(KERN_ERR "scsi%d: (%d:%d) RESELECTED but no saved command (MSG = %02x)!!\n",
+			       host->host_no, reselection_id, lun,
+			       hostdata->msgin[0]);
+		} else {
+			if(hostdata->state != D700_HOST_BUSY)
+				printk(KERN_ERR "scsi%d: FATAL, host not busy during valid reselection!\n",
+				       host->host_no);
+			resume_offset = slot->resume_offset;
+			hostdata->cmd = slot->cmnd;
+
+			/* re-patch for this command */
+			script_patch_32_abs(hostdata->script, CommandAddress, 
+					    virt_to_bus(slot->cmnd->cmnd));
+			script_patch_16(hostdata->script,
+					CommandCount, slot->cmnd->cmd_len);
+			script_patch_32_abs(hostdata->script, SGScriptStartAddress,
+					    virt_to_bus(&slot->SG[0].ins));
+
+			/* Note: setting SXFER only works if we're
+			 * still in the MESSAGE phase, so it is vital
+			 * that ACK is still asserted when we process
+			 * the reselection message.  The resume offset
+			 * should therefore always clear ACK */
+			outb(D700_get_SXFER(hostdata->cmd->device),
+			     host->base + SXFER_REG);
+			
+		}
+	} else if(dsps == A_RESELECTED_DURING_SELECTION) {
+
+		/* This section is full of debugging code because I've
+		 * never managed to reach it.  I think what happens is
+		 * that, because the 700 runs with selection
+		 * interrupts enabled the whole time that we take a
+		 * selection interrupt before we manage to get to the
+		 * reselected script interrupt */
+
+		__u8 reselection_id = inb(host->base + SFBR_REG);
+		struct D700_command_slot *slot;
+		
+		/* Take out our own ID */
+		reselection_id &= ~(1<<host->this_id);
+		
+		printk("scsi%d: (%d:%d) RESELECTION DURING SELECTION, dsp=%p[%04x] state=%d, count=%d\n",
+		       host->host_no, reselection_id, lun, (void *)dsp, dsp - hostdata->pScript, hostdata->state, hostdata->command_slot_count);
+
+		{
+			/* FIXME: DEBUGGING CODE */
+			__u32 SG = (__u32)bus_to_virt(hostdata->script[A_SGScriptStartAddress_used[0]]);
+			int i;
+
+			for(i=0; i< D700_COMMAND_SLOTS_PER_HOST; i++) {
+				if(SG >= (__u32)(&hostdata->slots[i].SG[0])
+				   && SG <= (__u32)(&hostdata->slots[i].SG[NCR_D700_SG_SEGMENTS]))
+					break;
+			}
+			printk("IDENTIFIED SG segment as being %p in slot %p, cmd %p, slot->resume_offset=%p\n", (void *)SG, &hostdata->slots[i], hostdata->slots[i].cmnd, (void *)hostdata->slots[i].resume_offset);
+			SCp =  hostdata->slots[i].cmnd;
+		}
+
+		if(SCp != NULL) {
+			slot = (struct D700_command_slot *)SCp->host_scribble;
+			/* change slot from busy to queued to redo command */
+			slot->state = D700_SLOT_QUEUED;
+		}
+		hostdata->cmd = NULL;
+		
+		if(reselection_id == 0) {
+			if(hostdata->reselection_id == 0xff) {
+				printk(KERN_ERR "scsi%d: Invalid reselection during selection!!\n", host->host_no);
+				return 0;
+			} else {
+				printk(KERN_ERR "scsi%d: script reselected and we took a selection interrupt\n",
+				       host->host_no);
+				reselection_id = hostdata->reselection_id;
+			}
+		} else {
+			
+			/* convert to real ID */
+			reselection_id = bitmap_to_number(reselection_id);
+		}
+		hostdata->reselection_id = reselection_id;
+		resume_offset = hostdata->pScript + Ent_GetReselectionData;
+	} else if(dsps == A_WDTR_MSG_AFTER_CMD) { 
+		/* FIXME: message processing engine should be better */
+		printk(KERN_INFO "scsi%d: (%d:%d), Unsolicited WDTR after CMD, Rejecting\n",
+		       host->host_no, pun, lun);
+		hostdata->msgout[0] = A_REJECT_MSG;
+		script_patch_16(hostdata->script, MessageCount, 1);
+		resume_offset = dsp;
+	} else if(dsps == A_SDTR_MSG_AFTER_CMD) {
+		/* FIXME: message processing should be better */
+		printk(KERN_INFO "scsi%d: (%d:%d), Unsolicited SDTR after CMD, Rejecting\n",
+		       host->host_no, pun, lun);
+		hostdata->msgout[0] = A_REJECT_MSG;
+		script_patch_16(hostdata->script, MessageCount, 1);
+		resume_offset = dsp;
+	} else if((dsps &  0xfffff000) == 0) {
+		__u8 i = (dsps & 0xf0) >> 4, j = (dsps & 0xf00) >> 8;
+		printk(KERN_ERR "scsi%d: (%d:%d), unhandled script condition %s %s at %04x\n",
+		       host->host_no, pun, lun, D700_condition[i],
+		       D700_phase[j], dsp - hostdata->pScript);
+		if(SCp != NULL) {
+			print_command(SCp->cmnd);
+
+			if(SCp->use_sg) {
+				for(i = 0; i < SCp->use_sg + 1; i++) {
+					printk(" SG[%d].length = %d, move_insn=%08x, addr %08x\n", i, ((struct scatterlist *)SCp->buffer)[i].length, ((struct D700_command_slot *)SCp->host_scribble)->SG[i].ins, ((struct D700_command_slot *)SCp->host_scribble)->SG[i].pAddr);
+				}
+			}
+		}	       
+		D700_internal_bus_reset(host);
+	} else {
+		printk(KERN_ERR "scsi%d: (%d:%d), unidentified script interrupt 0x%x at %04x\n",
+		       host->host_no, pun, lun, dsps, dsp - hostdata->pScript);
+		D700_internal_bus_reset(host);
+	}
+	return resume_offset;
+}
+
+STATIC int
+D700_start_command(Scsi_Cmnd *SCp)
+{
+	struct D700_command_slot *slot =
+		(struct D700_command_slot *)SCp->host_scribble;
+	struct D700_Host_Parameters *hostdata =
+		(struct D700_Host_Parameters *)SCp->host->hostdata[0];
+	unsigned long flags;
+	
+	save_flags(flags);
+	cli();
+	if(hostdata->state != D700_HOST_FREE) {
+		/* keep this inside the lock to close the race window where
+		 * the running command finishes on another CPU while we don't
+		 * change the state to queued on this one */
+		slot->state = D700_SLOT_QUEUED;
+		restore_flags(flags);
+
+		DEBUG(("scsi%d: host busy, queueing command %p, slot %p\n",
+		       SCp->host->host_no, slot->cmnd, slot));
+		return 0;
+	}
+	hostdata->state = D700_HOST_BUSY;
+	hostdata->cmd = SCp;
+	slot->state = D700_SLOT_BUSY;
+	/* keep interrupts disabled until we have the command correctly
+	 * set up so we cannot take a selection interrupt */
+
+	hostdata->msgout[0] = D700_identify(1, SCp->lun);
+	/* for INQUIRY or REQUEST_SENSE commands, we cannot be sure
+	 * if the negotiated transfer parameters still hold, so
+	 * always renegotiate them */
+	if(SCp->cmnd[0] == INQUIRY || SCp->cmnd[0] == REQUEST_SENSE) {
+		D700_clear_flag(SCp->device, D700_DEV_NEGOTIATED_SYNC);
+	}
+
+	if(hostdata->fast &&
+	   D700_is_flag_clear(SCp->device, D700_DEV_NEGOTIATED_SYNC)) {
+		memcpy(&hostdata->msgout[1], D700_SDTR_msg,
+		       sizeof(D700_SDTR_msg));
+		script_patch_16(hostdata->script, MessageCount,
+				1 + sizeof(D700_SDTR_msg));
+		D700_set_flag(SCp->device, D700_DEV_BEGIN_SYNC_NEGOTIATION);
+	} else {
+		script_patch_16(hostdata->script, MessageCount, 1);
+	}
+
+	script_patch_ID(hostdata->script,
+			Device_ID, 1<<SCp->target);
+
+	script_patch_32_abs(hostdata->script, CommandAddress, 
+			virt_to_bus(SCp->cmnd));
+	script_patch_16(hostdata->script, CommandCount, SCp->cmd_len);
+	/* finally plumb the beginning of the SG list into the script
+	 * */
+	script_patch_32_abs(hostdata->script, SGScriptStartAddress,
+			    virt_to_bus(&slot->SG[0].ins));
+	outb(CLR_FIFO, SCp->host->base + DFIFO_REG);
+
+	/* set the synchronous period/offset */
+	if(slot->resume_offset == 0)
+		slot->resume_offset = hostdata->pScript;
+	outb(D700_get_SXFER(SCp->device),
+	     SCp->host->base + SXFER_REG);
+	/* allow interrupts here so that if we're selected we can take
+	 * a selection interrupt.  The script start may not be
+	 * effective in this case, but the selection interrupt will
+	 * save our command in that case */
+	outl(slot->temp, SCp->host->base + TEMP_REG);
+	outl(slot->resume_offset, SCp->host->base + DSP_REG);
+	restore_flags(flags);
+
+	return 1;
+}
+
+STATIC void
+D700_intr(int irq, void *dev_id, struct pt_regs *regs)
+{
+	struct Scsi_Host *host = (struct Scsi_Host *)dev_id;
+	struct D700_Host_Parameters *hostdata =
+		(struct D700_Host_Parameters *)host->hostdata[0];
+	__u8 istat;
+	__u32 resume_offset = 0;
+	__u8 pun = 0xff, lun = 0xff;
+	unsigned long flags;
+
+	/* Unfortunately, we have to take the io_request_lock here
+	 * rather than the host lock hostdata->lock because we're
+	 * looking to exclude queuecommand from messing with the
+	 * registers while we're processing the interrupt.  Since
+	 * queuecommand is called holding io_request_lock, and we have
+	 * to take io_request_lock before we call the command
+	 * scsi_done, we would get a deadlock if we took
+	 * hostdata->lock here and in queuecommand (because the order
+	 * of locking in queuecommand: 1) io_request_lock then 2)
+	 * hostdata->lock would be the reverse of taking it in this
+	 * routine */
+	spin_lock_irqsave(&io_request_lock, flags);
+	if((istat = inb(host->base + ISTAT_REG))
+	      & (SCSI_INT_PENDING | DMA_INT_PENDING)) {
+		__u32 dsps;
+		__u8 sstat0 = 0, dstat = 0;
+		__u32 dsp;
+		Scsi_Cmnd *SCp = hostdata->cmd;
+		enum D700_Host_State state;
+
+		state = hostdata->state;
+		SCp = hostdata->cmd;
+
+		if(istat & SCSI_INT_PENDING) {
+			udelay(10);
+
+			sstat0 = inb(host->base + SSTAT0_REG);
+		}
+
+		if(istat & DMA_INT_PENDING) {
+			udelay(10);
+
+			dstat = inb(host->base + DSTAT_REG);
+		}
+
+		dsps = inl(host->base + DSPS_REG);
+		dsp = inl(host->base + DSP_REG);
+
+		DEBUG(("scsi%d: istat %02x sstat0 %02x dstat %02x dsp %04x[%08lx] dsps 0x%x\n",
+		       host->host_no, istat, sstat0, dstat,
+		       (dsp - (__u32)virt_to_bus(hostdata->script))/4,
+		       dsp, dsps));
+
+		if(sstat0 & SCSI_RESET_DETECTED) {
+			Scsi_Device *SDp;
+			int i;
+
+			hostdata->state = D700_HOST_BUSY;
+
+			printk(KERN_ERR "scsi%d: Bus Reset detected, executing command %p, slot %p, dsp %p[%04x]\n",
+			       host->host_no, SCp, SCp == NULL ? NULL : SCp->host_scribble, (void *)dsp, dsp - hostdata->pScript);
+
+			/* clear all the negotiated parameters */
+			for(SDp = host->host_queue; SDp != NULL; SDp = SDp->next)
+				SDp->hostdata = 0;
+			
+			/* clear all the slots and their pending commands */
+			for(i = 0; i < D700_COMMAND_SLOTS_PER_HOST; i++) {
+				Scsi_Cmnd *SCp;
+				struct D700_command_slot *slot =
+					&hostdata->slots[i];
+
+				if(slot->state == D700_SLOT_FREE)
+					continue;
+				
+				SCp = slot->cmnd;
+				printk(KERN_ERR " failing command because of reset, slot %p, cmnd %p\n",
+				       slot, SCp);
+				free_slot(slot, hostdata);
+				SCp->host_scribble = NULL;
+				/* NOTE: deadlock potential here: we
+				 * rely on mid-layer guarantees that
+				 * scsi_done won't try to issue the
+				 * command again otherwise we'll
+				 * deadlock on the
+				 * hostdata->state_lock */
+				SCp->result = DID_RESET << 16;
+				SCp->scsi_done(SCp);
+			}
+			mdelay(25);
+			D700_chip_setup(host);
+
+			hostdata->state = D700_HOST_FREE;
+			hostdata->cmd = NULL;
+		}
+
+		if(SCp != NULL) {
+			pun = SCp->target;
+			lun = SCp->lun;
+		}
+		if(sstat0 & SELECTION_TIMEOUT) {
+			DEBUG(("scsi%d: (%d:%d) selection timeout\n",
+			       host->host_no, pun, lun));
+			D700_scsi_done(hostdata, SCp, DID_NO_CONNECT<<16);
+		} 
+
+		if(sstat0 & PHASE_MISMATCH) {
+			struct D700_command_slot *slot = 
+				(struct D700_command_slot *)SCp->host_scribble;
+
+			if(dsp >= virt_to_bus(&slot->SG[0].ins) &&
+			   dsp <= virt_to_bus(&slot->SG[NCR_D700_SG_SEGMENTS].ins)) {
+				int data_transfer = inl(host->base + DBC_REG) & 0xffffff;
+				int SGcount = (dsp - virt_to_bus(&slot->SG[0].ins))/sizeof(struct D700_SG_List);
+				int residual = D700_data_residual(host);
+				int i;
+#ifdef NCR_D700_DEBUG
+				printk("scsi%d: (%d:%d) Expected phase mismatch in slot->SG[%d], transferred 0x%x\n",
+				       host->host_no, pun, lun,
+				       SGcount, data_transfer);
+				print_command(SCp->cmnd);
+				if(residual) {
+					printk("scsi%d: (%d:%d) Expected phase mismatch in slot->SG[%d], transferred 0x%x, residual %d\n",
+				       host->host_no, pun, lun,
+				       SGcount, data_transfer, residual);
+				}
+#endif
+				data_transfer += residual;
+
+				/* point to mismatch ins */
+				/* FIXME: Should check the contents of
+				 * the DMA FIFO to see if it contains
+				 * any untransferred bytes.  In
+				 * practice, most devices DISCONNECT
+				 * on a block boundary, so this is
+				 * unnecessary, but we'll screw up
+				 * badly if this becomes untrue for
+				 * some device */
+				if(data_transfer != 0) {
+					int count; 
+					SGcount--;
+
+					count = (slot->SG[SGcount].ins & 0x00ffffff);
+					DEBUG(("DATA TRANSFER MISMATCH, count = %d, transferred %d\n", count, count-data_transfer));
+					slot->SG[SGcount].ins &= 0xff000000;
+					slot->SG[SGcount].ins |= data_transfer;
+					slot->SG[SGcount].pAddr += (count - data_transfer);
+				}
+				/* set the executed moves to nops */
+				for(i=0; i<SGcount; i++) {
+					slot->SG[i].ins = SCRIPT_NOP;
+					slot->SG[i].pAddr = 0;
+				}
+				/* and pretend we disconnected after
+				 * the command phase */
+				resume_offset = hostdata->pScript + Ent_MsgInDuringData;
+			} else {
+				__u8 sbcl = inb(host->base + SBCL_REG);
+				printk(KERN_ERR "scsi%d: (%d:%d) phase mismatch at %04x, phase %s\n",
+				       host->host_no, pun, lun, dsp - hostdata->pScript, sbcl_to_string(sbcl));
+				D700_internal_bus_reset(host);
+			}
+
+		}
+
+		if(sstat0 & SCSI_GROSS_ERROR) {
+			printk(KERN_ERR "scsi%d: (%d:%d) GROSS ERROR\n",
+			       host->host_no, pun, lun);
+			D700_scsi_done(hostdata, SCp, DID_ERROR<<16);
+		} 
+
+		if(dstat & SCRIPT_INT_RECEIVED) {
+			DEBUG(("scsi%d: (%d:%d) ====>SCRIPT INTERRUPT<====\n",
+			       host->host_no, pun, lun));
+			resume_offset = process_script_interrupt(dsps, dsp, SCp, host, hostdata);
+		} 
+
+		if(dstat & (ILGL_INST_DETECTED)) {
+			printk(KERN_ERR "scsi%d: (%d:%d) Illegal Instruction detected at 0x%p[0x%x]!!!\n"
+			       "         Please email James.Bottomley@HansenPartnership.com with the details\n",
+			       host->host_no, pun, lun,
+			       (void *)dsp, dsp - hostdata->pScript);
+			D700_scsi_done(hostdata, SCp, DID_ERROR<<16);
+		} 
+
+		if(dstat & (WATCH_DOG_INTERRUPT|ABORTED)) {
+			printk(KERN_ERR "scsi%d: (%d:%d) serious DMA problem, dstat=%02x\n",
+			       host->host_no, pun, lun, dstat);
+			D700_scsi_done(hostdata, SCp, DID_ERROR<<16);
+		}
+
+		
+		/* NOTE: selection interrupt processing MUST occur
+		 * after script interrupt processing to correctly cope
+		 * with the case where we process a disconnect and
+		 * then get reselected before we process the
+		 * disconnection */
+		if(sstat0 & SELECTED) {
+			/* FIXME: It currently takes at least FOUR
+			 * interrupts to complete a command that
+			 * disconnects: one for the disconnect, one
+			 * for the reselection, one to get the
+			 * reselection data and one to complete the
+			 * command.  If we guess the reselected
+			 * command here and prepare it, we only need
+			 * to get a reselection data interrupt if we
+			 * guessed wrongly.  Since the interrupt
+			 * overhead is much greater than the command
+			 * setup, this would be an efficient
+			 * optimisation particularly as we probably
+			 * only have one outstanding command on a
+			 * target most of the time */
+
+			__u8 id = inb(host->base + SFBR_REG);
+	
+			/* Take out our own ID */
+			id &= ~(1<<host->this_id);
+			
+			if(id == 0) {
+				/* no selection */
+				printk(" INCORRECT IDENTIFICATION OF RESELECTION\n");
+			} else {
+	
+				/* convert to real ID */
+				hostdata->reselection_id = id = bitmap_to_number(id);
+				DEBUG(("scsi%d:  Reselected by %d\n",
+				       host->host_no, id));
+				
+				if(hostdata->state == D700_HOST_BUSY) {
+					struct D700_command_slot *slot =
+						(struct D700_command_slot *)hostdata->cmd->host_scribble;
+					DEBUG(("  ID %d WARNING: RESELECTION OF BUSY HOST, saving cmd %p, slot %p, addr %p [%04x], resume %p!\n", id, hostdata->cmd, slot, dsp, dsp - hostdata->pScript, resume_offset));
+
+					switch(dsp - hostdata->pScript) {
+					case Ent_Disconnect1:
+					case Ent_Disconnect2:
+						save_for_reselection(hostdata, SCp, Ent_Disconnect2 + hostdata->pScript);
+						break;
+					case Ent_Disconnect3:
+					case Ent_Disconnect4:
+						save_for_reselection(hostdata, SCp, Ent_Disconnect4 + hostdata->pScript);
+						break;
+					case Ent_Disconnect5:
+					case Ent_Disconnect6:
+						save_for_reselection(hostdata, SCp, Ent_Disconnect6 + hostdata->pScript);
+						break;
+					case Ent_Disconnect7:
+					case Ent_Disconnect8:
+						save_for_reselection(hostdata, SCp, Ent_Disconnect8 + hostdata->pScript);
+						break;
+					case Ent_Finish1:
+					case Ent_Finish2:
+						process_script_interrupt(A_GOOD_STATUS_AFTER_STATUS, dsp, SCp, host, hostdata);
+						break;
+						
+					default:
+						slot->state = D700_SLOT_QUEUED;
+						break;
+					}
+				}
+				hostdata->state = D700_HOST_BUSY;
+				hostdata->cmd = NULL;
+
+				resume_offset = hostdata->pScript + Ent_GetReselectionData;
+			}
+
+
+		}
+
+	}
+
+	if(resume_offset) {
+		if(hostdata->state != D700_HOST_BUSY) {
+			printk(KERN_ERR "scsi%d: Driver error: resume at %p [%04x] with non busy host!\n",
+			       host->host_no, (void *)resume_offset, resume_offset - hostdata->pScript);
+			hostdata->state = D700_HOST_BUSY;
+		}
+
+		DEBUG(("Attempting to resume at %x\n", resume_offset));
+		outb(CLR_FIFO, host->base + DFIFO_REG);
+		outl(resume_offset, host->base + DSP_REG);
+	} 
+	/* There is probably a technical no-no about this: If we're a
+	 * shared interrupt and we got this interrupt because the
+	 * other device needs servicing not us, we're still going to
+	 * check our queued commands here---of course, there shouldn't
+	 * be any outstanding.... */
+	if(hostdata->state == D700_HOST_FREE) {
+		int i;
+
+		for(i = 0; i < D700_COMMAND_SLOTS_PER_HOST; i++) {
+			/* fairness: always run the queue from the last
+			 * position we left off */
+			int j = (i + hostdata->saved_slot_position)
+				% D700_COMMAND_SLOTS_PER_HOST;
+			
+			if(hostdata->slots[j].state != D700_SLOT_QUEUED)
+				continue;
+			if(D700_start_command(hostdata->slots[j].cmnd)) {
+				DEBUG(("scsi%d: Issuing saved command slot %p, cmd %p\t\n",
+				       host->host_no, &hostdata->slots[j],
+				       hostdata->slots[j].cmnd));
+				hostdata->saved_slot_position = j + 1;
+			}
+
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&io_request_lock, flags);
+}
+
+/* FIXME: Need to put some proc information in and plumb it
+ * into the scsi proc system */
+STATIC int
+D700_proc_directory_info(char *ProcBuffer, char **StartPointer,
+			       off_t Offset, int BytesAvailable,
+			       int HostNumber, int WriteFlag)
+{
+	return 0;
+}
+
+/* Detect a D700 card.  Note, because of the set up---the chips are
+ * essentially connectecd to the MCA bus independently, it is easier
+ * to set them up as two separate host adapters, rather than one
+ * adapter with two channels */
+STATIC int
+D700_detect(Scsi_Host_Template *tpnt)
+{
+	int slot = 0;
+	int found = 0;
+	int differential;
+	int banner = 1;
+
+	if(!MCA_bus)
+		return 0;
+
+	for(slot = 0; (slot = mca_find_adapter(NCR_D700_MCA_ID, slot)) != MCA_NOTFOUND; slot++) {
+		int irq, i;
+		int pos3j, pos3k, pos3a, pos3b, pos4;
+		__u32 base_addr, offset_addr;
+		struct Scsi_Host *host = NULL;
+
+		/* enable board interrupt */
+		pos4 = mca_read_pos(slot, 4);
+		pos4 |= 0x4;
+		mca_write_pos(slot, 4, pos4);
+
+		mca_write_pos(slot, 6, 9);
+		pos3j = mca_read_pos(slot, 3);
+		mca_write_pos(slot, 6, 10);
+		pos3k = mca_read_pos(slot, 3);
+		mca_write_pos(slot, 6, 0);
+		pos3a = mca_read_pos(slot, 3);
+		mca_write_pos(slot, 6, 1);
+		pos3b = mca_read_pos(slot, 3);
+
+		base_addr = ((pos3j << 8) | pos3k) & 0xfffffff0;
+		offset_addr = ((pos3a << 8) | pos3b) & 0xffffff70;
+
+		irq = (pos4 & 0x3) + 11;
+		if(irq >= 13)
+			irq++;
+		if(banner) {
+			printk(KERN_NOTICE "NCR D700: Driver Version " NCR_D700_VERSION "\n"
+			       "NCR D700:  Copyright (c) 2001 by James.Bottomley@HansenPartnership.com\n"
+			       "NCR D700:\n");
+			banner = 0;
+		}
+		printk(KERN_NOTICE "NCR D700: found in slot %d  irq = %d  I/O base = 0x%x\n", slot, irq, offset_addr);
+
+		tpnt->proc_name = "NCR_D700";
+
+		/*outb(BOARD_RESET, base_addr);*/
+
+		/* clear any pending interrupts */
+		(void)inb(base_addr + 0x08);
+		/* get modctl, used later for setting diff bits */
+		switch(differential = (inb(base_addr + 0x08) >> 6)) {
+		case 0x00:
+			/* only SIOP1 differential */
+			differential = 0x02;
+			break;
+		case 0x01:
+			/* Both SIOPs differential */
+			differential = 0x03;
+			break;
+		case 0x03:
+			/* No SIOPs differential */
+			differential = 0x00;
+			break;
+		default:
+			printk(KERN_ERR "D700: UNEXPECTED DIFFERENTIAL RESULT 0x%02x\n",
+			       differential);
+			differential = 0x00;
+			break;
+		}
+
+		/* plumb in both 700 chips */
+		for(i=0; i<2; i++) {
+			__u32 *script = kmalloc(sizeof(SCRIPT), GFP_KERNEL);
+			__u32 pScript;
+			__u32 region = offset_addr | (0x80 * i);
+			int j;
+			struct D700_Host_Parameters *hostdata =
+				kmalloc(sizeof(struct D700_Host_Parameters),
+					GFP_KERNEL);
+			host = scsi_register(tpnt, 4);
+			if(request_irq(irq, D700_intr, SA_SHIRQ, "NCR_D700", host)) {
+				printk(KERN_ERR "NCR D700, channel %d: irq problem, detatching\n", i);
+				scsi_unregister(host);
+				continue;
+			}
+			if(script == NULL) {
+				printk(KERN_ERR "NCR D700: Failed to allocate script for channel %d, detatching\n", i);
+				scsi_unregister(host);
+				continue;
+			}
+			if(hostdata == NULL) {
+				printk(KERN_ERR "NCR D700: Failed to allocate host data for channel %d, detatching\n", i);
+				scsi_unregister(host);
+				continue;
+			}
+			memset(hostdata, 0, sizeof(struct D700_Host_Parameters));
+			hostdata->slots = kmalloc(sizeof(struct D700_command_slot) * D700_COMMAND_SLOTS_PER_HOST, GFP_KERNEL);
+			if(hostdata->slots == NULL) {
+				printk(KERN_ERR "NCR D700: Failed to allocate command slots for channel %d, detatching\n", i);
+				kfree(hostdata);
+				scsi_unregister(host);
+				continue;
+			}
+			memset(hostdata->slots, 0, sizeof(struct D700_command_slot) * D700_COMMAND_SLOTS_PER_HOST);
+			for(j = 0; j < D700_COMMAND_SLOTS_PER_HOST; j++)
+				hostdata->slots[j].state = D700_SLOT_FREE;
+			host->hostdata[0] = (__u32)hostdata;
+			memcpy(script, SCRIPT, sizeof(SCRIPT));
+			/* bus physical address of script */
+			pScript = virt_to_bus(script);
+			/* adjust all labels to be bus physical */
+			for(j = 0; j < PATCHES; j++) {
+				script[LABELPATCHES[j]] += pScript;
+			}
+			/* now patch up fixed addresses */
+			script_patch_32(script, MessageLocation,
+					virt_to_bus(&hostdata->msgout[0]));
+			script_patch_32(script, StatusAddress,
+					virt_to_bus(&hostdata->status));
+			script_patch_32(script, ReceiveMsgAddress,
+					virt_to_bus(&hostdata->msgin[0]))
+			hostdata->script = script;
+			hostdata->pScript = pScript;
+			hostdata->board_base = base_addr;
+			hostdata->state = D700_HOST_FREE;
+			spin_lock_init(&hostdata->lock);
+			hostdata->cmd = NULL;
+			host->irq = irq;
+			host->this_id = 7; /* FIXME: need to read from BIOS */
+			host->max_id = 7;
+			host->max_lun = NCR_D700_MAX_LUNS;
+			host->unique_id = region;
+			request_region(region, 64, "NCR_D700");
+			host->base = region;
+			/* kick the chip */
+			outb(0xff, host->base + CTEST9_REG);
+			hostdata->rev = (inb(host->base + CTEST7_REG)<<4) & 0x0f;
+			hostdata->differential = (((1<<i) & differential) != 0);
+			hostdata->fast = (inb(host->base + CTEST9_REG) == 0);
+			printk(KERN_NOTICE "NCR D700:     SIOP%d (scsi%d): %s rev %d %s\n", i, host->host_no,
+			       hostdata->fast
+			       ? "53c700-66" : "53c700",
+			       hostdata->rev, hostdata->differential ?
+			       "(Differential)" : "");
+			/* reset the chip */
+			D700_chip_reset(host);
+			outb(ASYNC_OPERATION , host->base + SXFER_REG);
+			found++;
+		}
+	}
+
+	return found;
+}
+
+
+STATIC int
+D700_release(struct Scsi_Host *host)
+{
+	struct D700_Host_Parameters *hostdata = 
+		(struct D700_Host_Parameters *)host->hostdata[0];
+
+	kfree(hostdata->script);
+	kfree(hostdata);
+	free_irq(host->irq, host);
+	release_region(host->base, 64);
+	return 1;
+}
+
+STATIC int
+D700_queuecommand(Scsi_Cmnd *SCp, void (*done)(Scsi_Cmnd *))
+{
+	struct D700_Host_Parameters *hostdata = 
+		(struct D700_Host_Parameters *)SCp->host->hostdata[0];
+	__u32 move_ins;
+	struct D700_command_slot *slot;
+
+	if(hostdata->command_slot_count >= D700_COMMAND_SLOTS_PER_HOST) {
+		/* We're over our allocation, this should never happen
+		 * since we report the max allocation to the mid layer */
+		printk(KERN_WARNING "scsi%d: Command depth has gone over queue depth\n", SCp->host->host_no);
+		return 1;
+	}
+	if(D700_get_depth(SCp->device) != 0) {
+		printk(KERN_ERR "scsi%d (%d:%d) has non zero depth %d\n",
+		       SCp->host->host_no, SCp->target, SCp->lun,
+		       D700_get_depth(SCp->device));
+		return 1;
+	}
+	D700_set_depth(SCp->device, D700_get_depth(SCp->device) + 1);
+
+	/* begin the command here */
+	/* no need to check for NULL, test for command_slot_cound above
+	 * ensures a slot is free */
+	slot = find_empty_slot(hostdata);
+
+	slot->cmnd = SCp;
+
+	SCp->scsi_done = done;
+	SCp->host_scribble = (unsigned char *)slot;
+	SCp->SCp.ptr = NULL;
+	SCp->SCp.buffer = NULL;
+
+#ifdef NCR_D700_DEBUG
+	printk("D700: scsi%d, command ", SCp->host->host_no);
+	print_command(SCp->cmnd);
+#endif
+
+	/* This is f****g ridiculous; every low level HBA driver has
+	 * to determine the direction of the commands, why isn't this
+	 * done inside the scsi_lib !!??? */
+	switch (SCp->cmnd[0]) {
+	case REQUEST_SENSE:
+		/* clear the internal sense magic */
+		SCp->cmnd[6] = 0;
+		/* fall through */
+	case INQUIRY:
+	case MODE_SENSE:
+	case READ_6:
+	case READ_10:
+	case READ_12:
+	case READ_CAPACITY:
+	case READ_BLOCK_LIMITS:
+	case READ_TOC:
+		move_ins = SCRIPT_MOVE_DATA_IN;
+		break;
+	case MODE_SELECT:
+	case WRITE_6:
+	case WRITE_10:
+	case WRITE_12:
+		move_ins = SCRIPT_MOVE_DATA_OUT;
+		break;
+	case TEST_UNIT_READY:
+	case ALLOW_MEDIUM_REMOVAL:
+	case START_STOP:
+		move_ins = 0;
+		break;
+	default:
+		/* OK, get it from the command */
+		switch(SCp->sc_data_direction) {
+		case SCSI_DATA_UNKNOWN:
+		default:
+			printk(KERN_ERR "NCR D700: Unknown command for data direction ");
+			print_command(SCp->cmnd);
+			
+			move_ins = 0;
+			break;
+		case SCSI_DATA_NONE:
+			move_ins = 0;
+			break;
+		case SCSI_DATA_READ:
+			move_ins = SCRIPT_MOVE_DATA_IN;
+			break;
+		case SCSI_DATA_WRITE:
+			move_ins = SCRIPT_MOVE_DATA_OUT;
+			break;
+		}
+	}
+
+	/* now build the scatter gather list */
+	if(move_ins != 0) {
+		int i;
+
+		for(i = 0; i < (SCp->use_sg ? SCp->use_sg : 1); i++) {
+			void *vPtr;
+			__u32 count;
+
+			if(SCp->use_sg) {
+				vPtr = (((struct scatterlist *)SCp->buffer)[i].address);
+				count = ((struct scatterlist *)SCp->buffer)[i].length;
+			} else {
+				vPtr = SCp->request_buffer;
+				count = SCp->request_bufflen;
+			}
+			slot->SG[i].ins = move_ins | count;
+			DEBUG((" scatter block %d: move %d[%08lx] from 0x%lx\n",
+			       i, count, slot->SG[i].move_ins, 
+			       virt_to_bus(vPtr)));
+			slot->SG[i].pAddr = virt_to_bus(vPtr);
+		}
+		hostdata->expect_pmm = virt_to_bus(&slot->SG[i].ins);
+		slot->SG[i].ins = SCRIPT_RETURN;
+		slot->SG[i].pAddr = 0;
+		DEBUG((" SETTING %08x to %x\n",
+		       virt_to_bus(&slot->SG[i].ins), 
+		       slot->SG[i].ins));
+	}
+	slot->resume_offset = 0;
+	D700_start_command(SCp);
+	return 0;
+}
+
+STATIC int
+D700_abort(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants to abort command\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun);
+	print_command(SCp->cmnd);
+	return FAILED;
+}
+
+STATIC int
+D700_bus_reset(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants BUS reset, cmd %p\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun, SCp);
+	print_command(SCp->cmnd);
+	D700_internal_bus_reset(SCp->host);
+	return SUCCESS;
+}
+
+STATIC int
+D700_dev_reset(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants device reset\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun);
+	print_command(SCp->cmnd);
+	
+	return FAILED;
+}
+
+STATIC int
+D700_host_reset(Scsi_Cmnd * SCp)
+{
+	printk("scsi%d (%d:%d) New error handler wants HOST reset\n\t",
+	       SCp->host->host_no, SCp->target, SCp->lun);
+	print_command(SCp->cmnd);
+
+	D700_internal_bus_reset(SCp->host);
+	D700_chip_reset(SCp->host);
+	return SUCCESS;
+}
+
+
+static Scsi_Host_Template driver_template = NCR_D700_SCSI;
+
+#include "scsi_module.c"
+
Index: linux/2.4/drivers/scsi/NCR_D700.h
diff -u /dev/null linux/2.4/drivers/scsi/NCR_D700.h:1.1.2.14
--- /dev/null	Sun Apr 29 10:16:33 2001
+++ linux/2.4/drivers/scsi/NCR_D700.h	Sat Apr 28 12:31:54 2001
@@ -0,0 +1,339 @@
+/* -*- mode: c; c-basic-offset: 8 -*- */
+
+/* NCR Dual 700 MCA SCSI Driver
+ *
+ * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
+ */
+
+#ifndef _NCR_D700_H
+#define _NCR_D700_H
+
+#undef NCR_D700_DEBUG
+
+#ifdef NCR_D700_DEBUG
+#define DEBUG(x)	printk x
+#else
+#define DEBUG(x)
+#endif
+
+#define NCR_D700_SG_SEGMENTS	32
+#define D700_COMMAND_SLOTS_PER_HOST	16
+
+#define NCR_D700_MAX_LUNS		32
+#define NCR_D700_LUN_MASK		(NCR_D700_MAX_LUNS - 1)
+
+/* The MCA identifier */
+#define NCR_D700_MCA_ID		0x0092
+
+/* magic byte identifying an internally generated REQUEST_SENSE command */
+#define D700_INTERNAL_SENSE_MAGIC	0x42
+
+static int D700_detect(Scsi_Host_Template *);
+static int D700_release(struct Scsi_Host *host);
+static int D700_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
+static int D700_abort(Scsi_Cmnd * SCpnt);
+static int D700_bus_reset(Scsi_Cmnd * SCpnt);
+static int D700_dev_reset(Scsi_Cmnd * SCpnt);
+static int D700_host_reset(Scsi_Cmnd * SCpnt);
+
+#define NCR_D700_SCSI {						\
+	name:				"NCR Dual 700 MCA",	\
+	proc_name:			"NCR_D700",		\
+	detect: 			D700_detect,		\
+	release:			D700_release,		\
+	queuecommand:			D700_queuecommand,	\
+	eh_abort_handler:		D700_abort,		\
+	eh_device_reset_handler:	D700_dev_reset,		\
+	eh_bus_reset_handler:		D700_bus_reset,		\
+	eh_host_reset_handler:		D700_host_reset,	\
+	can_queue:			D700_COMMAND_SLOTS_PER_HOST,\
+	this_id:			7,			\
+	sg_tablesize:		        NCR_D700_SG_SEGMENTS,	\
+	cmd_per_lun:			1,			\
+	use_clustering:			DISABLE_CLUSTERING,	\
+	use_new_eh_code:		1,			\
+}
+
+enum D700_Host_State {
+	D700_HOST_BUSY,
+	D700_HOST_FREE,
+};
+
+struct D700_SG_List {
+	/* The following is a script fragment to move the buffer onto the
+	 * bus and then link the next fragment or return */
+	#define	SCRIPT_MOVE_DATA_IN		0x09000000
+	#define	SCRIPT_MOVE_DATA_OUT		0x08000000
+	__u32	ins;
+	__u32	pAddr;
+	#define	SCRIPT_NOP			0x80000000
+	#define	SCRIPT_RETURN			0x90080000
+};
+
+/* We use device->hostdata to store negotiated parameters.  This is
+ * supposed to be a pointer to a device private area, but we cannot
+ * really use it as such since it will never be freed, so just use the
+ * 32 bits to cram the information.  The SYNC negotiation sequence looks
+ * like:
+ * 
+ * If DEV_NEGOTIATED_SYNC not set, tack and SDTR message on to the
+ * initial identify for the device and set DEV_BEGIN_SYNC_NEGOTATION
+ * If we get an SDTR reply, work out the SXFER parameters, squirrel
+ * them away here, clear DEV_BEGIN_SYNC_NEGOTIATION and set
+ * DEV_NEGOTIATED_SYNC.  If we get a REJECT msg, squirrel
+ *
+ *
+ * 0:7	SXFER_REG negotiated value for this device
+ * 8:15 Current queue depth
+ * 16	negotiated SYNC flag
+ * 17 begin SYNC negotiation flag */
+#define D700_DEV_NEGOTIATED_SYNC	(1<<16)
+#define D700_DEV_BEGIN_SYNC_NEGOTIATION	(1<<17)
+static inline void D700_set_SXFER(Scsi_Device *SDp, __u8 sxfer) {
+	((__u32)SDp->hostdata) &= 0xffffff00;
+	((__u32)SDp->hostdata) |= sxfer & 0xff;
+}
+static inline __u8 D700_get_SXFER(Scsi_Device *SDp) {
+	return (((__u32)SDp->hostdata) & 0xff);
+}
+static inline void D700_set_depth(Scsi_Device *SDp, __u8 depth) {
+	((__u32)SDp->hostdata) &= 0xffff00ff;
+	((__u32)SDp->hostdata) |= (0xff00 & (depth << 8));
+}
+static inline __u8 D700_get_depth(Scsi_Device *SDp) {
+	return ((((__u32)SDp->hostdata) & 0xff00)>>8);
+}
+static inline int D700_is_flag_set(Scsi_Device *SDp, __u32 flag) {
+	return (((__u32)SDp->hostdata) & flag) == flag;
+}
+static inline int D700_is_flag_clear(Scsi_Device *SDp, __u32 flag) {
+	return (((__u32)SDp->hostdata) & flag) == 0;
+}
+static inline void D700_set_flag(Scsi_Device *SDp, __u32 flag) {
+	((__u32)SDp->hostdata) |= (flag & 0xffff0000);
+}
+static inline void D700_clear_flag(Scsi_Device *SDp, __u32 flag) {
+	((__u32)SDp->hostdata) &= ~(flag & 0xffff0000);
+}
+
+
+struct D700_command_slot {
+	#define D700_SLOT_MASK 0xFC
+	#define D700_SLOT_MAGIC 0xb8
+	#define	D700_SLOT_FREE (0|D700_SLOT_MAGIC) /* slot may be used */
+	#define D700_SLOT_BUSY (1|D700_SLOT_MAGIC) /* slot has command active on HA */
+	#define D700_SLOT_QUEUED (2|D700_SLOT_MAGIC) /* slot has command to be made active on HA */
+	__u8	state;
+	struct D700_SG_List	SG[NCR_D700_SG_SEGMENTS+1];
+	__u32	resume_offset;
+	Scsi_Cmnd	*cmnd;
+	__u32		temp;
+};
+
+struct D700_Host_Parameters {
+	__u32	*script;		/* pointer to script location */
+	__u32	pScript;		/* physical mem addr of script */
+	/* This will be the host lock.  Unfortunately, we can't use it
+	 * at the moment because of the necessity of holding the
+	 * io_request_lock */
+	spinlock_t lock;
+	enum D700_Host_State state; /* protected by state lock */
+	Scsi_Cmnd *cmd;
+
+	__u8	msgout[8];
+	__u8	msgout_size;
+	__u8	status;
+	__u8	msgin[8];
+	__u32	expect_pmm;
+	struct D700_command_slot	*slots;
+	int	saved_slot_position;
+	int	command_slot_count; /* protected by state lock */
+	__u8	rev;
+	__u8	reselection_id;
+	/* flags for the host */
+	__u8	differential:1;	/* if we are differential */
+	__u8	fast:1;		/* if we can alter the SCSI bus clock
+                                   speed (so can negiotiate sync) */
+
+	__u16	board_base;
+};
+
+/*
+ *	53C700 Register Interface - the offset from the Selected base
+ *	I/O address */
+
+#define	SCNTL0_REG			0x00
+#define		FULL_ARBITRATION	0xc0
+#define 	PARITY			0x08
+#define		ENABLE_PARITY		0x04
+#define 	AUTO_ATN		0x02
+#define	SCNTL1_REG			0x01
+#define 	SLOW_BUS		0x80
+#define		ENABLE_SELECT		0x20
+#define		ASSERT_RST		0x08
+#define		ASSERT_EVEN_PARITY	0x04
+#define	SDID_REG			0x02
+#define	SIEN_REG			0x03
+#define 	PHASE_MM_INT		0x80
+#define 	FUNC_COMP_INT		0x40
+#define 	SEL_TIMEOUT_INT		0x20
+#define 	SELECT_INT		0x10
+#define 	GROSS_ERR_INT		0x08
+#define 	UX_DISC_INT		0x04
+#define 	RST_INT			0x02
+#define 	PAR_ERR_INT		0x01
+#define	SCID_REG			0x04
+#define SXFER_REG			0x05
+#define		ASYNC_OPERATION		0x00
+#define SODL_REG                        0x06
+#define	SOCL_REG			0x07
+#define	SFBR_REG			0x08
+#define	SIDL_REG			0x09
+#define	SBDL_REG			0x0A
+#define	SBCL_REG			0x0B
+#define	DSTAT_REG			0x0C
+#define		ILGL_INST_DETECTED	0x01
+#define		WATCH_DOG_INTERRUPT	0x02
+#define		SCRIPT_INT_RECEIVED	0x04
+#define		ABORTED			0x10
+#define	SSTAT0_REG			0x0D
+#define		PARITY_ERROR		0x01
+#define		SCSI_RESET_DETECTED	0x02
+#define		UNEXPECTED_DISCONNECT	0x04
+#define		SCSI_GROSS_ERROR	0x08
+#define		SELECTED		0x10
+#define		SELECTION_TIMEOUT	0x20
+#define		FUNCTION_COMPLETE	0x40
+#define		PHASE_MISMATCH 		0x80
+#define	SSTAT1_REG			0x0E
+#define		SIDL_REG_FULL		0x80
+#define		SODR_REG_FULL		0x40
+#define		SODL_REG_FULL		0x20
+#define SSTAT2_REG                      0x0F
+#define CTEST0_REG                      0x14
+#define CTEST1_REG                      0x15
+#define CTEST2_REG                      0x16
+#define CTEST3_REG                      0x17
+#define CTEST4_REG                      0x18
+#define         DISABLE_FIFO            0x00
+#define         SLBE                    0x10
+#define         SFWR                    0x08
+#define         BYTE_LANE0              0x04
+#define         BYTE_LANE1              0x05
+#define         BYTE_LANE2              0x06
+#define         BYTE_LANE3              0x07
+#define         SCSI_ZMODE              0x20
+#define         ZMODE                   0x40
+#define CTEST5_REG                      0x19
+#define         MASTER_CONTROL          0x10
+#define         DMA_DIRECTION           0x08
+#define CTEST7_REG                      0x1B
+#define         DFP                     0x08
+#define         EVP                     0x04
+#define		DIFF			0x01	/* XXX - 0007 */
+#define CTEST6_REG                      0x1A
+#define	TEMP_REG			0x1C
+#define	DFIFO_REG			0x20
+#define		FLUSH_DMA_FIFO		0x80
+#define		CLR_FIFO		0x40
+#define	ISTAT_REG			0x21
+#define		ABORT_OPERATION		0x80
+#define		DMA_INT_PENDING		0x01
+#define		SCSI_INT_PENDING	0x02
+#define		CONNECTED		0x08
+#define CTEST8_REG                      0x22	/* XXX - 0006 */
+#define         LAST_DIS_ENBL           0x01 	/* XXX - 0006 */
+#define		SHORTEN_FILTERING	0x04	/* XXX - 0008 */
+#define		ENABLE_ACTIVE_NEGATION	0x10	/* XXX - 0008 */
+#define		GENERATE_RECEIVE_PARITY	0x20	/* XXX - 0010 */
+#define CTEST9_REG                      0x23	/* XXX - 0006 */
+#define	DBC_REG				0x24
+#define	DCMD_REG			0x27
+#define	DNAD_REG			0x28
+#define	DIEN_REG			0x39
+#define 	ABORT_INT		0x10
+#define 	INT_INST_INT		0x04
+#define 	WD_INT			0x02
+#define 	ILGL_INST_INT		0x01
+#define	DCNTL_REG			0x3B	/*SEE THE VERY SYSTEM DEPENDANT BELOW	*/
+#define		SOFTWARE_RESET		0x01
+#define 	SCRPTS_16BITS		32
+#define	DMODE_REG			0x34
+#define		BURST_LENGTH_1		0x00
+#define		BURST_LENGTH_2		0x40
+#define		BURST_LENGTH_4		0x80
+#define		BURST_LENGTH_8		0xC0
+#define 	BW16			32 
+#define 	MODE_286		16
+#define 	IO_XFER			8
+#define 	FIXED_ADDR		4
+
+#define DSP_REG                         0x2C
+#define DSPS_REG                        0x30
+
+/* Defines for the Board registers (not chip registers) */
+#define	BOARD_RESET		0x80	/* board level reset */
+#define ADD_PARENB		0x04	/* Address Parity Enabled */
+#define DAT_PARENB		0x01	/* Data Parity Enabled */
+#define SFBK_ENB		0x10	/* SFDBK Interrupt Enabled */
+#define LED0GREEN		0x20	/* Led 0 (red 0; green 1) XXX 0001-2 */
+#define LED1GREEN		0x40	/* Led 1 (red 0; green 1) XXX 0001-2 */
+#define LED0RED			0xDF	/* Led 0 (red 0; green 1) XXX 0002 */
+#define LED1RED			0xBF	/* Led 1 (red 0; green 1) XXX 0002 */
+
+#define NCR_D700_CLOCK_MHZ	50
+/* Parameters to begin SDTR negotiations.  Empirically, I find that
+ * the 53c700-66 cannot handle an offset >8, so don't change this  */
+#define NCR_D700_MAX_OFFSET	8
+#define NCR_D700_MIN_XFERP	1
+#define NCR_D700_MIN_PERIOD	25 /* for SDTR message, 100ns */
+
+#define script_patch_32(script, symbol, value) \
+{ \
+	int i; \
+	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
+		(script)[A_##symbol##_used[i]] += (value); \
+		DEBUG((" script, patching %s at %ld to 0x%lx\n", \
+		       #symbol, A_##symbol##_used[i], (value))); \
+	} \
+}
+
+#define script_patch_32_abs(script, symbol, value) \
+{ \
+	int i; \
+	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
+		(script)[A_##symbol##_used[i]] = (value); \
+		DEBUG((" script, patching %s at %ld to 0x%lx\n", \
+		       #symbol, A_##symbol##_used[i], (value))); \
+	} \
+}
+
+/* Used for patching the SCSI ID in the SELECT instruction */
+#define script_patch_ID(script, symbol, value) \
+{ \
+	int i; \
+	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
+		__u32 val = (script)[A_##symbol##_used[i]]; \
+		val &= 0xff00ffff; \
+		val |= ((value) & 0xff) << 16; \
+		(script)[A_##symbol##_used[i]] = val; \
+		DEBUG((" script, patching ID field %s at %ld to 0x%lx\n", \
+		       #symbol, A_##symbol##_used[i], val)); \
+	} \
+}
+
+#define script_patch_16(script, symbol, value) \
+{ \
+	int i; \
+	for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
+		__u32 val = (script)[A_##symbol##_used[i]]; \
+		val &= 0xffff0000; \
+		val |= ((value) & 0xffff); \
+		(script)[A_##symbol##_used[i]] = val; \
+		DEBUG((" script, patching ID field %s at %ld to 0x%lx\n", \
+		       #symbol, A_##symbol##_used[i], val)); \
+	} \
+}
+
+
+#endif
Index: linux/2.4/drivers/scsi/NCR_D700.scr
diff -u /dev/null linux/2.4/drivers/scsi/NCR_D700.scr:1.1.2.12
--- /dev/null	Sun Apr 29 10:16:33 2001
+++ linux/2.4/drivers/scsi/NCR_D700.scr	Sat Apr 28 14:51:31 2001
@@ -0,0 +1,341 @@
+; Script for the NCR Dual 700 Card
+;
+; Copyright (C) 2001 James.Bottomley@HansenPartnership.com
+;
+; This script is designed to be modified for the particular command in
+; operation.  The particular variables pertaining to the commands are:
+;
+ABSOLUTE	Device_ID = 0		; ID of target for command
+ABSOLUTE	MessageCount = 0	; Number of bytes in message
+ABSOLUTE	MessageLocation = 0	; Addr of message
+ABSOLUTE	CommandCount = 0	; Number of bytes in command
+ABSOLUTE	CommandAddress = 0	; Addr of Command
+ABSOLUTE	StatusAddress = 0	; Addr to receive status return
+ABSOLUTE	ReceiveMsgAddress = 0	; Addr to receive msg
+;
+; This is the magic component for handling scatter-gather.  Each of the
+; SG components is preceeded by a script fragment which moves the
+; necessary amount of data and jumps to the next SG segment.  The final
+; SG segment jumps back to .  However, this address is the first SG script
+; segment.
+;
+ABSOLUTE	SGScriptStartAddress = 0
+
+; The following represent status interrupts we use 3 hex digits for
+; this: 0xPRS where 
+
+; P:
+ABSOLUTE	AFTER_SELECTION 	= 0x100
+ABSOLUTE	BEFORE_CMD 		= 0x200
+ABSOLUTE	AFTER_CMD 		= 0x300
+ABSOLUTE	AFTER_STATUS 		= 0x400
+ABSOLUTE	AFTER_DATA_IN		= 0x500
+ABSOLUTE	AFTER_DATA_OUT		= 0x600
+ABSOLUTE	DURING_DATA_IN		= 0x700
+
+; R:
+ABSOLUTE	NOT_MSG_OUT 		= 0x10
+ABSOLUTE	UNEXPECTED_PHASE 	= 0x20
+ABSOLUTE	NOT_MSG_IN 		= 0x30
+ABSOLUTE	UNEXPECTED_MSG		= 0x40
+ABSOLUTE	MSG_IN			= 0x50
+ABSOLUTE	SDTR_MSG_R		= 0x60
+ABSOLUTE	REJECT_MSG_R		= 0x70
+ABSOLUTE	DISCONNECT		= 0x80
+ABSOLUTE	MSG_OUT			= 0x90
+ABSOLUTE	WDTR_MSG_R		= 0xA0
+
+; S:
+ABSOLUTE	GOOD_STATUS 		= 0x1
+
+; Combinations, since the script assembler can't process |
+ABSOLUTE	NOT_MSG_OUT_AFTER_SELECTION = 0x110
+ABSOLUTE	UNEXPECTED_PHASE_BEFORE_CMD = 0x220
+ABSOLUTE	UNEXPECTED_PHASE_AFTER_CMD = 0x320
+ABSOLUTE	NOT_MSG_IN_AFTER_STATUS = 0x430
+ABSOLUTE	GOOD_STATUS_AFTER_STATUS = 0x401
+ABSOLUTE	UNEXPECTED_PHASE_AFTER_DATA_IN = 0x520
+ABSOLUTE	UNEXPECTED_PHASE_AFTER_DATA_OUT = 0x620
+ABSOLUTE	UNEXPECTED_MSG_BEFORE_CMD = 0x240
+ABSOLUTE	MSG_IN_BEFORE_CMD = 0x250
+ABSOLUTE	MSG_IN_AFTER_CMD = 0x350
+ABSOLUTE	SDTR_MSG_BEFORE_CMD = 0x260
+ABSOLUTE	REJECT_MSG_BEFORE_CMD = 0x270
+ABSOLUTE	DISCONNECT_AFTER_CMD = 0x380
+ABSOLUTE	SDTR_MSG_AFTER_CMD = 0x360
+ABSOLUTE	WDTR_MSG_AFTER_CMD = 0x3A0
+ABSOLUTE	DISCONNECT_AFTER_DATA = 0x580
+ABSOLUTE	MSG_IN_AFTER_DATA_IN = 0x550
+ABSOLUTE	MSG_IN_AFTER_DATA_OUT = 0x650
+ABSOLUTE	MSG_OUT_AFTER_DATA_IN = 0x590
+ABSOLUTE	DATA_IN_AFTER_DATA_IN = 0x5a0
+ABSOLUTE	MSG_IN_DURING_DATA_IN = 0x750
+ABSOLUTE	DISCONNECT_DURING_DATA = 0x780
+
+;
+; Other interrupt conditions
+; 
+ABSOLUTE	RESELECTED_DURING_SELECTION = 0x1000
+ABSOLUTE	RESELECTION_IDENTIFIED = 0x1003
+;
+; Fatal interrupt conditions.  If you add to this, also add to the
+; array of corresponding messages
+;
+ABSOLUTE	FATAL = 0x2000
+ABSOLUTE	UNEXPECTED_RESELECTION_MSG = 0x2000
+ABSOLUTE	FATAL_SEND_IDENTIFY_MESSAGE = 0x2001
+ABSOLUTE	FATAL_SEND_MSG = 0x2002
+ABSOLUTE	FATAL_SELECTED_AS_TARGET = 0x2003
+ABSOLUTE	FATAL_NOT_MSG_IN_AFTER_SELECTION = 0x2004
+
+
+;
+; SCSI Messages we interpret in the script
+; 
+ABSOLUTE	EXTENDED_MSG		= 0x01
+ABSOLUTE	SDTR_MSG		= 0x01
+ABSOLUTE	SAVE_DATA_PTRS_MSG	= 0x02
+ABSOLUTE	RESTORE_DATA_PTRS_MSG	= 0x03
+ABSOLUTE	WDTR_MSG		= 0x03
+ABSOLUTE	DISCONNECT_MSG		= 0x04
+ABSOLUTE	REJECT_MSG		= 0x07
+ABSOLUTE	IDENTIFY_MSG		= 0x80
+ABSOLUTE	IDENTIFY_MSG_MASK	= 0x7F
+
+; This is where the script begins
+
+ENTRY	StartUp
+
+StartUp:
+	SELECT	ATN Device_ID, Reselect
+	JUMP	Finish, WHEN STATUS
+	JUMP	SendIdentifyMsg, IF MSG_OUT
+	INT	NOT_MSG_OUT_AFTER_SELECTION
+
+Reselect:
+	WAIT	RESELECT SelectedAsTarget
+	INT	RESELECTED_DURING_SELECTION, WHEN MSG_IN
+	INT	FATAL_NOT_MSG_IN_AFTER_SELECTION
+
+	ENTRY	GetReselectionData
+GetReselectionData:
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	INT	UNEXPECTED_RESELECTION_MSG, IF NOT IDENTIFY_MSG, AND MASK IDENTIFY_MSG_MASK
+	INT	RESELECTION_IDENTIFIED
+	
+SelectedAsTarget:
+	INT	FATAL_SELECTED_AS_TARGET
+
+SendIdentifyMsg:
+	MOVE	MessageCount, MessageLocation, WHEN MSG_OUT
+	JUMP	SendCommand, WHEN NOT MSG_OUT
+; shouldn't be able to get here
+	INT	FATAL_SEND_IDENTIFY_MESSAGE
+
+IgnoreMsgBeforeCommand:
+	CLEAR	ACK
+	ENTRY	SendCommand
+SendCommand:
+	JUMP	Finish, WHEN STATUS
+	JUMP	MsgInBeforeCommand, IF MSG_IN
+	INT	UNEXPECTED_PHASE_BEFORE_CMD, IF NOT CMD
+	MOVE	CommandCount, CommandAddress, WHEN CMD
+ResumeSendCommand:
+	JUMP	Finish, WHEN STATUS
+	JUMP	MsgInAfterCmd, IF MSG_IN
+	JUMP	DataIn, IF DATA_IN
+	JUMP	DataOut, IF DATA_OUT
+	INT	UNEXPECTED_PHASE_AFTER_CMD
+
+IgnoreMsgDuringData:
+	CLEAR	ACK
+	; fall through to MsgInDuringData
+
+Entry MsgInDuringData
+MsgInDuringData:
+;
+; Could be we have nothing more to transfer
+;
+	JUMP	Finish, WHEN STATUS
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	JUMP	DisconnectDuringDataIn, IF DISCONNECT_MSG
+	JUMP	IgnoreMsgDuringData, IF SAVE_DATA_PTRS_MSG
+	JUMP	IgnoreMsgDuringData, IF RESTORE_DATA_PTRS_MSG
+	INT	MSG_IN_DURING_DATA_IN
+
+MsgInAfterCmd:
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	JUMP	DisconnectAfterCmd, IF DISCONNECT_MSG
+	JUMP	ExtendedMsgInAfterCmd, IF EXTENDED_MSG
+	JUMP	IgnoreMsgInAfterCmd, IF SAVE_DATA_PTRS_MSG
+	JUMP	IgnoreMsgInAfterCmd, IF RESTORE_DATA_PTRS_MSG
+	INT	MSG_IN_AFTER_CMD
+
+ExtendedMsgInAfterCmd:
+	CLEAR	ACK
+	MOVE	1, ReceiveMsgAddress + 1, WHEN MSG_IN
+	CLEAR	ACK
+	MOVE	1, ReceiveMsgAddress + 2, WHEN MSG_IN
+	JUMP	WDTRMsg, IF WDTR_MSG
+	JUMP	SDTRMsgAfterCmd, IF SDTR_MSG
+	INT	MSG_IN_AFTER_CMD
+
+WDTRMsg:
+	CLEAR	ACK
+; we're narrow, so we're going to reject this one
+	MOVE	1, ReceiveMsgAddress + 3, WHEN MSG_IN
+	INT	WDTR_MSG_AFTER_CMD
+	CALL	SendMsgOut
+	JUMP	ResumeSendCommand
+
+SDTRMsgAfterCmd:
+	CLEAR	ACK
+	MOVE	2, ReceiveMsgAddress + 3, WHEN MSG_IN
+	INT	SDTR_MSG_AFTER_CMD
+	CALL	SendMsgOut
+	JUMP	ResumeSendCommand
+
+
+IgnoreMsgInAfterCmd:
+	CLEAR	ACK
+	JUMP	ResumeSendCommand
+
+DisconnectAfterCmd:
+	CLEAR	ACK
+	WAIT	DISCONNECT
+	ENTRY	Disconnect1
+Disconnect1:
+	INT	DISCONNECT_AFTER_CMD
+	ENTRY	Disconnect2
+Disconnect2:
+; We return here after a reselection
+	CLEAR	ACK
+	JUMP	ResumeSendCommand
+
+; This is used in any phase to send a message.  The calling entity
+; must set up TEMP_REG with the address to jump to after sending
+; the message
+	ENTRY	SendMsgOut
+SendMsgOut:
+	SET	ATN
+	CLEAR	ACK
+	MOVE	MessageCount, MessageLocation, WHEN MSG_OUT
+	RETURN, WHEN NOT MSG_OUT
+	INT	FATAL_SEND_MSG
+	
+
+MsgInBeforeCommand:
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	JUMP	ExtendedMsgInBeforeCommand, IF EXTENDED_MSG
+	INT	REJECT_MSG_BEFORE_CMD, IF REJECT_MSG
+	JUMP	IgnoreMsgBeforeCommand, IF SAVE_DATA_PTRS_MSG
+	JUMP	IgnoreMsgBeforeCommand, IF RESTORE_DATA_PTRS_MSG
+	INT	MSG_IN_BEFORE_CMD
+
+ExtendedMsgInBeforeCommand:
+; This is a bit of a bugger.  The next byte tells us how long the message
+; is but we have no way of explaining this to the MOVE command without 
+; writing self modifying code, so we actually have to interpret the message
+; to get the length.
+	CLEAR	ACK
+	MOVE	1, ReceiveMsgAddress + 1, WHEN MSG_IN
+	CLEAR	ACK
+	MOVE	1, ReceiveMsgAddress + 2, WHEN MSG_IN
+	JUMP	SDTRMsg, IF SDTR_MSG
+	INT	UNEXPECTED_MSG_BEFORE_CMD
+
+SDTRMsg:
+	CLEAR	ACK
+	MOVE	2, ReceiveMsgAddress + 3, WHEN MSG_IN
+	INT	SDTR_MSG_BEFORE_CMD
+	CLEAR	ACK
+	JUMP	SendCommand
+	
+DataIn:
+	CALL	SGScriptStartAddress
+ResumeDataIn:
+	JUMP	Finish, WHEN STATUS
+	JUMP	MsgInAfterDataIn, IF MSG_IN
+	JUMP	DataInAfterDataIn, if DATA_IN
+	INT	MSG_OUT_AFTER_DATA_IN, if MSG_OUT
+	INT	UNEXPECTED_PHASE_AFTER_DATA_IN
+
+DataInAfterDataIn:
+	INT	DATA_IN_AFTER_DATA_IN
+	JUMP	ResumeDataIn
+
+DataOut:
+	CALL	SGScriptStartAddress
+ResumeDataOut:
+	JUMP	Finish, WHEN STATUS
+	JUMP	MsgInAfterDataOut, IF MSG_IN
+	INT	UNEXPECTED_PHASE_AFTER_DATA_OUT
+
+MsgInAfterDataIn:
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	JUMP	DisconnectAfterDataIn, IF DISCONNECT_MSG
+	JUMP	IgnoreMsgAfterData, IF SAVE_DATA_PTRS_MSG
+	JUMP	IgnoreMsgAfterData, IF RESTORE_DATA_PTRS_MSG
+	INT	MSG_IN_AFTER_DATA_IN
+
+DisconnectDuringDataIn:
+	CLEAR	ACK
+	WAIT	DISCONNECT
+	ENTRY	Disconnect3
+Disconnect3:
+	INT	DISCONNECT_DURING_DATA
+	ENTRY	Disconnect4
+Disconnect4:
+; we return here after a reselection
+	CLEAR	ACK
+	JUMP	ResumeSendCommand
+
+
+DisconnectAfterDataIn:
+	CLEAR	ACK
+	WAIT	DISCONNECT
+	ENTRY	Disconnect5
+Disconnect5:
+	INT	DISCONNECT_AFTER_DATA
+	ENTRY	Disconnect6
+Disconnect6:
+; we return here after a reselection
+	CLEAR	ACK
+	JUMP	ResumeDataIn
+
+MsgInAfterDataOut:
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	JUMP	DisconnectAfterDataOut, if DISCONNECT_MSG
+	JUMP	IgnoreMsgAfterData, IF SAVE_DATA_PTRS_MSG
+	JUMP	IgnoreMsgAfterData, IF RESTORE_DATA_PTRS_MSG
+	INT	MSG_IN_AFTER_DATA_OUT
+
+IgnoreMsgAfterData:
+	CLEAR	ACK
+; Data in and out do the same thing on resume, so pick one
+	JUMP	ResumeDataIn
+
+DisconnectAfterDataOut:
+	CLEAR	ACK
+	WAIT	DISCONNECT
+	ENTRY	Disconnect7
+Disconnect7:
+	INT	DISCONNECT_AFTER_DATA
+	ENTRY	Disconnect8
+Disconnect8:
+; we return here after a reselection
+	CLEAR	ACK
+	JUMP	ResumeDataOut
+
+Finish:
+	MOVE	1, StatusAddress, WHEN STATUS
+	INT	NOT_MSG_IN_AFTER_STATUS, WHEN NOT MSG_IN
+	MOVE	1, ReceiveMsgAddress, WHEN MSG_IN
+	CLEAR	ACK
+	WAIT	DISCONNECT
+	ENTRY	Finish1
+Finish1:
+	INT	GOOD_STATUS_AFTER_STATUS
+	ENTRY	Finish2
+Finish2:
+
Index: linux/2.4/include/asm-i386/hw_irq.h
diff -u linux/2.4/include/asm-i386/hw_irq.h:1.1.1.3 linux/2.4/include/asm-i386/hw_irq.h:1.1.1.3.2.1
--- linux/2.4/include/asm-i386/hw_irq.h:1.1.1.3	Sat Mar 31 15:44:14 2001
+++ linux/2.4/include/asm-i386/hw_irq.h	Sat Mar 31 16:41:03 2001
@@ -210,7 +210,7 @@
 	atomic_inc((atomic_t *)&prof_buffer[eip]);
 }
 
-#ifdef CONFIG_SMP /*more of this file should probably be ifdefed SMP */
+#if defined(CONFIG_SMP) && !defined(CONFIG_VOYAGER) /*more of this file should probably be ifdefed SMP */
 static inline void hw_resend_irq(struct hw_interrupt_type *h, unsigned int i) {
 	if (IO_APIC_IRQ(i))
 		send_IPI_self(IO_APIC_VECTOR(i));
Index: linux/2.4/include/asm-i386/smp.h
diff -u linux/2.4/include/asm-i386/smp.h:1.1.1.1 linux/2.4/include/asm-i386/smp.h:1.1.1.1.22.1
--- linux/2.4/include/asm-i386/smp.h:1.1.1.1	Fri Jul 28 10:42:51 2000
+++ linux/2.4/include/asm-i386/smp.h	Sat Mar 31 16:41:03 2001
@@ -6,6 +6,7 @@
  */
 #ifndef ASSEMBLY
 #include <linux/config.h>
+#include <linux/kernel.h>
 #include <linux/threads.h>
 #include <linux/ptrace.h>
 #endif
@@ -41,7 +42,23 @@
 extern void (*mtrr_hook) (void);
 extern void zap_low_mappings (void);
 
+#ifdef CONFIG_VOYAGER
 /*
+ * On voyager, all CPU's are labelled by their VIC ID which is not
+ * usually sequential, so we need to map from the contiguous (logical)
+ * list used in the scheduler to the physical list */
+extern volatile int __cpu_logical_map[NR_CPUS], __cpu_number_map[NR_CPUS];
+
+extern inline int cpu_logical_map(int cpu)
+{
+	return __cpu_logical_map[cpu];
+}
+extern inline int cpu_number_map(int cpu)
+{
+	return __cpu_number_map[cpu];
+}
+#else
+/*
  * On x86 all CPUs are mapped 1:1 to the APIC space.
  * This simplifies scheduling and IPI sending and
  * compresses data structures.
@@ -54,6 +71,7 @@
 {
 	return cpu;
 }
+#endif
 
 /*
  * Some lowlevel functions might want to know about
@@ -77,12 +95,13 @@
 
 #define smp_processor_id() (current->processor)
 
+#ifdef CONFIG_X86_LOCAL_APIC
 extern __inline int hard_smp_processor_id(void)
 {
 	/* we don't want to mark this access volatile - bad code generation */
 	return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID));
 }
-
+#endif
 #endif /* !ASSEMBLY */
 
 #define NO_PROC_ID		0xFF		/* No processor magic marker */
Index: linux/2.4/include/asm-i386/vic.h
diff -u /dev/null linux/2.4/include/asm-i386/vic.h:1.1.12.1
--- /dev/null	Sun Apr 29 10:17:04 2001
+++ linux/2.4/include/asm-i386/vic.h	Sat Mar 31 16:41:03 2001
@@ -0,0 +1,82 @@
+/* Copyright (C) 1999,2001
+ *
+ * Author: J.E.J.Bottomley@HansenPartnership.com
+ *
+ * Standard include definitions for the NCR Voyager Interrupt Controller */
+
+/* The eight CPI vectors.  To activate a CPI, you write a bit mask
+ * corresponding to the processor set to be interrupted into the
+ * relevant register.  That set of CPUs will then be interrupted with
+ * the CPI */
+static const int VIC_CPI_Registers[] =
+	{0xFC00, 0xFC01, 0xFC08, 0xFC09,
+	 0xFC10, 0xFC11, 0xFC18, 0xFC19 };
+
+#define VIC_PROC_WHO_AM_I		0xfc29
+#	define	QUAD_IDENTIFIER		0xC0
+#define QIC_EXTENDED_PROCESSOR_SELECT	0xFC72
+#define VIC_CPI_BASE_REGISTER		0xFC41
+#define VIC_PROCESSOR_ID		0xFC21
+#	define VIC_CPU_MASQUERADE_ENABLE 0x8
+
+#define VIC_CLAIM_REGISTER_0		0xFC38
+#define VIC_CLAIM_REGISTER_1		0xFC39
+#define VIC_REDIRECT_REGISTER_0		0xFC60
+#define VIC_REDIRECT_REGISTER_1		0xFC61
+#define VIC_PRIORITY_REGISTER		0xFC20
+
+#define VIC_PRIMARY_MC_BASE		0xFC48
+#define VIC_SECONDARY_MC_BASE		0xFC49
+
+#define QIC_PROCESSOR_ID		0xFC71
+#	define	QIC_CPUID_ENABLE	0x08
+
+#define QIC_VIC_CPI_BASE_REGISTER	0xFC79
+#define QIC_CPI_BASE_REGISTER		0xFC7A
+
+#define QIC_MASK_REGISTER0		0xFC80
+#define QIC_MASK_REGISTER1		0xFC81
+#	define QIC_BOOT_CPI_MASK	0xFE
+#	define QIC_CPI_ENABLE		0xC1
+
+#define QIC_INTERRUPT_CLEAR0		0xFC8A
+#define QIC_INTERRUPT_CLEAR1		0xFC8B
+
+/* this is where we place the CPI vectors */
+#define VIC_DEFAULT_CPI_BASE		0xC0
+/* this is where we place the QIC CPI vectors */
+#define QIC_DEFAULT_CPI_BASE		0xD0
+
+/* These define the CPIs we use in linux */
+#define VIC_CPI_LEVEL0			0
+#define VIC_CPI_LEVEL1			1
+/* now the fake CPIs */
+#define VIC_TIMER_CPI			2
+#define VIC_INVALIDATE_CPI		3
+#define VIC_RESCHEDULE_CPI		4
+#define VIC_ENABLE_IRQ_CPI		5
+#define VIC_CALL_FUNCTION_CPI		6
+
+/* Now the QIC CPIs:  Since we don't need the two initial levels,
+ * these are 2 less than the VIC CPIs */
+#define QIC_CPI_OFFSET			1
+#define QIC_TIMER_CPI			(VIC_TIMER_CPI - QIC_CPI_OFFSET)
+#define QIC_INVALIDATE_CPI		(VIC_INVALIDATE_CPI - QIC_CPI_OFFSET)
+#define QIC_RESCHEDULE_CPI		(VIC_RESCHEDULE_CPI - QIC_CPI_OFFSET)
+#define QIC_ENABLE_IRQ_CPI		(VIC_ENABLE_IRQ_CPI - QIC_CPI_OFFSET)
+#define QIC_CALL_FUNCTION_CPI		(VIC_CALL_FUNCTION_CPI - QIC_CPI_OFFSET)
+
+#define VIC_START_FAKE_CPI		VIC_TIMER_CPI
+#define VIC_END_FAKE_CPI		VIC_CALL_FUNCTION_CPI
+
+/* this is the SYS_INT CPI. */
+#define VIC_SYS_INT			8
+#define VIC_CMN_INT			15
+
+/* This is the boot CPI for alternate processors.  It gets overwritten
+ * by the above once the system has activated all available processors */
+#define VIC_CPU_BOOT_CPI		VIC_CPI_LEVEL0
+#define VIC_CPU_BOOT_ERRATA_CPI		(VIC_CPI_LEVEL0 + 8)
+#define VIC_BOOT_INTERRUPT_MASK		0xfe
+
+extern void smp_vic_timer_interrupt(struct pt_regs *regs);
Index: linux/2.4/include/asm-i386/voyager.h
diff -u /dev/null linux/2.4/include/asm-i386/voyager.h:1.1.12.1
--- /dev/null	Sun Apr 29 10:17:04 2001
+++ linux/2.4/include/asm-i386/voyager.h	Sat Mar 31 16:41:03 2001
@@ -0,0 +1,375 @@
+/* Copyright (C) 1999,2001
+ *
+ * Author: J.E.J.Bottomley@HansenPartnership.com
+ *
+ * Standard include definitions for the NCR Voyager system */
+
+#undef	VOYAGER_DEBUG
+#undef	VOYAGER_CAT_DEBUG
+
+#ifdef VOYAGER_DEBUG
+#define VDEBUG(x)	printk x
+#else
+#define VDEBUG(x)
+#endif
+
+/* There are three levels of voyager machine: 3,4 and 5. The rule is
+ * if it's less than 3435 it's a Level 3 except for a 3360 which is
+ * a level 4.  A 3435 or above is a Level 5 */
+#define VOYAGER_LEVEL5_AND_ABOVE	0x3435
+#define VOYAGER_LEVEL4			0x3360
+
+/* voyager ports in standard I/O space */
+#define VOYAGER_MC_SETUP	0x96
+
+
+#define	VOYAGER_CAT_CONFIG_PORT			0x97
+#	define VOYAGER_CAT_DESELECT		0xff
+#define VOYAGER_SSPB_RELOCATION_PORT		0x98
+
+/* Valid CAT controller commands */
+/* start instruction register cycle */
+#define VOYAGER_CAT_IRCYC			0x01
+/* start data register cycle */
+#define VOYAGER_CAT_DRCYC			0x02
+/* move to execute state */
+#define VOYAGER_CAT_RUN				0x0F
+/* end operation */
+#define VOYAGER_CAT_END				0x80
+/* hold in idle state */
+#define VOYAGER_CAT_HOLD			0x90
+/* single step an "intest" vector */
+#define VOYAGER_CAT_STEP			0xE0
+/* return cat controller to CLEMSON mode */
+#define VOYAGER_CAT_CLEMSON			0xFF
+
+/* the default cat command header */
+#define VOYAGER_CAT_HEADER			0x7F
+
+/* the range of possible CAT module ids in the system */
+#define VOYAGER_MIN_MODULE			0x10
+#define VOYAGER_MAX_MODULE			0x1f
+
+/* The voyager registers per asic */
+#define VOYAGER_ASIC_ID_REG			0x00
+#define VOYAGER_ASIC_TYPE_REG			0x01
+/* the sub address registers can be made auto incrementing on reads */
+#define VOYAGER_AUTO_INC_REG			0x02
+#	define VOYAGER_AUTO_INC			0x04
+#	define VOYAGER_NO_AUTO_INC		0xfb
+#define VOYAGER_SUBADDRDATA			0x03
+#define VOYAGER_SCANPATH			0x05
+#	define VOYAGER_CONNECT_ASIC		0x01
+#	define VOYAGER_DISCONNECT_ASIC		0xfe
+#define VOYAGER_SUBADDRLO			0x06
+#define VOYAGER_SUBADDRHI			0x07
+#define VOYAGER_SUBMODSELECT			0x08
+#define VOYAGER_SUBMODPRESENT			0x09
+
+#define VOYAGER_SUBADDR_LO			0xff
+#define VOYAGER_SUBADDR_HI			0xffff
+
+/* the maximum size of a scan path -- used to form instructions */
+#define VOYAGER_MAX_SCAN_PATH			0x100
+/* the biggest possible register size (in bytes) */
+#define VOYAGER_MAX_REG_SIZE			4
+
+/* Total number of possible modules (including submodules) */
+#define VOYAGER_MAX_MODULES			16
+/* Largest number of asics per module */
+#define VOYAGER_MAX_ASICS_PER_MODULE		7
+
+/* the CAT asic of each module is always the first one */
+#define VOYAGER_CAT_ID				0
+
+/* voyager instruction operations and registers */
+#define VOYAGER_READ_CONFIG			0x1
+#define VOYAGER_WRITE_CONFIG			0x2
+#define VOYAGER_BYPASS				0xff
+
+typedef struct voyager_asic 
+{
+	__u8	asic_addr;	/* ASIC address; Level 4 */
+	__u8	asic_type;      /* ASIC type */
+	__u8	asic_id;	/* ASIC id */
+	__u8	jtag_id[4];	/* JTAG id */
+	__u8	asic_location;	/* Location within scan path; start w/ 0 */
+	__u8	bit_location;	/* Location within bit stream; start w/ 0 */
+	__u8	ireg_length;	/* Instruction register length */
+	__u16	subaddr;	/* Amount of sub address space */
+	struct voyager_asic *next;	/* Next asic in linked list */
+} voyager_asic_t;
+
+typedef struct voyager_module {
+	__u8	module_addr;		/* Module address */
+	__u8	scan_path_connected;	/* Scan path connected */
+	__u16   ee_size;		/* Size of the EEPROM */
+	__u16   num_asics;		/* Number of Asics */
+	__u16   inst_bits;		/* Instruction bits in the scan path */
+	__u16   largest_reg;		/* Largest register in the scan path */
+	__u16   smallest_reg;		/* Smallest register in the scan path */
+	voyager_asic_t   *asic;		/* First ASIC in scan path (CAT_I) */
+	struct   voyager_module *submodule;	/* Submodule pointer */ 
+	struct   voyager_module *next;		/* Next module in linked list */
+} voyager_module_t;
+
+typedef struct voyager_eeprom_hdr {
+	 __u8  module_id[4] __attribute__((packed)); 
+	 __u8  version_id __attribute__((packed));
+	 __u8  config_id __attribute__((packed)); 
+	 __u16 boundry_id __attribute__((packed));	/* boundary scan id */
+	 __u16 ee_size __attribute__((packed));		/* size of EEPROM */
+	 __u8  assembly[11] __attribute__((packed));	/* assembly # */
+	 __u8  assembly_rev __attribute__((packed));	/* assembly rev */
+	 __u8  tracer[4] __attribute__((packed));	/* tracer number */
+	 __u16 assembly_cksum __attribute__((packed));	/* asm checksum */
+	 __u16 power_consump __attribute__((packed));	/* pwr requirements */
+	 __u16 num_asics __attribute__((packed));	/* number of asics */
+	 __u16 bist_time __attribute__((packed));	/* min. bist time */
+	 __u16 err_log_offset __attribute__((packed));	/* error log offset */
+	 __u16 scan_path_offset __attribute__((packed));/* scan path offset */
+	 __u16 cct_offset __attribute__((packed));
+	 __u16 log_length __attribute__((packed));	/* length of err log */
+	 __u16 xsum_end __attribute__((packed));	/* offset to end of
+							   checksum */
+	 __u8  reserved[4] __attribute__((packed));
+	 __u8  sflag __attribute__((packed));		/* starting sentinal */
+	 __u8  part_number[13] __attribute__((packed));	/* prom part number */
+	 __u8  version[10] __attribute__((packed));	/* version number */
+	 __u8  signature[8] __attribute__((packed));
+	 __u16 eeprom_chksum __attribute__((packed));
+	 __u32  data_stamp_offset __attribute__((packed));
+	 __u8  eflag  __attribute__((packed));		 /* ending sentinal */
+} voyager_eprom_hdr_t;
+
+
+
+#define VOYAGER_EPROM_SIZE_OFFSET   ((__u16)(&(((voyager_eprom_hdr_t *)0)->ee_size)))
+#define VOYAGER_XSUM_END_OFFSET		0x2a
+
+/* the following three definitions are for internal table layouts
+ * in the module EPROMs.  We really only care about the IDs and
+ * offsets */
+typedef struct voyager_sp_table {
+	__u8 asic_id __attribute__((packed));
+	__u8 bypass_flag __attribute__((packed));
+	__u16 asic_data_offset __attribute__((packed));
+	__u16 config_data_offset __attribute__((packed));
+} voyager_sp_table_t;
+
+typedef struct voyager_jtag_table {
+	__u8 icode[4] __attribute__((packed));
+	__u8 runbist[4] __attribute__((packed));
+	__u8 intest[4] __attribute__((packed));
+	__u8 samp_preld[4] __attribute__((packed));
+	__u8 ireg_len __attribute__((packed));
+} voyager_jtt_t;
+
+typedef struct voyager_asic_data_table {
+	__u8 jtag_id[4] __attribute__((packed));
+	__u16 length_bsr __attribute__((packed));
+	__u16 length_bist_reg __attribute__((packed));
+	__u32 bist_clk __attribute__((packed));
+	__u16 subaddr_bits __attribute__((packed));
+	__u16 seed_bits __attribute__((packed));
+	__u16 sig_bits __attribute__((packed));
+	__u16 jtag_offset __attribute__((packed));
+} voyager_at_t;
+
+/* Voyager Interrupt Controller (VIC) registers */
+
+/* Base to add to Cross Processor Interrupts (CPIs) when triggering
+ * the CPU IRQ line */
+/* register defines for the WCBICs (one per processor) */
+#define VOYAGER_WCBIC0	0x41		/* bus A node P1 processor 0 */
+#define VOYAGER_WCBIC1	0x49		/* bus A node P1 processor 1 */
+#define VOYAGER_WCBIC2	0x51		/* bus A node P2 processor 0 */
+#define VOYAGER_WCBIC3	0x59		/* bus A node P2 processor 1 */
+#define VOYAGER_WCBIC4	0x61		/* bus B node P1 processor 0 */
+#define VOYAGER_WCBIC5	0x69		/* bus B node P1 processor 1 */
+#define VOYAGER_WCBIC6	0x71		/* bus B node P2 processor 0 */
+#define VOYAGER_WCBIC7	0x79		/* bus B node P2 processor 1 */
+
+
+/* top of memory registers */
+#define VOYAGER_WCBIC_TOM_L	0x4
+#define VOYAGER_WCBIC_TOM_H	0x5
+
+/* register defines for Voyager Memory Contol (VMC) 
+ * these are present on L4 machines only */
+#define	VOYAGER_VMC1		0x81
+#define VOYAGER_VMC2		0x91
+#define VOYAGER_VMC3		0xa1
+#define VOYAGER_VMC4		0xb1
+
+/* VMC Ports */
+#define VOYAGER_VMC_MEMORY_SETUP	0x9
+#	define VMC_Interleaving		0x01
+#	define VMC_4Way			0x02
+#	define VMC_EvenCacheLines	0x04
+#	define VMC_HighLine		0x08
+#	define VMC_Start0_Enable	0x20
+#	define VMC_Start1_Enable	0x40
+#	define VMC_Vremap		0x80
+#define VOYAGER_VMC_BANK_DENSITY	0xa
+#	define	VMC_BANK_EMPTY		0
+#	define	VMC_BANK_4MB		1
+#	define	VMC_BANK_16MB		2
+#	define	VMC_BANK_64MB		3
+#	define	VMC_BANK0_MASK		0x03
+#	define	VMC_BANK1_MASK		0x0C
+#	define	VMC_BANK2_MASK		0x30
+#	define	VMC_BANK3_MASK		0xC0
+
+/* Magellan Memory Controller (MMC) defines - present on L5 */
+#define VOYAGER_MMC_ASIC_ID		1
+/* the two memory modules corresponding to memory cards in the system */
+#define VOYAGER_MMC_MEMORY0_MODULE	0x14
+#define VOYAGER_MMC_MEMORY1_MODULE	0x15
+/* the Magellan Memory Address (MMA) defines */
+#define VOYAGER_MMA_ASIC_ID		2
+
+/* Submodule number for the Quad Baseboard */
+#define VOYAGER_QUAD_BASEBOARD		1
+
+/* ASIC defines for the Quad Baseboard */
+#define VOYAGER_QUAD_QDATA0		1
+#define VOYAGER_QUAD_QDATA1		2
+#define VOYAGER_QUAD_QABC		3
+
+/* Useful areas in extended CMOS */
+#define VOYAGER_PROCESSOR_PRESENT_MASK	0x88a
+#define VOYAGER_MEMORY_CLICKMAP		0xa23
+
+/* SUS In Control bit - used to tell SUS that we don't need to be
+ * babysat anymore */
+#define VOYAGER_SUS_IN_CONTROL_PORT	0x3ff
+#	define VOYAGER_IN_CONTROL_FLAG	0x80
+
+
+struct voyager_bios_info {
+	__u8	len;
+	__u8	major;
+	__u8	minor;
+	__u8	debug;
+	__u8	num_classes;
+	__u8	class_1;
+	__u8	class_2;
+};
+
+/* The following structures and definitions are for the Kernel/SUS
+ * interface these are needed to find out how SUS initialised any Quad
+ * boards in the system */
+
+#define	NUMBER_OF_MC_BUSSES	2
+#define SLOTS_PER_MC_BUS	8
+#define MAX_CPUS                16      /* 16 way CPU system */
+#define MAX_PROCESSOR_BOARDS	4	/* 4 processor slot system */
+#define MAX_CACHE_LEVELS	4	/* # of cache levels supported */
+#define MAX_SHARED_CPUS		4	/* # of CPUs that can share a LARC */
+#define NUMBER_OF_POS_REGS	8
+
+typedef struct {
+	__u8	MC_Slot __attribute__((packed));
+	__u8	POS_Values[NUMBER_OF_POS_REGS] __attribute__((packed));
+} MC_SlotInformation_t;
+
+struct QuadDescription {
+	__u8  Type __attribute__((packed));	/* for type 0 (DYADIC or MONADIC) all fields
+                         * will be zero except for slot */
+	__u8 StructureVersion __attribute__((packed));
+	__u32 CPI_BaseAddress __attribute__((packed));
+	__u32  LARC_BankSize __attribute__((packed));	
+	__u32 LocalMemoryStateBits __attribute__((packed));
+	__u8  Slot __attribute__((packed)); /* Processor slots 1 - 4 */
+}; 
+
+struct ProcBoardInfo { 
+	__u8 Type __attribute__((packed));    
+	__u8 StructureVersion __attribute__((packed));
+	__u8 NumberOfBoards __attribute__((packed));
+	struct QuadDescription QuadData[MAX_PROCESSOR_BOARDS] __attribute__((packed));
+};
+
+struct CacheDescription {
+	__u8 Level __attribute__((packed));
+	__u32 TotalSize __attribute__((packed));
+	__u16 LineSize __attribute__((packed));
+	__u8  Associativity __attribute__((packed));
+	__u8  CacheType __attribute__((packed));
+	__u8  WriteType __attribute__((packed));
+	__u8  Number_CPUs_SharedBy __attribute__((packed));
+	__u8  Shared_CPUs_Hardware_IDs[MAX_SHARED_CPUS] __attribute__((packed));
+
+};
+
+struct CPU_Description {
+	__u8 CPU_HardwareId __attribute__((packed));
+	char *FRU_String __attribute__((packed));
+	__u8 NumberOfCacheLevels __attribute__((packed));
+	struct CacheDescription CacheLevelData[MAX_CACHE_LEVELS] __attribute__((packed));
+};
+
+struct CPU_Info {
+	__u8 Type __attribute__((packed));
+	__u8 StructureVersion __attribute__((packed));
+	__u8 NumberOf_CPUs __attribute__((packed));
+	struct CPU_Description CPU_Data[MAX_CPUS] __attribute__((packed));
+};
+
+
+/*
+ * This structure will be used by SUS and the OS.
+ * The assumption about this structure is that no blank space is
+ * packed in it by our friend the compiler.
+ */
+typedef struct {
+	__u8	Mailbox_SUS;		/* Written to by SUS to give commands/response to the OS */
+	__u8	Mailbox_OS;		/* Written to by the OS to give commands/response to SUS */
+	__u8	SUS_MailboxVersion;	/* Tells the OS which iteration of the interface SUS supports */
+	__u8	OS_MailboxVersion;	/* Tells SUS which iteration of the interface the OS supports */
+	__u32	OS_Flags;		/* Flags set by the OS as info for SUS */
+	__u32	SUS_Flags;		/* Flags set by SUS as info for the OS */
+	__u32	WatchDogPeriod;		/* Watchdog period (in seconds) which the DP uses to see if the OS is dead */
+	__u32	WatchDogCount;		/* Updated by the OS on every tic. */
+	__u32	MemoryFor_SUS_ErrorLog;	/* Flat 32 bit address which tells SUS where to stuff the SUS error log on a dump */
+	MC_SlotInformation_t  MC_SlotInfo[NUMBER_OF_MC_BUSSES*SLOTS_PER_MC_BUS];	/* Storage for MCA POS data */
+	/* All new SECOND_PASS_INTERFACE fields added from this point */
+        struct ProcBoardInfo    *BoardData;
+        struct CPU_Info         *CPU_Data;
+	/* All new fields must be added from this point */
+} Voyager_KernelSUS_Mbox_t;
+
+/* structure for finding the right memory address to send a QIC CPI to */
+struct voyager_qic_cpi {
+	/* Each cache line (32 bytes) can trigger a cpi.  The cpi
+	 * read/write may occur anywhere in the cache line---pick the
+	 * middle to be safe */
+	struct  {
+		__u32 pad1[3];
+		__u32 cpi;
+		__u32 pad2[4];
+	} qic_cpi[8];
+};
+
+/* Variables exported by voyager_smp */
+extern __u32 voyager_extended_vic_processors;
+extern __u32 voyager_quad_processors;
+extern struct voyager_qic_cpi *voyager_quad_cpi_addr[NR_CPUS];
+
+
+/* functions exported by the voyager and voyager_smp modules */
+
+extern int voyager_cat_readb(__u8 module, __u8 asic, int reg);
+extern void voyager_cat_init(void);
+extern void voyager_trap_init(void);
+extern void voyager_setup_irqs(void);
+extern int voyager_memory_detect(int region, __u32 *addr, __u32 *length);
+extern void voyager_smp_intr_init(void);
+extern __u8 voyager_extended_cmos_read(__u16 cmos_address);
+extern void voyager_dump(void);
+extern void voyager_smp_dump(void);
+extern void voyager_timer_interrupt(struct pt_regs *regs);
+extern void smp_local_timer_interrupt(struct pt_regs * regs);
+extern void voyager_power_off(void);
+extern void smp_voyager_power_off(void *dummy);
