diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/Documentation/Configure.help linux/Documentation/Configure.help
--- tmp/linux/Documentation/Configure.help	Mon Feb 25 20:28:49 2002
+++ linux/Documentation/Configure.help	Mon Feb 25 20:05:54 2002
@@ -4796,6 +4796,13 @@
   bits per pixel packed pixels on Mac. It supports variable font
   widths for low resolution screens.
 
+Permedia3 support (EXPERIMENTAL)
+CONFIG_FB_PM3
+  This is the frame buffer device driver for the 3DLabs Permedia3
+  chipset, used in Formac ProFormance III, 3DLabs Oxygen VX1 &
+  similar boards, 3DLabs Permedia3 Create!, Appian Jeronimo 2000
+  and maybe other boards.
+
 HGA monochrome support
 CONFIG_FBCON_HGA
   This is the low level frame buffer console driver for Hercules mono
@@ -6394,6 +6401,18 @@
   boards supported by this driver, and for further information
   on the use of this driver.
 
+SCSI tape drive support for Smart Array 5xxx
+CONFIG_CISS_SCSI_TAPE
+  When enabled (Y), this option allows SCSI tape drives and SCSI medium
+  changers (tape robots) to be accessed via a Compaq 5xxx array
+  controller.  (See Documentation/cciss.txt for more details.)
+
+  "SCSI support" and "SCSI tape support" must also be enabled for this
+  option to work.
+
+  When this option is disabled (N), the SCSI portion of the driver
+  is not compiled.
+
 QuickNet Internet LineJack/PhoneJack support
 CONFIG_PHONE_IXJ
   Say M if you have a telephony card manufactured by Quicknet
@@ -18943,8 +18962,11 @@
 
 Yamaha YMF7xx PCI audio (native mode)
 CONFIG_SOUND_YMFPCI
-  Support for Yamaha cards including the YMF711, YMF715, YMF718,
-  YMF719, YMF724, Waveforce 192XG, and Waveforce 192 Digital.
+  Support for Yamaha cards with the following chipsets: YMF724,
+  YMF724F, YMF740, YMF740C, YMF744, and YMF754.
+
+  Two common cards that use this type of chip are Waveforce 192XG,
+  and Waveforce 192 Digital.
 
 Yamaha PCI legacy ports support
 CONFIG_SOUND_YMFPCI_LEGACY
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/Documentation/cciss.txt linux/Documentation/cciss.txt
--- tmp/linux/Documentation/cciss.txt	Thu Oct 11 16:04:57 2001
+++ linux/Documentation/cciss.txt	Mon Feb 25 18:52:01 2002
@@ -100,7 +100,7 @@
 can be informed of changes to the virtual SCSI bus which the driver 
 presents to it in the usual way. For example: 
 
-	echo add-single-device 3 2 1 0 > /proc/scsi/scsi
+	echo scsi add-single-device 3 2 1 0 > /proc/scsi/scsi
  
 to add a device on controller 3, bus 2, target 1, lun 0.   Note that
 the driver makes an effort to preserve the devices positions
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/Documentation/filesystems/Locking linux/Documentation/filesystems/Locking
--- tmp/linux/Documentation/filesystems/Locking	Fri Dec 21 17:41:53 2001
+++ linux/Documentation/filesystems/Locking	Mon Feb 25 19:45:39 2002
@@ -156,7 +156,7 @@
 block_flushpage() instead.
 	->releasepage() is called when the kernel is about to try to drop the
 buffers from the page in preparation for freeing it.  It returns zero to
-indicate that the buffers are (or may be) freeable.  If ->flushpage is zero,
+indicate that the buffers are (or may be) freeable.  If ->releasepage is zero,
 the kernel assumes that the fs has no private interest in the buffers.
 
 	Note: currently almost all instances of address_space methods are
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/Documentation/filesystems/cramfs.txt linux/Documentation/filesystems/cramfs.txt
--- tmp/linux/Documentation/filesystems/cramfs.txt	Thu Jul 19 23:14:53 2001
+++ linux/Documentation/filesystems/cramfs.txt	Mon Feb 25 20:01:04 2002
@@ -10,7 +10,7 @@
 
 You can't write to a cramfs filesystem (making it compressible and
 compact also makes it _very_ hard to update on-the-fly), so you have to
-create the disk image with the "mkcramfs" utility in scripts/cramfs.
+create the disk image with the "mkcramfs" utility.
 
 
 Usage Notes
@@ -19,9 +19,7 @@
 File sizes are limited to less than 16MB.
 
 Maximum filesystem size is a little over 256MB.  (The last file on the
-filesystem is allowed to extend past 256MB.)  (Comments in mkcramfs.c
-suggest that ROM sizes may be limited to 64MB, though that's not a
-limitation in cramfs code.)
+filesystem is allowed to extend past 256MB.)
 
 Only the low 8 bits of gid are stored.  The current version of
 mkcramfs simply truncates to 8 bits, which is a potential security
@@ -48,18 +46,28 @@
 
 
 For /usr/share/magic
-------------------
+--------------------
 
-0	long	0x28cd3d45	Linux cramfs
->4	long	x		size %d
->8	long	x		flags 0x%x
->12	long	x		future 0x%x
+0	ulelong	0x28cd3d45	Linux cramfs offset 0
+>4	ulelong	x		size %d
+>8	ulelong	x		flags 0x%x
+>12	ulelong	x		future 0x%x
 >16	string	>\0		signature "%.16s"
->32	long	x		fsid.crc 0x%x
->36	long	x		fsid.edition %d
->40	long	x		fsid.blocks %d
->44	long	x		fsid.files %d
+>32	ulelong	x		fsid.crc 0x%x
+>36	ulelong	x		fsid.edition %d
+>40	ulelong	x		fsid.blocks %d
+>44	ulelong	x		fsid.files %d
 >48	string	>\0		name "%.16s"
+512	ulelong	0x28cd3d45	Linux cramfs offset 512
+>516	ulelong	x		size %d
+>520	ulelong	x		flags 0x%x
+>524	ulelong	x		future 0x%x
+>528	string	>\0		signature "%.16s"
+>544	ulelong	x		fsid.crc 0x%x
+>548	ulelong	x		fsid.edition %d
+>552	ulelong	x		fsid.blocks %d
+>556	ulelong	x		fsid.files %d
+>560	string	>\0		name "%.16s"
 
 
 Hacker Notes
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/Makefile linux/Makefile
--- tmp/linux/Makefile	Mon Feb 25 20:28:49 2002
+++ linux/Makefile	Mon Feb 25 20:30:48 2002
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
-SUBLEVEL = 18
-EXTRAVERSION =
+SUBLEVEL = 19
+EXTRAVERSION = pre1
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/alpha/Makefile linux/arch/alpha/Makefile
--- tmp/linux/arch/alpha/Makefile	Mon Dec  4 01:45:20 2000
+++ linux/arch/alpha/Makefile	Mon Feb 25 19:44:21 2002
@@ -40,20 +40,20 @@
     CFLAGS := $(CFLAGS) -mcpu=pca56
     mcpu_done := y
   endif
-  ifeq ($(mcpu_done)$(CONFIG_ALPHA_PYXIS),ny)
-    CFLAGS := $(CFLAGS) -mcpu=ev56
-    mcpu_done := y
-  endif
-  ifeq ($(mcpu_done)$(CONFIG_ALPHA_POLARIS),ny)
-    ifeq ($(have_mcpu_pca56),y)
-      CFLAGS := $(CFLAGS) -mcpu=pca56
-    else
-      CFLAGS := $(CFLAGS) -mcpu=ev56
-    endif
+  ifeq ($(mcpu_done)$(CONFIG_ALPHA_POLARIS)$(have_mcpu_pca56),nyy)
+    CFLAGS := $(CFLAGS) -mcpu=pca56
     mcpu_done := y
   endif
   ifeq ($(mcpu_done)$(CONFIG_ALPHA_EV4),ny)
     CFLAGS := $(CFLAGS) -mcpu=ev4
+    mcpu_done := y
+  endif
+  ifeq ($(mcpu_done)$(CONFIG_ALPHA_EV56),ny)
+    CFLAGS := $(CFLAGS) -mcpu=ev56
+    mcpu_done := y
+  endif
+  ifeq ($(mcpu_done)$(CONFIG_ALPHA_EV5),ny)
+    CFLAGS := $(CFLAGS) -mcpu=ev5
     mcpu_done := y
   endif
   ifeq ($(mcpu_done)$(CONFIG_ALPHA_EV67)$(have_mcpu_ev67),nyy)
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/alpha/config.in linux/arch/alpha/config.in
--- tmp/linux/arch/alpha/config.in	Tue Nov 20 23:49:31 2001
+++ linux/arch/alpha/config.in	Mon Feb 25 19:44:21 2002
@@ -102,19 +102,44 @@
 then
 	define_bool CONFIG_ALPHA_EB64P y
 fi
-if [ "$CONFIG_ALPHA_EB164" = "y" -o "$CONFIG_ALPHA_PC164" = "y" \
-	-o "$CONFIG_ALPHA_ALCOR" = "y" -o "$CONFIG_ALPHA_TAKARA" = "y" ]
+if [ "$CONFIG_ALPHA_ALCOR" = "y" ]
 then
 	define_bool CONFIG_ALPHA_EV5 y
 	define_bool CONFIG_ALPHA_CIA y
+	bool 'EV56 CPU (speed >= 366MHz)?' CONFIG_ALPHA_EV56
 fi
-if [ "$CONFIG_ALPHA_MIKASA" = "y" -o "$CONFIG_ALPHA_NORITAKE" = "y" ]
+if [ "$CONFIG_ALPHA_EB164" = "y" ]
+then
+	define_bool CONFIG_ALPHA_EV5 y
+	define_bool CONFIG_ALPHA_CIA y
+fi
+if [ "$CONFIG_ALPHA_PC164" = "y" -o "$CONFIG_ALPHA_TAKARA" = "y" ]
+then
+	define_bool CONFIG_ALPHA_EV5 y
+	define_bool CONFIG_ALPHA_EV56 y
+	define_bool CONFIG_ALPHA_CIA y
+fi
+if [ "$CONFIG_ALPHA_MIKASA" = "y" ]
 then
 	bool 'EV5 CPU daughtercard (model 5/xxx)?' CONFIG_ALPHA_PRIMO
 	if [ "$CONFIG_ALPHA_PRIMO" = "y" ]
 	then
 		define_bool CONFIG_ALPHA_EV5 y
 		define_bool CONFIG_ALPHA_CIA y
+		bool 'EV56 CPU (speed >= 333MHz)?' CONFIG_ALPHA_EV56
+	else
+		define_bool CONFIG_ALPHA_EV4 y
+		define_bool CONFIG_ALPHA_APECS y
+	fi
+fi
+if [ "$CONFIG_ALPHA_NORITAKE" = "y" ]
+then
+	bool 'EV5 CPU (model 5/xxx)?' CONFIG_ALPHA_PRIMO
+	if [ "$CONFIG_ALPHA_PRIMO" = "y" ]
+	then
+		define_bool CONFIG_ALPHA_EV5 y
+		define_bool CONFIG_ALPHA_CIA y
+		bool 'EV56 CPU (speed >= 333MHz)?' CONFIG_ALPHA_EV56
 	else
 		define_bool CONFIG_ALPHA_EV4 y
 		define_bool CONFIG_ALPHA_APECS y
@@ -135,6 +160,7 @@
 	-o "$CONFIG_ALPHA_SX164" = "y" -o "$CONFIG_ALPHA_RUFFIAN" = "y" ]
 then
 	define_bool CONFIG_ALPHA_EV5 y
+	define_bool CONFIG_ALPHA_EV56 y
 	define_bool CONFIG_ALPHA_CIA y
 	define_bool CONFIG_ALPHA_PYXIS y
 fi
@@ -159,10 +185,12 @@
 then
 	define_bool CONFIG_ALPHA_EV5 y
 	define_bool CONFIG_ALPHA_MCPCIA y
+	bool 'EV56 CPU (speed >= 400MHz)?' CONFIG_ALPHA_EV56
 fi
 if [ "$CONFIG_ALPHA_RX164" = "y" ]
 then
 	define_bool CONFIG_ALPHA_EV5 y
+	define_bool CONFIG_ALPHA_EV56 y
 	define_bool CONFIG_ALPHA_POLARIS y
 fi
 if [ "$CONFIG_ALPHA_JENSEN" = "y" ]
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/alpha/kernel/pci_iommu.c linux/arch/alpha/kernel/pci_iommu.c
--- tmp/linux/arch/alpha/kernel/pci_iommu.c	Mon Feb 25 20:28:49 2002
+++ linux/arch/alpha/kernel/pci_iommu.c	Mon Feb 25 19:44:21 2002
@@ -217,9 +217,14 @@
 	}
 
 	/* If the machine doesn't define a pci_tbi routine, we have to
-	   assume it doesn't support sg mapping.  */
+	   assume it doesn't support sg mapping, and, since we tried to
+	   use direct_map above, it now must be considered an error. */
 	if (! alpha_mv.mv_pci_tbi) {
-		printk(KERN_WARNING "pci_map_single failed: no hw sg\n");
+		static int been_here = 0; /* Only print the message once. */
+		if (!been_here) {
+		    printk(KERN_WARNING "pci_map_single: no HW sg\n");
+		    been_here = 1;
+		}
 		return 0;
 	}
 		
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/alpha/kernel/smp.c linux/arch/alpha/kernel/smp.c
--- tmp/linux/arch/alpha/kernel/smp.c	Fri Dec 21 17:41:53 2001
+++ linux/arch/alpha/kernel/smp.c	Mon Feb 25 19:44:21 2002
@@ -184,9 +184,23 @@
 	 */
 	wait_boot_cpu_to_stop(cpuid);
 	mb();
+ try_again:
 	calibrate_delay();
 
 	smp_store_cpu_info(cpuid);
+
+	{
+#define LPJ(c) ((long)cpu_data[c].loops_per_jiffy)
+	  static int tries = 3;
+	  long diff = LPJ(boot_cpuid) - LPJ(cpuid);
+	  if (diff < 0) diff = -diff;
+				
+	  if (diff > LPJ(boot_cpuid)/10 && --tries) {
+	    printk("Bogus BogoMIPS for cpu %d - retrying...\n", cpuid);
+	    goto try_again;
+	  }
+	}
+
 	/*
 	 * Allow master to continue only after we written
 	 * the loops_per_jiffy.
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/i386/kernel/dmi_scan.c linux/arch/i386/kernel/dmi_scan.c
--- tmp/linux/arch/i386/kernel/dmi_scan.c	Mon Feb 25 20:28:49 2002
+++ linux/arch/i386/kernel/dmi_scan.c	Mon Feb 25 20:13:14 2002
@@ -493,6 +493,11 @@
 			MATCH(DMI_PRODUCT_NAME, "Delhi3"),
 			NO_MATCH, NO_MATCH,
 			} },
+	{ apm_is_horked, "Fujitsu-Siemens", { /* APM crashes */
+			MATCH(DMI_BIOS_VENDOR, "hoenix/FUJITSU SIEMENS"),
+			MATCH(DMI_BIOS_VERSION, "Version1.01"),
+			NO_MATCH, NO_MATCH,
+			} },
 	{ apm_is_horked, "Sharp PC-PJ/AX", { /* APM crashes */
 			MATCH(DMI_SYS_VENDOR, "SHARP"),
 			MATCH(DMI_PRODUCT_NAME, "PC-PJ/AX"),
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/i386/kernel/i386_ksyms.c linux/arch/i386/kernel/i386_ksyms.c
--- tmp/linux/arch/i386/kernel/i386_ksyms.c	Mon Feb 25 20:28:49 2002
+++ linux/arch/i386/kernel/i386_ksyms.c	Mon Feb 25 20:04:47 2002
@@ -73,6 +73,7 @@
 EXPORT_SYMBOL(get_cmos_time);
 EXPORT_SYMBOL(apm_info);
 EXPORT_SYMBOL(gdt);
+EXPORT_SYMBOL(empty_zero_page);
 
 #ifdef CONFIG_DEBUG_IOVIRT
 EXPORT_SYMBOL(__io_virt_debug);
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/sparc64/kernel/pci.c linux/arch/sparc64/kernel/pci.c
--- tmp/linux/arch/sparc64/kernel/pci.c	Thu Oct 11 06:42:46 2001
+++ linux/arch/sparc64/kernel/pci.c	Mon Feb 25 19:45:08 2002
@@ -1,4 +1,4 @@
-/* $Id: pci.c,v 1.36 2001/10/06 00:38:25 davem Exp $
+/* $Id: pci.c,v 1.36.2.4 2002/02/10 15:06:48 ecd Exp $
  * pci.c: UltraSparc PCI controller support.
  *
  * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
@@ -418,7 +418,7 @@
 				  enum pci_mmap_state mmap_state)
 {
 	unsigned long user_offset = vma->vm_pgoff << PAGE_SHIFT;
-	unsigned long user32 = user_offset & 0xffffffffUL;
+	unsigned long user32 = user_offset & pci_memspace_mask;
 	unsigned long largest_base, this_base, addr32;
 	int i;
 
@@ -448,7 +448,7 @@
 
 		this_base = rp->start;
 
-		addr32 = (this_base & PAGE_MASK) & 0xffffffffUL;
+		addr32 = (this_base & PAGE_MASK) & pci_memspace_mask;
 
 		if (mmap_state == pci_mmap_io)
 			addr32 &= 0xffffff;
@@ -464,7 +464,7 @@
 	if (mmap_state == pci_mmap_io)
 		vma->vm_pgoff = (((largest_base & ~0xffffffUL) | user32) >> PAGE_SHIFT);
 	else
-		vma->vm_pgoff = (((largest_base & ~0xffffffffUL) | user32) >> PAGE_SHIFT);
+		vma->vm_pgoff = (((largest_base & ~(pci_memspace_mask)) | user32) >> PAGE_SHIFT);
 
 	return 0;
 }
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/arch/sparc64/kernel/sys_sparc32.c linux/arch/sparc64/kernel/sys_sparc32.c
--- tmp/linux/arch/sparc64/kernel/sys_sparc32.c	Sun Oct 21 17:36:54 2001
+++ linux/arch/sparc64/kernel/sys_sparc32.c	Mon Feb 25 19:45:08 2002
@@ -1,4 +1,4 @@
-/* $Id: sys_sparc32.c,v 1.182 2001/10/18 09:06:36 davem Exp $
+/* $Id: sys_sparc32.c,v 1.182.2.1 2002/02/20 08:49:24 davem Exp $
  * sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
  *
  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
@@ -49,6 +49,7 @@
 #include <linux/in.h>
 #include <linux/icmpv6.h>
 #include <linux/sysctl.h>
+#include <linux/dnotify.h>
 
 #include <asm/types.h>
 #include <asm/ipc.h>
@@ -1066,16 +1067,20 @@
 	/* First get the "struct iovec" from user memory and
 	 * verify all the pointers
 	 */
+	retval = 0;
 	if (!count)
-		return 0;
+		goto out_nofree;
+	retval = -EFAULT;
 	if (verify_area(VERIFY_READ, vector, sizeof(struct iovec32)*count))
-		return -EFAULT;
+		goto out_nofree;
+	retval = -EINVAL;
 	if (count > UIO_MAXIOV)
-		return -EINVAL;
+		goto out_nofree;
 	if (count > UIO_FASTIOV) {
+		retval = -ENOMEM;
 		iov = kmalloc(count*sizeof(struct iovec), GFP_KERNEL);
 		if (!iov)
-			return -ENOMEM;
+			goto out_nofree;
 	}
 
 	tot_len = 0;
@@ -1135,6 +1140,11 @@
 out:
 	if (iov != iovstack)
 		kfree(iov);
+out_nofree:
+	/* VERIFY_WRITE actually means a read, as we write to user space */
+	if ((retval + (type == VERIFY_WRITE)) > 0)
+		dnotify_parent(file->f_dentry,
+			(type == VERIFY_WRITE) ? DN_MODIFY : DN_ACCESS);
 
 	return retval;
 }
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/Config.in linux/drivers/block/Config.in
--- tmp/linux/drivers/block/Config.in	Fri Sep 14 21:04:06 2001
+++ linux/drivers/block/Config.in	Mon Feb 25 18:52:01 2002
@@ -35,6 +35,7 @@
 fi
 dep_tristate 'Compaq SMART2 support' CONFIG_BLK_CPQ_DA $CONFIG_PCI
 dep_tristate 'Compaq Smart Array 5xxx support' CONFIG_BLK_CPQ_CISS_DA $CONFIG_PCI 
+dep_mbool '       SCSI tape drive support for Smart Array 5xxx' CONFIG_CISS_SCSI_TAPE $CONFIG_BLK_CPQ_CISS_DA $CONFIG_SCSI
 dep_tristate 'Mylex DAC960/DAC1100 PCI RAID Controller support' CONFIG_BLK_DEV_DAC960 $CONFIG_PCI
 
 tristate 'Loopback device support' CONFIG_BLK_DEV_LOOP
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/cciss.c linux/drivers/block/cciss.c
--- tmp/linux/drivers/block/cciss.c	Fri Dec 21 17:41:53 2001
+++ linux/drivers/block/cciss.c	Mon Feb 25 18:52:01 2002
@@ -126,6 +126,8 @@
 	revalidate:		frevalidate_logvol,
 };
 
+#include "cciss_scsi.c"		/* For SCSI tape support */
+
 /*
  * Report information about this controller.
  */
@@ -162,6 +164,7 @@
 		h->maxQsinceinit, h->max_outstanding, h->maxSG);
 
         pos += size; len += size;
+	cciss_proc_tape_report(ctlr, buffer, &pos, &len);
 	for(i=0; i<h->num_luns; i++) {
                 drv = &h->drv[i];
                 size = sprintf(buffer+len, "cciss/c%dd%d: blksz=%d nr_blocks=%d\n",
@@ -181,20 +184,53 @@
         return len;
 }
 
+static int
+cciss_proc_write(struct file *file, const char *buffer,
+			unsigned long count, void *data)
+{
+	unsigned char cmd[80];
+	int len;
+#ifdef CONFIG_CISS_SCSI_TAPE
+	ctlr_info_t *h = (ctlr_info_t *) data;
+	int rc;
+#endif
+
+	if (count > sizeof(cmd)-1) return -EINVAL;
+	if (copy_from_user(cmd, buffer, count)) return -EFAULT;
+	cmd[count] = '\0';
+	len = strlen(cmd);	// safe???
+	if (cmd[len-1] == '\n')
+		cmd[--len] = '\0';
+#	ifdef CONFIG_CISS_SCSI_TAPE
+		if (strcmp("engage scsi", cmd)==0) {
+			rc = cciss_engage_scsi(h->ctlr);
+			if (rc != 0) return -rc;
+			return count;
+		}
+		/* might be nice to have "disengage" too, but it's not
+		   safely possible. (only 1 module use count, lock issues.) */
+#	endif
+	return -EINVAL;
+}
+
 /*
  * Get us a file in /proc/cciss that says something about each controller.
  * Create /proc/cciss if it doesn't exist yet.
  */
 static void __init cciss_procinit(int i)
 {
-        if (proc_cciss == NULL) {
-                proc_cciss = proc_mkdir("cciss", proc_root_driver);
-                if (!proc_cciss) 
+	struct proc_dir_entry *pde;
+
+	if (proc_cciss == NULL) {
+		proc_cciss = proc_mkdir("cciss", proc_root_driver);
+		if (!proc_cciss)
 			return;
-        }
+	}
 
-        create_proc_read_entry(hba[i]->devname, 0, proc_cciss,
-        		cciss_proc_get_info, hba[i]);
+	pde = create_proc_read_entry(hba[i]->devname,
+		S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH,
+		proc_cciss, cciss_proc_get_info, hba[i]);
+	pde->write_proc = cciss_proc_write;
 }
 #endif /* CONFIG_PROC_FS */
 
@@ -849,9 +885,12 @@
 	int	ctlr,
 	void	*buff,
 	size_t	size,
-	unsigned int use_unit_num,
+	unsigned int use_unit_num, /* 0: address the controller,
+				      1: address logical volume log_unit,
+				      2: periph device address is scsi3addr */
 	unsigned int log_unit,
-	__u8	page_code )
+	__u8	page_code,
+	unsigned char *scsi3addr)
 {
 	CommandList_struct *c;
 	int i;
@@ -885,15 +924,23 @@
 				to controller so It's a physical command
 				mode = 0 target = 0.
 				So we have nothing to write. 
-				Otherwise 
-				mode = 1  target = LUNID
+				otherwise, if use_unit_num == 1,
+				mode = 1(volume set addressing) target = LUNID
+				otherwise, if use_unit_num == 2,
+				mode = 0(periph dev addr) target = scsi3addr
 			*/
-			if(use_unit_num != 0)
+			if(use_unit_num == 1)
 			{
 				c->Header.LUN.LogDev.VolId=
                                 	hba[ctlr]->drv[log_unit].LunID;
                         	c->Header.LUN.LogDev.Mode = 1;
 			}
+			else if (use_unit_num == 2)
+			{
+				memcpy(c->Header.LUN.LunAddrBytes,scsi3addr,8);
+				c->Header.LUN.LogDev.Mode = 0; // phys dev addr
+			}
+
 			/* are we trying to read a vital product page */
 			if(page_code != 0)
 			{
@@ -909,6 +956,7 @@
 			c->Request.CDB[4] = size  & 0xFF;  
 		break;
 		case CISS_REPORT_LOG:
+		case CISS_REPORT_PHYS:
                         /* Talking to controller so It's a physical command
                                 mode = 00 target = 0.
                                 So we have nothing to write.
@@ -918,7 +966,7 @@
                         c->Request.Type.Attribute = ATTR_SIMPLE; 
                         c->Request.Type.Direction = XFER_READ; // Read
                         c->Request.Timeout = 0; // Don't time out
-                        c->Request.CDB[0] = CISS_REPORT_LOG;
+			c->Request.CDB[0] = cmd;
                         c->Request.CDB[6] = (size >> 24) & 0xFF;  //MSB
                         c->Request.CDB[7] = (size >> 16) & 0xFF;
                         c->Request.CDB[8] = (size >> 8) & 0xFF;
@@ -996,6 +1044,7 @@
 				ignore it 
 			*/
 			if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
+			     (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
 			     (c->Request.CDB[0] == CISS_INQUIRY)) &&
 				((c->err_info->CommandStatus == 
 					CMD_DATA_OVERRUN) || 
@@ -1443,6 +1492,11 @@
 				} else if (c->cmd_type == CMD_IOCTL_PEND) {
 					c->cmd_type = CMD_IOCTL_DONE;
 				}
+#				ifdef CONFIG_CISS_SCSI_TAPE
+				else if (c->cmd_type == CMD_SCSI) {
+					complete_scsi_command(c, 0, a1);
+				}
+#				endif
 				continue;
 			}
 		}
@@ -1678,7 +1732,7 @@
         }
 	/* Get the firmware version */ 
 	return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff, 
-		sizeof(InquiryData_struct), 0, 0 ,0 );
+		sizeof(InquiryData_struct), 0, 0 ,0, NULL);
 	if (return_code == IO_OK)
 	{
 		hba[cntl_num]->firm_ver[0] = inq_buff->data_byte[32];
@@ -1692,7 +1746,7 @@
 	}
 	/* Get the number of logical volumes */ 
 	return_code = sendcmd(CISS_REPORT_LOG, cntl_num, ld_buff, 
-			sizeof(ReportLunData_struct), 0, 0, 0 );
+			sizeof(ReportLunData_struct), 0, 0, 0, NULL);
 
 	if( return_code == IO_OK)
 	{
@@ -1738,7 +1792,7 @@
 
 	  	memset(size_buff, 0, sizeof(ReadCapdata_struct));
 	  	return_code = sendcmd(CCISS_READ_CAPACITY, cntl_num, size_buff, 
-				sizeof( ReadCapdata_struct), 1, i, 0 );
+				sizeof( ReadCapdata_struct), 1, i, 0, NULL);
 	  	if (return_code == IO_OK)
 		{
 			total_size = (0xff & 
@@ -1770,7 +1824,7 @@
 		/* Execute the command to read the disk geometry */
 		memset(inq_buff, 0, sizeof(InquiryData_struct));
 		return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
-                	sizeof(InquiryData_struct), 1, i ,0xC1 );
+			sizeof(InquiryData_struct), 1, i, 0xC1, NULL );
 	  	if (return_code == IO_OK)
 		{
 			if(inq_buff->data_byte[8] == 0xFF)
@@ -1935,6 +1989,8 @@
 
 	cciss_getgeometry(i);
 
+	cciss_find_non_disk_devices(i);	/* find our tape drives, if any */
+
 	/* Turn the interrupts on so we can service requests */
 	hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
 
@@ -1975,6 +2031,8 @@
 			MAX_PART, &cciss_fops, 
 			hba[i]->drv[j].nr_blocks);
 
+	cciss_register_scsi(i, 1);  /* hook ourself into SCSI subsystem */
+
 	return(1);
 }
 
@@ -2001,6 +2059,7 @@
 	free_irq(hba[i]->intr, hba[i]);
 	pci_set_drvdata(pdev, NULL);
 	iounmap((void*)hba[i]->vaddr);
+	cciss_unregister_scsi(i);  /* unhook from SCSI subsystem */
 	unregister_blkdev(MAJOR_NR+i, hba[i]->devname);
 	remove_proc_entry(hba[i]->devname, proc_cciss);	
 	
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/cciss.h linux/drivers/block/cciss.h
--- tmp/linux/drivers/block/cciss.h	Tue May 22 17:23:16 2001
+++ linux/drivers/block/cciss.h	Mon Feb 25 18:52:01 2002
@@ -88,6 +88,9 @@
 	int              sizes[256];
 	int              blocksizes[256];
 	int              hardsizes[256];
+#ifdef CONFIG_CISS_SCSI_TAPE
+	void *scsi_ctlr; /* ptr to structure containing scsi related stuff */
+#endif
 };
 
 /*  Defining the diffent access_menthods */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/cciss_cmd.h linux/drivers/block/cciss_cmd.h
--- tmp/linux/drivers/block/cciss_cmd.h	Sat Nov  3 01:45:42 2001
+++ linux/drivers/block/cciss_cmd.h	Mon Feb 25 18:52:01 2002
@@ -89,6 +89,7 @@
 //STRUCTURES
 //###########################################################################
 #define CISS_MAX_LUN	16	
+#define CISS_MAX_PHYS_LUN	1024
 // SCSI-3 Cmmands 
 
 #pragma pack(1)	
@@ -101,6 +102,7 @@
 } InquiryData_struct;
 
 #define CISS_REPORT_LOG 0xc2    /* Report Logical LUNs */
+#define CISS_REPORT_PHYS 0xc3   /* Report Physical LUNs */
 // Data returned
 typedef struct _ReportLUNdata_struct
 {
@@ -215,6 +217,9 @@
 #define CMD_RWREQ       0x00
 #define CMD_IOCTL_PEND  0x01
 #define CMD_IOCTL_DONE  0x02
+#define CMD_SCSI	0x03
+#define CMD_MSG_DONE	0x04
+#define CMD_MSG_TIMEOUT 0x05
 
 typedef struct _CommandList_struct {
   CommandListHeader_struct Header;
@@ -229,6 +234,9 @@
   struct _CommandList_struct *prev;
   struct _CommandList_struct *next;
   struct request *	   rq;
+#ifdef CONFIG_CISS_SCSI_TAPE
+  void * scsi_cmd;
+#endif
 } CommandList_struct;
 
 //Configuration Table Structure
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/cciss_scsi.c linux/drivers/block/cciss_scsi.c
--- tmp/linux/drivers/block/cciss_scsi.c	Thu Jan  1 00:00:00 1970
+++ linux/drivers/block/cciss_scsi.c	Mon Feb 25 18:53:39 2002
@@ -0,0 +1,1607 @@
+/*
+ *    Disk Array driver for Compaq SA53xx Controllers, SCSI Tape module
+ *    Copyright 2001 Compaq Computer Corporation
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *    NON INFRINGEMENT.  See the GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *    Questions/Comments/Bugfixes to arrays@compaq.com
+ *
+ *    Author: Stephen M. Cameron
+ */
+#ifdef CONFIG_CISS_SCSI_TAPE
+
+/* Here we have code to present the driver as a scsi driver
+   as it is simultaneously presented as a block driver.  The
+   reason for doing this is to allow access to SCSI tape drives
+   through the array controller.  Note in particular, neither
+   physical nor logical disks are presented through the scsi layer. */
+
+#include "../scsi/scsi.h"
+#include "../scsi/hosts.h"
+#include <asm/atomic.h>
+#include <linux/timer.h>
+
+#include "cciss_scsi.h"
+
+/* some prototypes... */
+static int sendcmd(
+	__u8	cmd,
+	int	ctlr,
+	void	*buff,
+	size_t	size,
+	unsigned int use_unit_num, /* 0: address the controller,
+				      1: address logical volume log_unit,
+				      2: address is in scsi3addr */
+	unsigned int log_unit,
+	__u8	page_code,
+	unsigned char *scsi3addr );
+
+
+int __init cciss_scsi_detect(Scsi_Host_Template *tpnt);
+int cciss_scsi_release(struct Scsi_Host *sh);
+const char *cciss_scsi_info(struct Scsi_Host *sa);
+
+int cciss_scsi_proc_info(
+		char *buffer, /* data buffer */
+		char **start, 	   /* where data in buffer starts */
+		off_t offset,	   /* offset from start of imaginary file */
+		int length, 	   /* length of data in buffer */
+		int hostnum, 	   /* which host adapter (always zero for me) */
+		int func);	   /* 0 == read, 1 == write */
+
+int cciss_scsi_queue_command (Scsi_Cmnd *cmd, void (* done)(Scsi_Cmnd *));
+#if 0
+int cciss_scsi_abort(Scsi_Cmnd *cmd);
+#if defined SCSI_RESET_SYNCHRONOUS && defined SCSI_RESET_ASYNCHRONOUS
+int cciss_scsi_reset(Scsi_Cmnd *cmd, unsigned int reset_flags);
+#else
+int cciss_scsi_reset(Scsi_Cmnd *cmd);
+#endif
+#endif
+
+static struct cciss_scsi_hba_t ccissscsi[MAX_CTLR] = {
+	{ name: "cciss0", ndevices: 0 },
+	{ name: "cciss1", ndevices: 0 },
+	{ name: "cciss2", ndevices: 0 },
+	{ name: "cciss3", ndevices: 0 },
+	{ name: "cciss4", ndevices: 0 },
+	{ name: "cciss5", ndevices: 0 },
+	{ name: "cciss6", ndevices: 0 },
+	{ name: "cciss7", ndevices: 0 },
+};
+
+/* We need one Scsi_Host_Template *per controller* instead of
+   the usual one Scsi_Host_Template per controller *type*. This
+   is so PCI hot plug could have a remote possibility of still
+   working even with the SCSI system.  It's so
+   scsi_unregister_module will differentiate the controllers.
+   When register_scsi_module is called, each host template is
+   customized (name change) in cciss_register_scsi()
+   (that's called from cciss.c:cciss_init_one()) */
+
+static
+Scsi_Host_Template driver_template[MAX_CTLR] =
+{
+	CCISS_SCSI, CCISS_SCSI, CCISS_SCSI, CCISS_SCSI,
+	CCISS_SCSI, CCISS_SCSI, CCISS_SCSI, CCISS_SCSI,
+};
+
+#pragma pack(1)
+struct cciss_scsi_cmd_stack_elem_t {
+	CommandList_struct cmd;
+	ErrorInfo_struct Err;
+	__u32 busaddr; // 32 bits always, must fit through cmd register.
+};
+
+#pragma pack()
+
+#define CMD_STACK_SIZE (SCSI_CCISS_CAN_QUEUE * \
+		CCISS_MAX_SCSI_DEVS_PER_HBA + 2)
+			// plus two for init time usage
+
+#pragma pack(1)
+struct cciss_scsi_cmd_stack_t {
+	struct cciss_scsi_cmd_stack_elem_t *pool;
+	struct cciss_scsi_cmd_stack_elem_t *elem[CMD_STACK_SIZE];
+	dma_addr_t cmd_pool_handle;
+	int top;
+};
+#pragma pack()
+
+struct cciss_scsi_adapter_data_t {
+	struct Scsi_Host *scsi_host;
+	struct cciss_scsi_cmd_stack_t cmd_stack;
+	int registered;
+	spinlock_t lock; // to protect ccissscsi[ctlr];
+};
+#if 1
+#define CPQ_TAPE_LOCK(ctlr, flags) spin_lock_irqsave( \
+	&(((struct cciss_scsi_adapter_data_t *) \
+	hba[ctlr]->scsi_ctlr)->lock), flags);
+#define CPQ_TAPE_UNLOCK(ctlr, flags) spin_unlock_irqrestore( \
+	&(((struct cciss_scsi_adapter_data_t *) \
+	hba[ctlr]->scsi_ctlr)->lock), flags);
+#else
+#define CPQ_TAPE_LOCK(x,y)
+#define CPQ_TAPE_UNLOCK(x,y)
+#endif
+
+static CommandList_struct *
+scsi_cmd_alloc(ctlr_info_t *h)
+{
+	/* assume only one process in here at a time, locking done by caller. */
+
+	/* take the top memory chunk off the stack and return it, if any. */
+	struct cciss_scsi_cmd_stack_elem_t *c;
+	struct cciss_scsi_adapter_data_t *sa;
+	struct cciss_scsi_cmd_stack_t *stk;
+	u64bit temp64;
+
+	sa = (struct cciss_scsi_adapter_data_t *) h->scsi_ctlr;
+	stk = &sa->cmd_stack;
+
+	if (stk->top < 0)
+		return NULL;
+	c = stk->elem[stk->top];
+	memset(&c->cmd, 0, sizeof(c->cmd));
+	memset(&c->Err, 0, sizeof(c->Err));
+	/* set physical addr of cmd and addr of scsi parameters */
+	c->cmd.busaddr = c->busaddr;
+
+	temp64.val = (__u64) (c->busaddr + sizeof(CommandList_struct));
+	stk->top--;
+	c->cmd.ErrDesc.Addr.lower = temp64.val32.lower;
+	c->cmd.ErrDesc.Addr.upper = temp64.val32.upper;
+	c->cmd.ErrDesc.Len = sizeof(ErrorInfo_struct);
+
+	c->cmd.ctlr = h->ctlr;
+	c->cmd.err_info = &c->Err;
+
+	return (CommandList_struct *) c;
+}
+
+static void
+scsi_cmd_free(ctlr_info_t *h, CommandList_struct *cmd)
+{
+	/* assume only one process in here at a time, locking done by caller. */
+	/* drop the free memory chunk on top of the stack. */
+
+	struct cciss_scsi_adapter_data_t *sa;
+	struct cciss_scsi_cmd_stack_t *stk;
+
+	sa = (struct cciss_scsi_adapter_data_t *) h->scsi_ctlr;
+	stk = &sa->cmd_stack;
+	if (stk->top >= CMD_STACK_SIZE) {
+		printk("cciss: scsi_cmd_free called too many times.\n");
+		BUG();
+	}
+	stk->top++;
+	stk->elem[stk->top] = (struct cciss_scsi_cmd_stack_elem_t *) cmd;
+}
+
+static int
+scsi_cmd_stack_setup(int ctlr)
+{
+	int i;
+	struct cciss_scsi_adapter_data_t *sa;
+	struct cciss_scsi_cmd_stack_t *stk;
+	size_t size;
+
+	sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
+	stk = &sa->cmd_stack;
+	size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE;
+
+	// We use NULL as first arg to pci_alloc_consistent so we can be
+	// sure that we get addresses that will fit through the 32 bit
+	// command register, (our DMA mask says we can do 64 bit DMA, which
+	// we can, just not for commands.)
+
+	stk->pool = (struct cciss_scsi_cmd_stack_elem_t *)
+		pci_alloc_consistent(NULL, size, &stk->cmd_pool_handle);
+
+	if (stk->pool == NULL) {
+		printk("stk->pool is null\n");
+		return -1;
+	}
+
+	for (i=0; i<CMD_STACK_SIZE; i++) {
+		stk->elem[i] = &stk->pool[i];
+		stk->elem[i]->busaddr = (__u32) (stk->cmd_pool_handle +
+			(sizeof(struct cciss_scsi_cmd_stack_elem_t) * i));
+	}
+	stk->top = CMD_STACK_SIZE-1;
+	return 0;
+}
+
+static void
+scsi_cmd_stack_free(int ctlr)
+{
+	struct cciss_scsi_adapter_data_t *sa;
+	struct cciss_scsi_cmd_stack_t *stk;
+	size_t size;
+
+	sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
+	stk = &sa->cmd_stack;
+	if (stk->top != CMD_STACK_SIZE-1) {
+		printk( "cciss: %d scsi commands are still outstanding.\n",
+			CMD_STACK_SIZE - stk->top);
+		// BUG();
+		printk("WE HAVE A BUG HERE!!! stk=0x%08x\n",
+			(unsigned int) stk);
+	}
+	size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE;
+
+	// About NULL, see note above in scsi_cmd_stack_setup()
+	pci_free_consistent(NULL, size, stk->pool, stk->cmd_pool_handle);
+	stk->pool = NULL;
+}
+
+/* scsi_device_types comes from scsi.h */
+#define DEVICETYPE(n) (n<0 || n>MAX_SCSI_DEVICE_CODE) ? \
+	"Unknown" : scsi_device_types[n]
+
+#if 0
+static int xmargin=8;
+static int amargin=60;
+
+static void
+print_bytes (unsigned char *c, int len, int hex, int ascii)
+{
+
+	int i;
+	unsigned char *x;
+
+	if (hex)
+	{
+		x = c;
+		for (i=0;i<len;i++)
+		{
+			if ((i % xmargin) == 0 && i>0) printk("\n");
+			if ((i % xmargin) == 0) printk("0x%04x:", i);
+			printk(" %02x", *x);
+			x++;
+		}
+		printk("\n");
+	}
+	if (ascii)
+	{
+		x = c;
+		for (i=0;i<len;i++)
+		{
+			if ((i % amargin) == 0 && i>0) printk("\n");
+			if ((i % amargin) == 0) printk("0x%04x:", i);
+			if (*x > 26 && *x < 128) printk("%c", *x);
+			else printk(".");
+			x++;
+		}
+		printk("\n");
+	}
+}
+
+static void
+print_cmd(CommandList_struct *cp)
+{
+	printk("queue:%d\n", cp->Header.ReplyQueue);
+	printk("sglist:%d\n", cp->Header.SGList);
+	printk("sgtot:%d\n", cp->Header.SGTotal);
+	printk("Tag:0x%08x/0x%08x\n", cp->Header.Tag.upper,
+			cp->Header.Tag.lower);
+	printk("LUN:0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
+		cp->Header.LUN.LunAddrBytes[0],
+		cp->Header.LUN.LunAddrBytes[1],
+		cp->Header.LUN.LunAddrBytes[2],
+		cp->Header.LUN.LunAddrBytes[3],
+		cp->Header.LUN.LunAddrBytes[4],
+		cp->Header.LUN.LunAddrBytes[5],
+		cp->Header.LUN.LunAddrBytes[6],
+		cp->Header.LUN.LunAddrBytes[7]);
+	printk("CDBLen:%d\n", cp->Request.CDBLen);
+	printk("Type:%d\n",cp->Request.Type.Type);
+	printk("Attr:%d\n",cp->Request.Type.Attribute);
+	printk(" Dir:%d\n",cp->Request.Type.Direction);
+	printk("Timeout:%d\n",cp->Request.Timeout);
+	printk( "CDB: %02x %02x %02x %02x %02x %02x %02x %02x"
+		" %02x %02x %02x %02x %02x %02x %02x %02x\n",
+		cp->Request.CDB[0], cp->Request.CDB[1],
+		cp->Request.CDB[2], cp->Request.CDB[3],
+		cp->Request.CDB[4], cp->Request.CDB[5],
+		cp->Request.CDB[6], cp->Request.CDB[7],
+		cp->Request.CDB[8], cp->Request.CDB[9],
+		cp->Request.CDB[10], cp->Request.CDB[11],
+		cp->Request.CDB[12], cp->Request.CDB[13],
+		cp->Request.CDB[14], cp->Request.CDB[15]),
+	printk("edesc.Addr: 0x%08x/0%08x, Len  = %d\n",
+		cp->ErrDesc.Addr.upper, cp->ErrDesc.Addr.lower,
+			cp->ErrDesc.Len);
+	printk("sgs..........Errorinfo:\n");
+	printk("scsistatus:%d\n", cp->err_info->ScsiStatus);
+	printk("senselen:%d\n", cp->err_info->SenseLen);
+	printk("cmd status:%d\n", cp->err_info->CommandStatus);
+	printk("resid cnt:%d\n", cp->err_info->ResidualCnt);
+	printk("offense size:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_size);
+	printk("offense byte:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_num);
+	printk("offense value:%d\n", cp->err_info->MoreErrInfo.Invalid_Cmd.offense_value);
+
+}
+
+#endif
+
+static int
+find_bus_target_lun(int ctlr, int *bus, int *target, int *lun)
+{
+	/* finds an unused bus, target, lun for a new device */
+	/* assumes hba[ctlr]->scsi_ctlr->lock is held */
+	int i, found=0;
+	unsigned char target_taken[CCISS_MAX_SCSI_DEVS_PER_HBA];
+
+	memset(&target_taken[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA);
+
+#	if SELF_SCSI_ID >= 0
+		target_taken[SELF_SCSI_ID] = 1;
+#	endif
+	for (i=0;i<ccissscsi[ctlr].ndevices;i++)
+		target_taken[ccissscsi[ctlr].dev[i].target] = 1;
+
+	for (i=0;i<CCISS_MAX_SCSI_DEVS_PER_HBA;i++) {
+		if (!target_taken[i]) {
+			*bus = 0; *target=i; *lun = 0; found=1;
+			break;
+		}
+	}
+	return (!found);
+}
+
+static int
+cciss_scsi_add_entry(int ctlr, int hostno,
+		unsigned char *scsi3addr, int devtype)
+{
+	/* assumes hba[ctlr]->scsi_ctlr->lock is held */
+	int n = ccissscsi[ctlr].ndevices;
+	struct cciss_scsi_dev_t *sd;
+
+	if (n >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
+		printk("cciss%d: Too many devices, "
+			"some will be inaccessible.\n", ctlr);
+		return -1;
+	}
+	sd = &ccissscsi[ctlr].dev[n];
+	if (find_bus_target_lun(ctlr, &sd->bus, &sd->target, &sd->lun) != 0)
+		return -1;
+	memcpy(&sd->scsi3addr[0], scsi3addr, 8);
+	sd->devtype = devtype;
+	ccissscsi[ctlr].ndevices++;
+
+	/* initially, (before registering with scsi layer) we don't
+	   know our hostno and we don't want to print anything first
+	   time anyway (the scsi layer's inquiries will show that info) */
+	if (hostno != -1)
+		printk("cciss%d: %s device c%db%dt%dl%d added.\n",
+			ctlr, DEVICETYPE(sd->devtype), hostno,
+			sd->bus, sd->target, sd->lun);
+	return 0;
+}
+
+static void
+cciss_scsi_remove_entry(int ctlr, int hostno, int entry)
+{
+	/* assumes hba[ctlr]->scsi_ctlr->lock is held */
+	int i;
+	struct cciss_scsi_dev_t sd;
+
+	if (entry < 0 || entry >= CCISS_MAX_SCSI_DEVS_PER_HBA) return;
+	sd = ccissscsi[ctlr].dev[entry];
+	for (i=entry;i<ccissscsi[ctlr].ndevices-1;i++)
+		ccissscsi[ctlr].dev[i] = ccissscsi[ctlr].dev[i+1];
+	ccissscsi[ctlr].ndevices--;
+	printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
+		ctlr, DEVICETYPE(sd.devtype), hostno,
+			sd.bus, sd.target, sd.lun);
+}
+
+
+#define SCSI3ADDR_EQ(a,b) ( \
+	(a)[7] == (b)[7] && \
+	(a)[6] == (b)[6] && \
+	(a)[5] == (b)[5] && \
+	(a)[4] == (b)[4] && \
+	(a)[3] == (b)[3] && \
+	(a)[2] == (b)[2] && \
+	(a)[1] == (b)[1] && \
+	(a)[0] == (b)[0])
+
+static int
+adjust_cciss_scsi_table(int ctlr, int hostno,
+	struct cciss_scsi_dev_t sd[], int nsds)
+{
+	/* sd contains scsi3 addresses and devtypes, but
+	   bus target and lun are not filled in.  This funciton
+	   takes what's in sd to be the current and adjusts
+	   ccissscsi[] to be in line with what's in sd. */
+
+	int i,j, found, changes=0;
+	struct cciss_scsi_dev_t *csd;
+	unsigned long flags;
+
+	CPQ_TAPE_LOCK(ctlr, flags);
+
+	/* find any devices in ccissscsi[] that are not in
+	   sd[] and remove them from ccissscsi[] */
+
+	i = 0;
+	while(i<ccissscsi[ctlr].ndevices) {
+		csd = &ccissscsi[ctlr].dev[i];
+		found=0;
+		for (j=0;j<nsds;j++) {
+			if (SCSI3ADDR_EQ(sd[j].scsi3addr,
+				csd->scsi3addr)) {
+				if (sd[j].devtype == csd->devtype)
+					found=2;
+				else
+					found=1;
+				break;
+			}
+		}
+
+		if (found == 0) { /* device no longer present. */
+			changes++;
+			/* printk("cciss%d: %s device c%db%dt%dl%d removed.\n",
+				ctlr, DEVICETYPE(csd->devtype), hostno,
+					csd->bus, csd->target, csd->lun); */
+			cciss_scsi_remove_entry(ctlr, hostno, i);
+			/* note, i not incremented */
+		}
+		else if (found == 1) { /* device is different kind */
+			changes++;
+			printk("cciss%d: device c%db%dt%dl%d type changed "
+				"(device type now %s).\n",
+				ctlr, hostno, csd->bus, csd->target, csd->lun,
+					DEVICETYPE(csd->devtype));
+			csd->devtype = sd[j].devtype;
+			i++;	/* so just move along. */
+		} else 		/* device is same as it ever was, */
+			i++;	/* so just move along. */
+	}
+
+	/* Now, make sure every device listed in sd[] is also
+ 	   listed in ccissscsi[], adding them if they aren't found */
+
+	for (i=0;i<nsds;i++) {
+		found=0;
+		for (j=0;j<ccissscsi[ctlr].ndevices;j++) {
+			csd = &ccissscsi[ctlr].dev[j];
+			if (SCSI3ADDR_EQ(sd[i].scsi3addr,
+				csd->scsi3addr)) {
+				if (sd[i].devtype == csd->devtype)
+					found=2;	/* found device */
+				else
+					found=1; 	/* found a bug. */
+				break;
+			}
+		}
+		if (!found) {
+			changes++;
+			if (cciss_scsi_add_entry(ctlr, hostno,
+				&sd[i].scsi3addr[0], sd[i].devtype) != 0)
+				break;
+		} else if (found == 1) {
+			/* should never happen... */
+			changes++;
+			printk("cciss%d: device unexpectedly changed type\n",
+				ctlr);
+			/* but if it does happen, we just ignore that device */
+		}
+	}
+	CPQ_TAPE_UNLOCK(ctlr, flags);
+
+	if (!changes)
+		printk("cciss%d: No device changes detected.\n", ctlr);
+
+	return 0;
+}
+
+static int
+lookup_scsi3addr(int ctlr, int bus, int target, int lun, char *scsi3addr)
+{
+	int i;
+	struct cciss_scsi_dev_t *sd;
+	unsigned long flags;
+
+	CPQ_TAPE_LOCK(ctlr, flags);
+	for (i=0;i<ccissscsi[ctlr].ndevices;i++) {
+		sd = &ccissscsi[ctlr].dev[i];
+		if (sd->bus == bus &&
+		    sd->target == target &&
+		    sd->lun == lun) {
+			memcpy(scsi3addr, &sd->scsi3addr[0], 8);
+			CPQ_TAPE_UNLOCK(ctlr, flags);
+			return 0;
+		}
+	}
+	CPQ_TAPE_UNLOCK(ctlr, flags);
+	return -1;
+}
+
+
+static void
+cciss_find_non_disk_devices(int cntl_num)
+{
+	ReportLunData_struct *ld_buff;
+	InquiryData_struct *inq_buff;
+	int return_code;
+	int i;
+	int listlength = 0;
+	int num_luns;
+	unsigned char scsi3addr[8];
+	unsigned long flags;
+	int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8;
+
+	hba[cntl_num]->scsi_ctlr = (void *)
+		kmalloc(sizeof(struct cciss_scsi_adapter_data_t),
+			GFP_KERNEL);
+	if (hba[cntl_num]->scsi_ctlr == NULL)
+		return;
+
+	((struct cciss_scsi_adapter_data_t *)
+		hba[cntl_num]->scsi_ctlr)->scsi_host = NULL;
+	((struct cciss_scsi_adapter_data_t *)
+		hba[cntl_num]->scsi_ctlr)->lock = SPIN_LOCK_UNLOCKED;
+	((struct cciss_scsi_adapter_data_t *)
+		hba[cntl_num]->scsi_ctlr)->registered = 0;
+
+	if (scsi_cmd_stack_setup(cntl_num) != 0) {
+		printk("Trouble, returned non-zero!\n");
+		return;
+	}
+
+	ld_buff = kmalloc(reportlunsize, GFP_KERNEL);
+	if (ld_buff == NULL) {
+		printk(KERN_ERR "cciss: out of memory\n");
+		return;
+	}
+	memset(ld_buff, 0, sizeof(ReportLunData_struct));
+	inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
+	if (inq_buff == NULL) {
+		printk(KERN_ERR "cciss: out of memory\n");
+		kfree(ld_buff);
+		return;
+	}
+
+	/* Get the physical luns */
+	return_code = sendcmd(CISS_REPORT_PHYS, cntl_num, ld_buff,
+			reportlunsize, 0, 0, 0, NULL );
+
+	if( return_code == IO_OK) {
+		unsigned char *c = &ld_buff->LUNListLength[0];
+		listlength = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
+	}
+	else {  /* getting report of physical luns failed */
+		printk(KERN_WARNING "cciss: report physical luns"
+			" command failed\n");
+		listlength = 0;
+	}
+
+	CPQ_TAPE_LOCK(cntl_num, flags);
+	ccissscsi[cntl_num].ndevices = 0;
+	num_luns = listlength / 8; // 8 bytes pre entry
+	/* printk("Found %d LUNs\n", num_luns); */
+
+	if (num_luns > CISS_MAX_PHYS_LUN)
+	{
+		printk(KERN_WARNING
+			"cciss: Maximum physical LUNs (%d) exceeded.  "
+			"%d LUNs ignored.\n", CISS_MAX_PHYS_LUN,
+			num_luns - CISS_MAX_PHYS_LUN);
+		num_luns = CISS_MAX_PHYS_LUN;
+	}
+
+	for(i=0; i<num_luns; i++) {
+		/* Execute an inquiry to figure the device type */
+		memset(inq_buff, 0, sizeof(InquiryData_struct));
+		memcpy(scsi3addr, ld_buff->LUN[i], 8); /* ugly... */
+		return_code = sendcmd(CISS_INQUIRY, cntl_num, inq_buff,
+			sizeof(InquiryData_struct), 2, 0 ,0, scsi3addr );
+	  	if (return_code == IO_OK) {
+			if(inq_buff->data_byte[8] == 0xFF)
+			{
+			   printk(KERN_WARNING "cciss: inquiry failed\n");
+			} else {
+			   int devtype;
+
+			   /* printk("Inquiry...\n");
+			   print_bytes((unsigned char *) inq_buff, 36, 1, 1); */
+			   devtype = (inq_buff->data_byte[0] & 0x1f);
+
+			   switch (devtype)
+			   {
+			    case 0x01: /* sequential access, (tape) */
+			    case 0x08: /* medium changer */
+					  /* this is the only kind of dev */
+					  /* we want to expose here. */
+				if (cciss_scsi_add_entry(cntl_num, -1,
+					(unsigned char *) ld_buff->LUN[i],
+					devtype) != 0)
+						i=num_luns; // leave loop
+				break;
+			    default:
+				break;
+			   }
+
+			}
+		}
+		else printk("cciss: inquiry failed.\n");
+	}
+#if 0
+	for (i=0;i<ccissscsi[cntl_num].ndevices;i++)
+		printk("Tape device presented at c%db%dt%dl%d\n",
+			cntl_num, // <-- this is wrong
+			ccissscsi[cntl_num].dev[i].bus,
+			ccissscsi[cntl_num].dev[i].target,
+			ccissscsi[cntl_num].dev[i].lun);
+#endif
+	CPQ_TAPE_UNLOCK(cntl_num, flags);
+	kfree(ld_buff);
+	kfree(inq_buff);
+	return;
+}
+
+static void
+complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
+{
+	Scsi_Cmnd *cmd;
+	ctlr_info_t *ctlr;
+	u64bit addr64;
+	ErrorInfo_struct *ei;
+
+	ei = cp->err_info;
+
+	/* First, see if it was a message rather than a command */
+	if (cp->Request.Type.Type == TYPE_MSG)  {
+		cp->cmd_type = CMD_MSG_DONE;
+		return;
+	}
+
+	/* we stored ptr to scsi cmd in the buffer head pointer */
+	cmd = (Scsi_Cmnd *) cp->scsi_cmd;
+	ctlr = hba[cp->ctlr];
+
+	/* undo the DMA mappings */
+
+	if (cmd->use_sg) {
+		pci_unmap_sg(ctlr->pdev,
+			cmd->buffer, cmd->use_sg,
+				scsi_to_pci_dma_dir(cmd->sc_data_direction));
+	}
+	else if (cmd->request_bufflen) {
+		addr64.val32.lower = cp->SG[0].Addr.lower;
+		addr64.val32.upper = cp->SG[0].Addr.upper;
+		pci_unmap_single(ctlr->pdev, (dma_addr_t) addr64.val,
+			cmd->request_bufflen,
+				scsi_to_pci_dma_dir(cmd->sc_data_direction));
+	}
+
+	cmd->result = (DID_OK << 16); 		/* host byte */
+	cmd->result |= (COMMAND_COMPLETE << 8);	/* msg byte */
+	/* cmd->result |= (GOOD < 1); */		/* status byte */
+
+	cmd->result |= (ei->ScsiStatus);
+	/* printk("Scsistatus is 0x%02x\n", ei->ScsiStatus);  */
+
+	/* copy the sense data whether we need to or not. */
+
+	memcpy(cmd->sense_buffer, ei->SenseInfo,
+		ei->SenseLen > SCSI_SENSE_BUFFERSIZE ?
+			SCSI_SENSE_BUFFERSIZE :
+			ei->SenseLen);
+	cmd->resid = ei->ResidualCnt;
+
+	if(ei->CommandStatus != 0)
+	{ /* an error has occurred */
+		switch(ei->CommandStatus)
+		{
+			case CMD_TARGET_STATUS:
+				/* Pass it up to the upper layers... */
+				if( ei->ScsiStatus)
+					cmd->result |= (ei->ScsiStatus < 1);
+				else {  /* scsi status is zero??? How??? */
+
+	/* Ordinarily, this case should never happen, but there is a bug
+	   in some released firmware revisions that allows it to happen
+	   if, for example, a 4100 backplane loses power and the tape
+	   drive is in it.  We assume that it's a fatal error of some
+	   kind because we can't show that it wasn't. We will make it
+	   look like selection timeout since that is the most common
+	   reason for this to occur, and it's severe enough. */
+
+					cmd->result = DID_NO_CONNECT << 16;
+				}
+			break;
+			case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
+			break;
+			case CMD_DATA_OVERRUN:
+				printk(KERN_WARNING "cciss: cp %p has"
+					" completed with data overrun "
+					"reported\n", cp);
+			break;
+			case CMD_INVALID: {
+				/* print_bytes(cp, sizeof(*cp), 1, 0);
+				print_cmd(cp); */
+     /* We get CMD_INVALID if you address a non-existent tape drive instead
+	of a selection timeout (no response).  You will see this if you yank
+	out a tape drive, then try to access it. This is kind of a shame
+	because it means that any other CMD_INVALID (e.g. driver bug) will
+	get interpreted as a missing target. */
+				cmd->result = DID_NO_CONNECT << 16;
+				}
+			break;
+			case CMD_PROTOCOL_ERR:
+				printk(KERN_WARNING "cciss: cp %p has "
+					"protocol error \n", cp);
+			break;
+			case CMD_HARDWARE_ERR:
+				cmd->result = DID_ERROR << 16;
+				printk(KERN_WARNING "cciss: cp %p had "
+					" hardware error\n", cp);
+			break;
+			case CMD_CONNECTION_LOST:
+				cmd->result = DID_ERROR << 16;
+				printk(KERN_WARNING "cciss: cp %p had "
+					"connection lost\n", cp);
+			break;
+			case CMD_ABORTED:
+				cmd->result = DID_ABORT << 16;
+				printk(KERN_WARNING "cciss: cp %p was "
+					"aborted\n", cp);
+			break;
+			case CMD_ABORT_FAILED:
+				cmd->result = DID_ERROR << 16;
+				printk(KERN_WARNING "cciss: cp %p reports "
+					"abort failed\n", cp);
+			break;
+			case CMD_UNSOLICITED_ABORT:
+				cmd->result = DID_ABORT << 16;
+				printk(KERN_WARNING "cciss: cp %p aborted "
+					"do to an unsolicited abort\n", cp);
+			break;
+			case CMD_TIMEOUT:
+				cmd->result = DID_TIME_OUT << 16;
+				printk(KERN_WARNING "cciss: cp %p timedout\n",
+					cp);
+			break;
+			default:
+				cmd->result = DID_ERROR << 16;
+				printk(KERN_WARNING "cciss: cp %p returned "
+					"unknown status %x\n", cp,
+						ei->CommandStatus);
+		}
+	}
+	cmd->scsi_done(cmd);
+	scsi_cmd_free(ctlr, cp);
+}
+
+/* cciss_scsi_detect is called from the scsi mid layer.
+   The scsi mid layer (scsi_register_module) is
+   called from cciss.c:cciss_init_one().  */
+
+int __init
+cciss_scsi_detect(Scsi_Host_Template *tpnt)
+{
+	int i;
+	struct Scsi_Host *sh;
+
+	/* Tell the kernel we want to be a SCSI driver... */
+	sh = scsi_register(tpnt, sizeof(struct ctlr_info *));
+	if (sh == NULL) return 0;
+
+	sh->io_port = 0;	// good enough?  FIXME,
+	sh->n_io_port = 0;	// I don't think we use these two...
+
+	sh->this_id = SELF_SCSI_ID;
+
+	/* This is a bit kludgey, using the adapter name to figure out */
+	/* which scsi host template we've got, won't scale beyond 9 ctlrs. */
+	i = tpnt->name[5] - '0';
+
+#	if MAX_CTLR > 9
+#		error "cciss_scsi.c: MAX_CTLR > 9, code maintenance needed."
+#	endif
+
+	if (i<0 || i>=MAX_CTLR || hba[i] == NULL) {
+		/* we didn't find ourself... we shouldn't get here. */
+		printk("cciss_scsi_detect: could not find ourself in hba[]\n");
+		return 0;
+	}
+
+	((struct cciss_scsi_adapter_data_t *)
+		hba[i]->scsi_ctlr)->scsi_host = (void *) sh;
+	sh->hostdata[0] = (unsigned long) hba[i];
+	sh->irq = hba[i]->intr;
+	sh->unique_id = sh->irq;
+	scsi_set_pci_device(sh, hba[i]->pdev);
+
+	return 1;	/* Say we have 1 scsi adapter, this will be */
+			/* called multiple times, once for each adapter */
+			/* from cciss.c:cciss_init_one().  We do it this */
+			/* way for PCI-hot plug reasons. (we don't know how */
+			/* many adapters we have total, so we say we have */
+			/* 1, each of a unique type.) */
+}
+
+static void __exit cleanup_cciss_module(void);
+int
+cciss_scsi_release(struct Scsi_Host *sh)
+{
+	return 0;
+}
+
+static void
+cciss_unmap_one(struct pci_dev *pdev,
+		CommandList_struct *cp,
+		size_t buflen,
+		int data_direction)
+{
+	u64bit addr64;
+
+	addr64.val32.lower = cp->SG[0].Addr.lower;
+	addr64.val32.upper = cp->SG[0].Addr.upper;
+	pci_unmap_single(pdev, (dma_addr_t) addr64.val, buflen, data_direction);
+}
+
+static void
+cciss_map_one(struct pci_dev *pdev,
+		CommandList_struct *cp,
+		unsigned char *buf,
+		size_t buflen,
+		int data_direction)
+{
+	__u64 addr64;
+
+	addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction);
+	cp->SG[0].Addr.lower =
+	  (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
+	cp->SG[0].Addr.upper =
+	  (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
+	cp->SG[0].Len = buflen;
+	cp->Header.SGList = (__u8) 1;   /* no. SGs contig in this cmd */
+	cp->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */
+}
+
+static int
+cciss_scsi_do_simple_cmd(ctlr_info_t *c,
+			CommandList_struct *cp,
+			unsigned char *scsi3addr,
+			unsigned char *cdb,
+			unsigned char cdblen,
+			unsigned char *buf, int bufsize,
+			int direction)
+{
+	unsigned long flags;
+
+	cp->cmd_type = CMD_IOCTL_PEND;		// treat this like an ioctl
+	cp->scsi_cmd = NULL;
+	cp->Header.ReplyQueue = 0;  // unused in simple mode
+	memcpy(&cp->Header.LUN, scsi3addr, sizeof(cp->Header.LUN));
+	cp->Header.Tag.lower = cp->busaddr;  // Use k. address of cmd as tag
+	// Fill in the request block...
+
+	/* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n",
+		scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3],
+		scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */
+
+	memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB));
+	memcpy(cp->Request.CDB, cdb, cdblen);
+	cp->Request.Timeout = 1000;		// guarantee completion.
+	cp->Request.CDBLen = cdblen;
+	cp->Request.Type.Type = TYPE_CMD;
+	cp->Request.Type.Attribute = ATTR_SIMPLE;
+	cp->Request.Type.Direction = direction;
+
+	/* Fill in the SG list and do dma mapping */
+	cciss_map_one(c->pdev, cp,
+			(unsigned char *) buf, bufsize,
+			scsi_to_pci_dma_dir(SCSI_DATA_READ));
+
+	/* Put the request on the tail of the request queue */
+	spin_lock_irqsave(&io_request_lock, flags);
+	addQ(&c->reqQ, cp);
+	c->Qdepth++;
+	start_io(c);
+	spin_unlock_irqrestore(&io_request_lock, flags);
+
+	/* Wait for the request to complete */
+	while(cp->cmd_type != CMD_IOCTL_DONE)
+		schedule_timeout(1);
+
+	/* undo the dma mapping */
+	cciss_unmap_one(c->pdev, cp, bufsize,
+				scsi_to_pci_dma_dir(SCSI_DATA_READ));
+
+	return(0);
+}
+
+static void
+cciss_scsi_interpret_error(CommandList_struct *cp)
+{
+	ErrorInfo_struct *ei;
+
+	ei = cp->err_info;
+	switch(ei->CommandStatus)
+	{
+		case CMD_TARGET_STATUS:
+			printk(KERN_WARNING "cciss: cmd %p has "
+				"completed with errors\n", cp);
+			printk(KERN_WARNING "cciss: cmd %p "
+				"has SCSI Status = %x\n",
+					cp,
+					ei->ScsiStatus);
+			if (ei->ScsiStatus == 0)
+				printk(KERN_WARNING
+				"cciss:SCSI status is abnormally zero.  "
+				"(probably indicates selection timeout "
+				"reported incorrectly due to a known "
+				"firmware bug, circa July, 2001.)\n");
+		break;
+		case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
+			printk("UNDERRUN\n");
+		break;
+		case CMD_DATA_OVERRUN:
+			printk(KERN_WARNING "cciss: cp %p has"
+				" completed with data overrun "
+				"reported\n", cp);
+		break;
+		case CMD_INVALID: {
+			/* controller unfortunately reports SCSI passthru's */
+			/* to non-existent targets as invalid commands. */
+			printk(KERN_WARNING "cciss: cp %p is "
+				"reported invalid (probably means "						"target device no longer present)\n",
+				cp);
+			/* print_bytes((unsigned char *) cp, sizeof(*cp), 1, 0);
+			print_cmd(cp);  */
+			}
+		break;
+		case CMD_PROTOCOL_ERR:
+			printk(KERN_WARNING "cciss: cp %p has "
+				"protocol error \n", cp);
+		break;
+		case CMD_HARDWARE_ERR:
+			/* cmd->result = DID_ERROR << 16; */
+			printk(KERN_WARNING "cciss: cp %p had "
+				" hardware error\n", cp);
+		break;
+		case CMD_CONNECTION_LOST:
+			printk(KERN_WARNING "cciss: cp %p had "
+				"connection lost\n", cp);
+		break;
+		case CMD_ABORTED:
+			printk(KERN_WARNING "cciss: cp %p was "
+				"aborted\n", cp);
+		break;
+		case CMD_ABORT_FAILED:
+			printk(KERN_WARNING "cciss: cp %p reports "
+				"abort failed\n", cp);
+		break;
+		case CMD_UNSOLICITED_ABORT:
+			printk(KERN_WARNING "cciss: cp %p aborted "
+				"do to an unsolicited abort\n", cp);
+		break;
+		case CMD_TIMEOUT:
+			printk(KERN_WARNING "cciss: cp %p timedout\n",
+				cp);
+		break;
+		default:
+			printk(KERN_WARNING "cciss: cp %p returned "
+				"unknown status %x\n", cp,
+					ei->CommandStatus);
+	}
+}
+
+static int
+cciss_scsi_do_inquiry(ctlr_info_t *c, unsigned char *scsi3addr,
+		 InquiryData_struct *buf)
+{
+	int rc;
+	CommandList_struct *cp;
+	char cdb[6];
+	ErrorInfo_struct *ei;
+
+	cp = scsi_cmd_alloc(c);
+	ei = cp->err_info;
+
+	if (cp == NULL) {			/* trouble... */
+		printk("cmd_alloc returned NULL!\n");
+		return -1;
+	}
+
+	cdb[0] = CISS_INQUIRY;
+	cdb[1] = 0;
+	cdb[2] = 0;
+	cdb[3] = 0;
+	cdb[4] = sizeof(*buf) & 0xff;
+	cdb[5] = 0;
+	rc = cciss_scsi_do_simple_cmd(c, cp, scsi3addr, cdb,
+				6, (unsigned char *) buf,
+				sizeof(*buf), XFER_READ);
+
+	if (rc != 0) return rc; /* something went wrong */
+
+	if (ei->CommandStatus != 0 &&
+	    ei->CommandStatus != CMD_DATA_UNDERRUN) {
+		cciss_scsi_interpret_error(cp);
+		scsi_cmd_free(c, cp);
+		return -1;
+	}
+	scsi_cmd_free(c, cp);
+	return 0;
+}
+
+static int
+cciss_scsi_do_report_phys_luns(ctlr_info_t *c,
+		ReportLunData_struct *buf, int bufsize)
+{
+	int rc;
+	CommandList_struct *cp;
+	unsigned char cdb[12];
+	unsigned char scsi3addr[8];
+	ErrorInfo_struct *ei;
+
+	cp = scsi_cmd_alloc(c);
+	if (cp == NULL) {			/* trouble... */
+		printk("cmd_alloc returned NULL!\n");
+		return -1;
+	}
+
+	memset(&scsi3addr[0], 0, 8); /* address the controller */
+	cdb[0] = CISS_REPORT_PHYS;
+	cdb[1] = 0;
+	cdb[2] = 0;
+	cdb[3] = 0;
+	cdb[4] = 0;
+	cdb[5] = 0;
+	cdb[6] = (sizeof(*buf) >> 24) & 0xFF;  //MSB
+	cdb[7] = (sizeof(*buf) >> 16) & 0xFF;
+	cdb[8] = (sizeof(*buf) >> 8) & 0xFF;
+	cdb[9] = sizeof(*buf) & 0xFF;
+	cdb[10] = 0;
+	cdb[11] = 0;
+
+	rc = cciss_scsi_do_simple_cmd(c, cp, scsi3addr,
+				cdb, 12,
+				(unsigned char *) buf,
+				bufsize, XFER_READ);
+
+	if (rc != 0) return rc; /* something went wrong */
+
+	ei = cp->err_info;
+	if (ei->CommandStatus != 0 &&
+	    ei->CommandStatus != CMD_DATA_UNDERRUN) {
+		cciss_scsi_interpret_error(cp);
+		scsi_cmd_free(c, cp);
+		return -1;
+	}
+	scsi_cmd_free(c, cp);
+	return 0;
+}
+
+static void
+cciss_update_non_disk_devices(int cntl_num, int hostno)
+{
+	/* the idea here is we could get notified from /proc
+	   that some devices have changed, so we do a report
+	   physical luns cmd, and adjust our list of devices
+	   accordingly.  (We can't rely on the scsi-mid layer just
+	   doing inquiries, because the "busses" that the scsi
+	   mid-layer probes are totally fabricated by this driver,
+	   so new devices wouldn't show up.
+
+	   the scsi3addr's of devices won't change so long as the
+	   adapter is not reset.  That means we can rescan and
+	   tell which devices we already know about, vs. new
+	   devices, vs.  disappearing devices.
+
+	   Also, if you yank out a tape drive, then put in a disk
+	   in it's place, (say, a configured volume from another
+	   array controller for instance)  _don't_ poke this driver
+	   (so it thinks it's still a tape, but _do_ poke the scsi
+	   mid layer, so it does an inquiry... the scsi mid layer
+	   could see the physical disk.  This would be bad.  Need to
+	   think about how to prevent that.  One idea would be to
+	   snoop all scsi responses and if an inquiry repsonse comes
+	   back that reports a disk, chuck it an return selection
+	   timeout instead and adjust our table...  Not sure i like
+	   that though.
+
+	 */
+
+	ReportLunData_struct *ld_buff;
+	InquiryData_struct *inq_buff;
+	unsigned char scsi3addr[8];
+	ctlr_info_t *c;
+	__u32 num_luns=0;
+	unsigned char *ch;
+	/* unsigned char found[CCISS_MAX_SCSI_DEVS_PER_HBA]; */
+	struct cciss_scsi_dev_t currentsd[CCISS_MAX_SCSI_DEVS_PER_HBA];
+	int ncurrent=0;
+	int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8;
+	int i;
+
+	c = (ctlr_info_t *) hba[cntl_num];
+	ld_buff = kmalloc(reportlunsize, GFP_KERNEL);
+	if (ld_buff == NULL) {
+		printk(KERN_ERR "cciss: out of memory\n");
+		return;
+	}
+	memset(ld_buff, 0, reportlunsize);
+	inq_buff = kmalloc(sizeof( InquiryData_struct), GFP_KERNEL);
+	if (inq_buff == NULL) {
+		printk(KERN_ERR "cciss: out of memory\n");
+		kfree(ld_buff);
+		return;
+	}
+
+	if (cciss_scsi_do_report_phys_luns(c, ld_buff, reportlunsize) == 0) {
+		ch = &ld_buff->LUNListLength[0];
+		num_luns = ((ch[0]<<24) | (ch[1]<<16) | (ch[2]<<8) | ch[3]) / 8;
+		if (num_luns > CISS_MAX_PHYS_LUN) {
+			printk(KERN_WARNING
+				"cciss: Maximum physical LUNs (%d) exceeded.  "
+				"%d LUNs ignored.\n", CISS_MAX_PHYS_LUN,
+				num_luns - CISS_MAX_PHYS_LUN);
+			num_luns = CISS_MAX_PHYS_LUN;
+		}
+	}
+	else {
+		printk(KERN_ERR  "cciss: Report physical LUNs failed.\n");
+		return;
+	}
+
+
+	/* adjust our table of devices */
+	for(i=0; i<num_luns; i++)
+	{
+		int devtype;
+
+		/* for each physical lun, do an inquiry */
+		memset(inq_buff, 0, sizeof(InquiryData_struct));
+		memcpy(&scsi3addr[0], &ld_buff->LUN[i][0], 8);
+
+		if (cciss_scsi_do_inquiry(hba[cntl_num],
+			scsi3addr, inq_buff) != 0)
+		{
+			/* Inquiry failed (msg printed already) */
+			devtype = 0; /* so we will skip this device. */
+		} else /* what kind of device is this? */
+			devtype = (inq_buff->data_byte[0] & 0x1f);
+
+		switch (devtype)
+		{
+		  case 0x01: /* sequential access, (tape) */
+		  case 0x08: /* medium changer */
+			memcpy(&currentsd[ncurrent].scsi3addr[0],
+				&scsi3addr[0], 8);
+			currentsd[ncurrent].devtype = devtype;
+			currentsd[ncurrent].bus = -1;
+			currentsd[ncurrent].target = -1;
+			currentsd[ncurrent].lun = -1;
+			ncurrent++;
+			break;
+		  default:
+			break;
+		}
+	}
+
+	adjust_cciss_scsi_table(cntl_num, hostno, currentsd, ncurrent);
+
+	kfree(inq_buff);
+	kfree(ld_buff);
+	return;
+}
+
+static int
+is_keyword(char *ptr, int len, char *verb)  // Thanks to ncr53c8xx.c
+{
+	int verb_len = strlen(verb);
+	if (len >= verb_len && !memcmp(verb,ptr,verb_len))
+		return verb_len;
+	else
+		return 0;
+}
+
+static int
+cciss_scsi_user_command(int ctlr, int hostno, char *buffer, int length)
+{
+	int arg_len;
+
+	if ((arg_len = is_keyword(buffer, length, "rescan")) != 0)
+		cciss_update_non_disk_devices(ctlr, hostno);
+	else
+		return -EINVAL;
+	return length;
+}
+
+/* It's a pity that we need this, but, we do... */
+extern struct Scsi_Host *scsi_hostlist;  /* from ../scsi/hosts.c */
+
+int
+cciss_scsi_proc_info(char *buffer, /* data buffer */
+		char **start, 	   /* where data in buffer starts */
+		off_t offset,	   /* offset from start of imaginary file */
+		int length, 	   /* length of data in buffer */
+		int hostnum, 	   /* which host adapter (always zero for me) */
+		int func)	   /* 0 == read, 1 == write */
+{
+
+	int buflen, datalen;
+	struct Scsi_Host *sh;
+	int found;
+	ctlr_info_t *ci;
+	int cntl_num;
+
+	/* Lets see if we can find our Scsi_Host...
+	   this might be kind of "bad", searching scis_hostlist this way
+	   but how else can we find the scsi host?  I think I've seen
+	   this coded both ways, (circular list and null terminated list)
+	   I coded it to work either way, since I wasn't sure.  */
+
+	sh = scsi_hostlist;
+	found=0;
+	do {
+		if (sh == NULL) break;
+		if (sh->host_no == hostnum) {
+			found++;
+			break;
+		}
+		sh = sh->next;
+	} while (sh != scsi_hostlist && sh != NULL);
+
+	if (sh == NULL || found == 0) /* This really shouldn't ever happen. */
+		return -EINVAL;
+
+	ci = (ctlr_info_t *) sh->hostdata[0];
+	if (ci == NULL)  /* This really shouldn't ever happen. */
+		return -EINVAL;
+
+	cntl_num = ci->ctlr;	/* Get our index into the hba[] array */
+
+	if (func == 0) {	/* User is reading from /proc/scsi/ciss*?/?*  */
+		buflen = sprintf(buffer, "hostnum=%d\n", hostnum);
+
+		datalen = buflen - offset;
+		if (datalen < 0) { 	/* they're reading past EOF. */
+			datalen = 0;
+			*start = buffer+buflen;
+		} else
+			*start = buffer + offset;
+		return(datalen);
+	} else 	/* User is writing to /proc/scsi/cciss*?/?*  ... */
+		return cciss_scsi_user_command(cntl_num, hostnum,
+			buffer, length);
+}
+
+/* this is via the generic proc support */
+const char *
+cciss_scsi_info(struct Scsi_Host *sa)
+{
+	static char buf[300];
+	ctlr_info_t *ci;
+
+	/* probably need to work on putting a bit more info in here... */
+	/* this is output via the /proc filesystem. */
+
+	ci = (ctlr_info_t *) sa->hostdata[0];
+
+	sprintf(buf, "%s %c%c%c%c\n",
+		ci->product_name,
+		ci->firm_ver[0],
+		ci->firm_ver[1],
+		ci->firm_ver[2],
+		ci->firm_ver[3]);
+
+	return buf;
+}
+
+
+/* cciss_scatter_gather takes a Scsi_Cmnd, (cmd), and does the pci
+   dma mapping  and fills in the scatter gather entries of the
+   cciss command, cp. */
+
+static void
+cciss_scatter_gather(struct pci_dev *pdev,
+		CommandList_struct *cp,
+		Scsi_Cmnd *cmd)
+{
+	unsigned int use_sg, nsegs=0, len;
+	struct scatterlist *scatter = (struct scatterlist *) cmd->buffer;
+	__u64 addr64;
+
+	/* is it just one virtual address? */
+	if (!cmd->use_sg) {
+		if (cmd->request_bufflen) {	/* anything to xfer? */
+
+			addr64 = (__u64) pci_map_single(pdev,
+				cmd->request_buffer,
+				cmd->request_bufflen,
+				scsi_to_pci_dma_dir(cmd->sc_data_direction));
+
+			cp->SG[0].Addr.lower =
+			  (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
+			cp->SG[0].Addr.upper =
+			  (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
+			cp->SG[0].Len = cmd->request_bufflen;
+			nsegs=1;
+		}
+	} /* else, must be a list of virtual addresses.... */
+	else if (cmd->use_sg <= MAXSGENTRIES) {	/* not too many addrs? */
+
+		use_sg = pci_map_sg(pdev, cmd->buffer, cmd->use_sg,
+			scsi_to_pci_dma_dir(cmd->sc_data_direction));
+
+		for (nsegs=0; nsegs < use_sg; nsegs++) {
+			addr64 = (__u64) sg_dma_address(&scatter[nsegs]);
+			len  = sg_dma_len(&scatter[nsegs]);
+			cp->SG[nsegs].Addr.lower =
+			  (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
+			cp->SG[nsegs].Addr.upper =
+			  (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
+			cp->SG[nsegs].Len = len;
+			cp->SG[nsegs].Ext = 0;  // we are not chaining
+		}
+	} else BUG();
+
+	cp->Header.SGList = (__u8) nsegs;   /* no. SGs contig in this cmd */
+	cp->Header.SGTotal = (__u16) nsegs; /* total sgs in this cmd list */
+	return;
+}
+
+
+int
+cciss_scsi_queue_command (Scsi_Cmnd *cmd, void (* done)(Scsi_Cmnd *))
+{
+	ctlr_info_t **c;
+	int ctlr, rc;
+	unsigned char scsi3addr[8];
+	CommandList_struct *cp;
+
+	// Get the ptr to our adapter structure (hba[i]) out of cmd->host.
+	// We violate cmd->host privacy here.  (Is there another way?)
+	c = (ctlr_info_t **) &cmd->host->hostdata[0];
+	ctlr = (*c)->ctlr;
+
+	rc = lookup_scsi3addr(ctlr, cmd->channel, cmd->target, cmd->lun,
+			scsi3addr);
+	if (rc != 0) {
+		/* the scsi nexus does not match any that we presented... */
+		/* pretend to mid layer that we got selection timeout */
+		cmd->result = DID_NO_CONNECT << 16;
+		done(cmd);
+		/* we might want to think about registering controller itself
+		   as a processor device on the bus so sg binds to it. */
+		return 0;
+	}
+
+	// printk("cciss_queue_command, p=%p, cmd=0x%02x, c%db%dt%dl%d\n",
+	//	cmd, cmd->cmnd[0], ctlr, cmd->channel, cmd->target, cmd->lun);
+
+	/* Ok, we have a reasonable scsi nexus, so send the cmd down, and
+		see what the device thinks of it. */
+
+	cp = scsi_cmd_alloc(*c);
+	if (cp == NULL) {			/* trouble... */
+		printk("scsi_cmd_alloc returned NULL!\n");
+		/* FIXME: next 3 lines are -> BAD! <- */
+		cmd->result = DID_NO_CONNECT << 16;
+		done(cmd);
+		return 0;
+	}
+
+	// Fill in the command list header
+
+	cmd->scsi_done = done;    // save this for use by completion code
+
+	// save cp in case we have to abort it
+	cmd->host_scribble = (unsigned char *) cp;
+
+	cp->cmd_type = CMD_SCSI;
+	cp->scsi_cmd = cmd;
+	cp->Header.ReplyQueue = 0;  // unused in simple mode
+	memcpy(&cp->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
+	cp->Header.Tag.lower = cp->busaddr;  // Use k. address of cmd as tag
+
+	// Fill in the request block...
+
+	cp->Request.Timeout = 1000; // guarantee completion
+	memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB));
+	if (cmd->cmd_len > sizeof(cp->Request.CDB)) BUG();
+	cp->Request.CDBLen = cmd->cmd_len;
+	memcpy(cp->Request.CDB, cmd->cmnd, cmd->cmd_len);
+	cp->Request.Type.Type = TYPE_CMD;
+	cp->Request.Type.Attribute = ATTR_SIMPLE;
+	switch(cmd->sc_data_direction)
+	{
+	  case SCSI_DATA_WRITE: cp->Request.Type.Direction = XFER_WRITE; break;
+	  case SCSI_DATA_READ: cp->Request.Type.Direction = XFER_READ; break;
+	  case SCSI_DATA_NONE: cp->Request.Type.Direction = XFER_NONE; break;
+
+	  case SCSI_DATA_UNKNOWN:
+		// This can happen if a buggy application does a scsi passthru
+		// and sets both inlen and outlen to non-zero. ( see
+		// ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
+
+		cp->Request.Type.Direction = XFER_RSVD;
+		// This is technically wrong, and cciss controllers should
+		// reject it with CMD_INVALID, which is the most correct
+		// response, but non-fibre backends appear to let it
+		// slide by, and give the same results as if this field
+		// were set correctly.  Either way is acceptable for
+		// our purposes here.
+
+		break;
+
+	  default:
+		printk("cciss: unknown data direction: %d\n",
+			cmd->sc_data_direction);
+		BUG();
+		break;
+	}
+
+	cciss_scatter_gather((*c)->pdev, cp, cmd); // Fill the SG list
+
+	/* Put the request on the tail of the request queue */
+
+	addQ(&(*c)->reqQ, cp);
+	(*c)->Qdepth++;
+	start_io(*c);
+
+	/* the cmd'll come back via intr handler in complete_scsi_command()  */
+	return 0;
+}
+
+static void
+init_driver_template(int ctlr)
+{
+	memset(&driver_template[ctlr], 0, sizeof(driver_template[ctlr]));
+	driver_template[ctlr].name = ccissscsi[ctlr].name;
+	driver_template[ctlr].proc_name = ccissscsi[ctlr].name;
+	driver_template[ctlr].detect = cciss_scsi_detect;
+	driver_template[ctlr].release = cciss_scsi_release;
+	driver_template[ctlr].proc_info = cciss_scsi_proc_info;
+	driver_template[ctlr].queuecommand = cciss_scsi_queue_command;
+	driver_template[ctlr].eh_abort_handler = NULL;
+	driver_template[ctlr].eh_device_reset_handler = NULL;
+	driver_template[ctlr].bios_param = scsicam_bios_param;
+	driver_template[ctlr].can_queue = SCSI_CCISS_CAN_QUEUE;
+	driver_template[ctlr].this_id = SELF_SCSI_ID;
+	driver_template[ctlr].sg_tablesize = MAXSGENTRIES;
+	driver_template[ctlr].cmd_per_lun = 1;
+	driver_template[ctlr].use_new_eh_code = 1;
+	driver_template[ctlr].use_clustering = DISABLE_CLUSTERING;
+	driver_template[ctlr].module = THIS_MODULE;
+
+	/* set scsi_host to NULL so our detect routine will
+	   find us on register */
+
+	((struct cciss_scsi_adapter_data_t *)
+		hba[ctlr]->scsi_ctlr)->scsi_host = NULL;
+
+}
+
+static void
+cciss_unregister_scsi(int ctlr)
+{
+	struct cciss_scsi_adapter_data_t *sa;
+	struct cciss_scsi_cmd_stack_t *stk;
+	unsigned long flags;
+
+	/* we are being forcibly unloaded, and may not refuse. */
+
+	spin_lock_irqsave(&io_request_lock, flags);
+	sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
+	stk = &sa->cmd_stack;
+
+	/* if we weren't ever actually registered, don't unregister */
+	if (((struct cciss_scsi_adapter_data_t *)
+		hba[ctlr]->scsi_ctlr)->registered) {
+		spin_unlock_irqrestore(&io_request_lock, flags);
+		scsi_unregister_module(MODULE_SCSI_HA, &driver_template[ctlr]);
+		spin_lock_irqsave(&io_request_lock, flags);
+	}
+	init_driver_template(ctlr);
+	scsi_cmd_stack_free(ctlr);
+	kfree(hba[ctlr]->scsi_ctlr);
+	spin_unlock_irqrestore(&io_request_lock, flags);
+}
+
+static int
+cciss_register_scsi(int ctlr, int this_is_init_time)
+{
+	unsigned long flags;
+
+	CPQ_TAPE_LOCK(ctlr, flags);
+	driver_template[ctlr].name = ccissscsi[ctlr].name;
+	driver_template[ctlr].proc_name = ccissscsi[ctlr].name;
+	driver_template[ctlr].module = THIS_MODULE;;
+
+	/* Since this is really a block driver, the SCSI core may not be
+	   initialized yet, in which case, calling scsi_register_module
+	   would hang.  instead, we will do it later, via /proc filesystem
+	   and rc scripts, when we know SCSI core is good to go. */
+
+	if (this_is_init_time) {
+		CPQ_TAPE_UNLOCK(ctlr, flags);
+		return 0;
+	}
+
+	/* Only register if SCSI devices are detected. */
+	if (ccissscsi[ctlr].ndevices != 0) {
+		((struct cciss_scsi_adapter_data_t *)
+			hba[ctlr]->scsi_ctlr)->registered = 1;
+		CPQ_TAPE_UNLOCK(ctlr, flags);
+		return scsi_register_module(MODULE_SCSI_HA,
+			&driver_template[ctlr]);
+	}
+	CPQ_TAPE_UNLOCK(ctlr, flags);
+	printk(KERN_INFO
+		"cciss%d: No appropriate SCSI device detected, "
+		"SCSI subsystem not engaged.\n", ctlr);
+	return 0;
+}
+
+static int
+cciss_engage_scsi(int ctlr)
+{
+	struct cciss_scsi_adapter_data_t *sa;
+	struct cciss_scsi_cmd_stack_t *stk;
+	unsigned long flags;
+
+	spin_lock_irqsave(&io_request_lock, flags);
+	sa = (struct cciss_scsi_adapter_data_t *) hba[ctlr]->scsi_ctlr;
+	stk = &sa->cmd_stack;
+
+	if (((struct cciss_scsi_adapter_data_t *)
+		hba[ctlr]->scsi_ctlr)->registered) {
+		printk("cciss%d: SCSI subsystem already engaged.\n", ctlr);
+		spin_unlock_irqrestore(&io_request_lock, flags);
+		return ENXIO;
+	}
+	spin_unlock_irqrestore(&io_request_lock, flags);
+	cciss_update_non_disk_devices(ctlr, -1);
+	cciss_register_scsi(ctlr, 0);
+	return 0;
+}
+
+static void
+cciss_proc_tape_report(int ctlr, unsigned char *buffer, off_t *pos, off_t *len)
+{
+	int size;
+	unsigned int flags;
+
+	*pos = *pos -1; *len = *len - 1; // cut off the last trailing newline
+
+	CPQ_TAPE_LOCK(ctlr, flags);
+	size = sprintf(buffer + *len,
+		"       Sequential access devices: %d\n\n",
+			ccissscsi[ctlr].ndevices);
+	CPQ_TAPE_UNLOCK(ctlr, flags);
+	*pos += size; *len += size;
+}
+
+#else /* no CONFIG_CISS_SCSI_TAPE */
+
+/* If no tape support, then these become defined out of existence */
+
+#define cciss_find_non_disk_devices(cntl_num)
+#define cciss_unregister_scsi(ctlr)
+#define cciss_register_scsi(ctlr, this_is_init_time)
+#define cciss_proc_tape_report(ctlr, buffer, pos, len)
+
+#endif /* CONFIG_CISS_SCSI_TAPE */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/cciss_scsi.h linux/drivers/block/cciss_scsi.h
--- tmp/linux/drivers/block/cciss_scsi.h	Thu Jan  1 00:00:00 1970
+++ linux/drivers/block/cciss_scsi.h	Mon Feb 25 18:53:39 2002
@@ -0,0 +1,99 @@
+/*
+ *    Disk Array driver for Compaq SA53xx Controllers, SCSI Tape module
+ *    Copyright 2001 Compaq Computer Corporation
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ *    NON INFRINGEMENT.  See the GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *    Questions/Comments/Bugfixes to arrays@compaq.com
+ *
+ */
+#ifdef CONFIG_CISS_SCSI_TAPE
+#ifndef _CCISS_SCSI_H_
+#define _CCISS_SCSI_H_
+
+#include <scsi/scsicam.h> /* possibly irrelevant, since we don't show disks */
+
+		// the scsi id of the adapter...
+#define SELF_SCSI_ID -1 
+		// In case we ever want to present controller so sg will 
+		// bind to it.  The scsi bus that's presented by the
+		// driver to the OS is fabricated.  The "real" scsi-3
+		// bus the hardware presents is fabricated too.
+		// The actual, honest-to-goodness physical
+		// bus that the devices are attached to is not
+		// addressible natively, and may in fact turn
+		// out to be not scsi at all.
+
+#define SCSI_CCISS_CAN_QUEUE 2
+
+/* this notation works fine for static initializations (as is the usual
+   case for linux scsi drivers), but not so well for dynamic settings,
+   so, if you change this, you also have to change cciss_unregister_scsi()
+   in cciss_scsi.c  */
+#define CCISS_SCSI {    \
+	name:			"",				\
+	detect:			cciss_scsi_detect,		\
+	release:		cciss_scsi_release,		\
+	proc_info:		cciss_scsi_proc_info,		\
+	queuecommand:   	cciss_scsi_queue_command,	\
+	bios_param:     	scsicam_bios_param,		\
+	can_queue:      	SCSI_CCISS_CAN_QUEUE,		\
+	this_id:		SELF_SCSI_ID,			\
+	sg_tablesize:   	MAXSGENTRIES, 			\
+	cmd_per_lun:		1,				\
+	use_new_eh_code:	1,				\
+	use_clustering:		DISABLE_CLUSTERING,\
+}
+
+/*
+	info:			cciss_scsi_info,		\
+
+Note, cmd_per_lun could give us some trouble, so I'm setting it very low.
+Likewise, SCSI_CCISS_CAN_QUEUE is set very conservatively.
+
+If the upper scsi layer tries to track how many commands we have
+outstanding, it will be operating under the misapprehension that it is
+the only one sending us requests.  We also have the block interface,
+which is where most requests must surely come from, so the upper layer's
+notion of how many requests we have outstanding will be wrong most or
+all of the time.
+
+Note, the normal SCSI mid-layer error handling doesn't work well
+for this driver because 1) it takes the io_request_lock before
+calling error handlers and uses a local variable to store flags,
+so the io_request_lock cannot be released and interrupts enabled
+inside the error handlers, and, the error handlers cannot poll
+for command completion because they might get commands from the
+block half of the driver completing, and not know what to do
+with them.  That's what we get for making a hybrid scsi/block
+driver, I suppose.
+
+*/
+
+struct cciss_scsi_dev_t {
+	int devtype;
+	int bus, target, lun;		/* as presented to the OS */
+	unsigned char scsi3addr[8];	/* as presented to the HW */
+};
+
+struct cciss_scsi_hba_t {
+	char *name;
+	int ndevices;
+#define CCISS_MAX_SCSI_DEVS_PER_HBA 16
+	struct cciss_scsi_dev_t dev[CCISS_MAX_SCSI_DEVS_PER_HBA];
+};
+
+#endif /* _CCISS_SCSI_H_ */
+#endif /* CONFIG_CISS_SCSI_TAPE */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/ll_rw_blk.c linux/drivers/block/ll_rw_blk.c
--- tmp/linux/drivers/block/ll_rw_blk.c	Mon Feb 25 20:28:49 2002
+++ linux/drivers/block/ll_rw_blk.c	Mon Feb 25 19:55:43 2002
@@ -118,10 +118,14 @@
 int * max_sectors[MAX_BLKDEV];
 
 /*
- * How many reqeusts do we allocate per queue,
- * and how many do we "batch" on freeing them?
+ * The total number of requests in each queue.
  */
-static int queue_nr_requests, batch_requests;
+static int queue_nr_requests;
+
+/*
+ * The threshold around which we make wakeup decisions
+ */
+static int batch_requests;
 
 static inline int get_max_sectors(kdev_t dev)
 {
@@ -352,7 +356,8 @@
 		q->rq[i&1].count++;
 	}
 
-	init_waitqueue_head(&q->wait_for_request);
+	init_waitqueue_head(&q->wait_for_requests[0]);
+	init_waitqueue_head(&q->wait_for_requests[1]);
 	spin_lock_init(&q->queue_lock);
 }
 
@@ -418,9 +423,9 @@
 #define blkdev_free_rq(list) list_entry((list)->next, struct request, queue);
 /*
  * Get a free request. io_request_lock must be held and interrupts
- * disabled on the way in.
+ * disabled on the way in.  Returns NULL if there are no free requests.
  */
-static inline struct request *get_request(request_queue_t *q, int rw)
+static struct request *get_request(request_queue_t *q, int rw)
 {
 	struct request *rq = NULL;
 	struct request_list *rl = q->rq + rw;
@@ -430,6 +435,7 @@
 		list_del(&rq->queue);
 		rl->count--;
 		rq->rq_status = RQ_ACTIVE;
+		rq->cmd = rw;
 		rq->special = NULL;
 		rq->q = q;
 	}
@@ -438,40 +444,84 @@
 }
 
 /*
- * No available requests for this queue, unplug the device.
+ * Here's the request allocation design:
+ *
+ * 1: Blocking on request exhaustion is a key part of I/O throttling.
+ * 
+ * 2: We want to be `fair' to all requesters.  We must avoid starvation, and
+ *    attempt to ensure that all requesters sleep for a similar duration.  Hence
+ *    no stealing requests when there are other processes waiting.
+ * 
+ * 3: We also wish to support `batching' of requests.  So when a process is
+ *    woken, we want to allow it to allocate a decent number of requests
+ *    before it blocks again, so they can be nicely merged (this only really
+ *    matters if the process happens to be adding requests near the head of
+ *    the queue).
+ * 
+ * 4: We want to avoid scheduling storms.  This isn't really important, because
+ *    the system will be I/O bound anyway.  But it's easy.
+ * 
+ *    There is tension between requirements 2 and 3.  Once a task has woken,
+ *    we don't want to allow it to sleep as soon as it takes its second request.
+ *    But we don't want currently-running tasks to steal all the requests
+ *    from the sleepers.  We handle this with wakeup hysteresis around
+ *    0 .. batch_requests and with the assumption that request taking is much,
+ *    much faster than request freeing.
+ * 
+ * So here's what we do:
+ * 
+ *    a) A READA requester fails if free_requests < batch_requests
+ * 
+ *       We don't want READA requests to prevent sleepers from ever
+ *       waking.  Note that READA is used extremely rarely - a few
+ *       filesystems use it for directory readahead.
+ * 
+ *  When a process wants a new request:
+ * 
+ *    b) If free_requests == 0, the requester sleeps in FIFO manner.
+ * 
+ *    b) If 0 <  free_requests < batch_requests and there are waiters,
+ *       we still take a request non-blockingly.  This provides batching.
+ *
+ *    c) If free_requests >= batch_requests, the caller is immediately
+ *       granted a new request.
+ * 
+ *  When a request is released:
+ * 
+ *    d) If free_requests < batch_requests, do nothing.
+ * 
+ *    f) If free_requests >= batch_requests, wake up a single waiter.
+ * 
+ *   The net effect is that when a process is woken at the batch_requests level,
+ *   it will be able to take approximately (batch_requests) requests before
+ *   blocking again (at the tail of the queue).
+ * 
+ *   This all assumes that the rate of taking requests is much, much higher
+ *   than the rate of releasing them.  Which is very true.
+ *
+ * -akpm, Feb 2002.
  */
+
 static struct request *__get_request_wait(request_queue_t *q, int rw)
 {
 	register struct request *rq;
 	DECLARE_WAITQUEUE(wait, current);
 
 	generic_unplug_device(q);
-	add_wait_queue(&q->wait_for_request, &wait);
+	add_wait_queue_exclusive(&q->wait_for_requests[rw], &wait);
 	do {
 		set_current_state(TASK_UNINTERRUPTIBLE);
-		if (q->rq[rw].count < batch_requests)
+		if (q->rq[rw].count == 0)
 			schedule();
 		spin_lock_irq(&io_request_lock);
 		rq = get_request(q,rw);
 		spin_unlock_irq(&io_request_lock);
 	} while (rq == NULL);
-	remove_wait_queue(&q->wait_for_request, &wait);
+	remove_wait_queue(&q->wait_for_requests[rw], &wait);
 	current->state = TASK_RUNNING;
 	return rq;
 }
 
-static inline struct request *get_request_wait(request_queue_t *q, int rw)
-{
-	register struct request *rq;
-
-	spin_lock_irq(&io_request_lock);
-	rq = get_request(q, rw);
-	spin_unlock_irq(&io_request_lock);
-	if (rq)
-		return rq;
-	return __get_request_wait(q, rw);
-}
-
 /* RO fail safe mechanism */
 
 static long ro_bits[MAX_BLKDEV][8];
@@ -546,7 +596,7 @@
 /*
  * Must be called with io_request_lock held and interrupts disabled
  */
-inline void blkdev_release_request(struct request *req)
+void blkdev_release_request(struct request *req)
 {
 	request_queue_t *q = req->q;
 	int rw = req->cmd;
@@ -560,8 +610,9 @@
 	 */
 	if (q) {
 		list_add(&req->queue, &q->rq[rw].free);
-		if (++q->rq[rw].count >= batch_requests && waitqueue_active(&q->wait_for_request))
-			wake_up(&q->wait_for_request);
+		if (++q->rq[rw].count >= batch_requests &&
+				waitqueue_active(&q->wait_for_requests[rw]))
+			wake_up(&q->wait_for_requests[rw]);
 	}
 }
 
@@ -742,22 +793,30 @@
 			BUG();
 	}
 		
-	/*
-	 * Grab a free request from the freelist - if that is empty, check
-	 * if we are doing read ahead and abort instead of blocking for
-	 * a free slot.
-	 */
 get_rq:
 	if (freereq) {
 		req = freereq;
 		freereq = NULL;
-	} else if ((req = get_request(q, rw)) == NULL) {
-		spin_unlock_irq(&io_request_lock);
-		if (rw_ahead)
-			goto end_io;
-
-		freereq = __get_request_wait(q, rw);
-		goto again;
+	} else {
+		/*
+		 * See description above __get_request_wait()
+		 */
+		if (rw_ahead) {
+			if (q->rq[rw].count < batch_requests) {
+				spin_unlock_irq(&io_request_lock);
+				goto end_io;
+			}
+			req = get_request(q, rw);
+			if (req == NULL)
+				BUG();
+		} else {
+			req = get_request(q, rw);
+			if (req == NULL) {
+				spin_unlock_irq(&io_request_lock);
+				freereq = __get_request_wait(q, rw);
+				goto again;
+			}
+		}
 	}
 
 /* fill up the request-info, and add it to the queue */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/block/nbd.c linux/drivers/block/nbd.c
--- tmp/linux/drivers/block/nbd.c	Fri Dec 21 17:41:53 2001
+++ linux/drivers/block/nbd.c	Mon Feb 25 19:21:59 2002
@@ -24,6 +24,8 @@
  * 01-3-11 Make nbd work with new Linux block layer code. It now supports
  *   plugging like all the other block devices. Also added in MSG_MORE to
  *   reduce number of partial TCP segments sent. <steve@chygwyn.com>
+ * 01-12-6 Fix deadlock condition by making queue locks independant of
+ *   the transmit lock. <steve@chygwyn.com>
  *
  * possible FIXME: make set_sock / set_blksize / set_size / do_it one syscall
  * why not: would need verify_area and friends, would share yet another 
@@ -146,11 +148,12 @@
 
 #define FAIL( s ) { printk( KERN_ERR "NBD: " s "(result %d)\n", result ); goto error_out; }
 
-void nbd_send_req(struct socket *sock, struct request *req)
+void nbd_send_req(struct nbd_device *lo, struct request *req)
 {
 	int result;
 	struct nbd_request request;
 	unsigned long size = req->nr_sectors << 9;
+	struct socket *sock = lo->sock;
 
 	DEBUG("NBD: sending control, ");
 	request.magic = htonl(NBD_REQUEST_MAGIC);
@@ -159,6 +162,8 @@
 	request.len = htonl(size);
 	memcpy(request.handle, &req, sizeof(req));
 
+	down(&lo->tx_lock);
+
 	result = nbd_xmit(1, sock, (char *) &request, sizeof(request), req->cmd == WRITE ? MSG_MORE : 0);
 	if (result <= 0)
 		FAIL("Sendmsg failed for control.");
@@ -173,30 +178,51 @@
 			bh = bh->b_reqnext;
 		} while(bh);
 	}
+	up(&lo->tx_lock);
 	return;
 
-      error_out:
+error_out:
+	up(&lo->tx_lock);
 	req->errors++;
 }
 
+static struct request *nbd_find_request(struct nbd_device *lo, char *handle)
+{
+	struct request *req;
+	struct list_head *tmp;
+	struct request *xreq;
+
+	memcpy(&xreq, handle, sizeof(xreq));
+
+	spin_lock(&lo->queue_lock);
+	list_for_each(tmp, &lo->queue_head) {
+		req = list_entry(tmp, struct request, queue);
+		if (req != xreq)
+			continue;
+		list_del(&req->queue);
+		spin_unlock(&lo->queue_lock);
+		return req;
+	}
+	spin_unlock(&lo->queue_lock);
+	return NULL;
+}
+
 #define HARDFAIL( s ) { printk( KERN_ERR "NBD: " s "(result %d)\n", result ); lo->harderror = result; return NULL; }
 struct request *nbd_read_stat(struct nbd_device *lo)
 		/* NULL returned = something went wrong, inform userspace       */ 
 {
 	int result;
 	struct nbd_reply reply;
-	struct request *xreq, *req;
+	struct request *req;
 
 	DEBUG("reading control, ");
 	reply.magic = 0;
 	result = nbd_xmit(0, lo->sock, (char *) &reply, sizeof(reply), MSG_WAITALL);
 	if (result <= 0)
 		HARDFAIL("Recv control failed.");
-	memcpy(&xreq, reply.handle, sizeof(xreq));
-	req = blkdev_entry_prev_request(&lo->queue_head);
-
-	if (xreq != req)
-		FAIL("Unexpected handle received.\n");
+	req = nbd_find_request(lo, reply.handle);
+	if (req == NULL)
+		HARDFAIL("Unexpected reply");
 
 	DEBUG("ok, ");
 	if (ntohl(reply.magic) != NBD_REPLY_MAGIC)
@@ -226,20 +252,14 @@
 {
 	struct request *req;
 
-	down (&lo->queue_lock);
 	while (1) {
-		up (&lo->queue_lock);
 		req = nbd_read_stat(lo);
-		down (&lo->queue_lock);
 
 		if (!req) {
 			printk(KERN_ALERT "req should never be null\n" );
 			goto out;
 		}
 #ifdef PARANOIA
-		if (req != blkdev_entry_prev_request(&lo->queue_head)) {
-			printk(KERN_ALERT "NBD: I have problem...\n");
-		}
 		if (lo != &nbd_dev[MINOR(req->rq_dev)]) {
 			printk(KERN_ALERT "NBD: request corrupted!\n");
 			continue;
@@ -249,15 +269,11 @@
 			goto out;
 		}
 #endif
-		list_del(&req->queue);
-		up (&lo->queue_lock);
 		
 		nbd_end_request(req);
 
-		down (&lo->queue_lock);
 	}
  out:
-	up (&lo->queue_lock);
 }
 
 void nbd_clear_que(struct nbd_device *lo)
@@ -270,27 +286,20 @@
 		return;
 	}
 #endif
-
-	while (!list_empty(&lo->queue_head)) {
-		req = blkdev_entry_prev_request(&lo->queue_head);
-#ifdef PARANOIA
-		if (!req) {
-			printk( KERN_ALERT "NBD: panic, panic, panic\n" );
-			break;
+	do {
+		req = NULL;
+		spin_lock(&lo->queue_lock);
+		if (!list_empty(&lo->queue_head)) {
+			req = list_entry(lo->queue_head.next, struct request, queue);
+			list_del(&req->queue);
 		}
-		if (lo != &nbd_dev[MINOR(req->rq_dev)]) {
-			printk(KERN_ALERT "NBD: request corrupted when clearing!\n");
-			continue;
+		spin_unlock(&lo->queue_lock);
+		if (req) {
+			req->errors++;
+			nbd_end_request(req);
 		}
-#endif
-		req->errors++;
-		list_del(&req->queue);
-		up(&lo->queue_lock);
+	} while(req);
 
-		nbd_end_request(req);
-
-		down(&lo->queue_lock);
-	}
 }
 
 /*
@@ -334,10 +343,11 @@
 		blkdev_dequeue_request(req);
 		spin_unlock_irq(&io_request_lock);
 
-		down (&lo->queue_lock);
-		list_add(&req->queue, &lo->queue_head);
-		nbd_send_req(lo->sock, req);	/* Why does this block?         */
-		up (&lo->queue_lock);
+		spin_lock(&lo->queue_lock);
+		list_add_tail(&req->queue, &lo->queue_head);
+		spin_unlock(&lo->queue_lock);
+
+		nbd_send_req(lo, req);
 
 		spin_lock_irq(&io_request_lock);
 		continue;
@@ -372,21 +382,21 @@
 	lo = &nbd_dev[dev];
 	switch (cmd) {
 	case NBD_DISCONNECT:
-	        printk("NBD_DISCONNECT\n") ;
+	        printk("NBD_DISCONNECT\n");
                 sreq.cmd=2 ; /* shutdown command */
-                if (!lo->sock) return -EINVAL ;
-                nbd_send_req(lo->sock,&sreq) ;
+                if (!lo->sock) return -EINVAL;
+                nbd_send_req(lo, &sreq);
                 return 0 ;
  
 	case NBD_CLEAR_SOCK:
-		down(&lo->queue_lock);
 		nbd_clear_que(lo);
+		spin_lock(&lo->queue_lock);
 		if (!list_empty(&lo->queue_head)) {
-			up(&lo->queue_lock);
+			spin_unlock(&lo->queue_lock);
 			printk(KERN_ERR "nbd: Some requests are in progress -> can not turn off.\n");
 			return -EBUSY;
 		}
-		up(&lo->queue_lock);
+		spin_unlock(&lo->queue_lock);
 		file = lo->file;
 		if (!file)
 			return -EINVAL;
@@ -507,8 +517,9 @@
 		nbd_dev[i].file = NULL;
 		nbd_dev[i].magic = LO_MAGIC;
 		nbd_dev[i].flags = 0;
+		spin_lock_init(&nbd_dev[i].queue_lock);
 		INIT_LIST_HEAD(&nbd_dev[i].queue_head);
-		init_MUTEX(&nbd_dev[i].queue_lock);
+		init_MUTEX(&nbd_dev[i].tx_lock);
 		nbd_blksizes[i] = 1024;
 		nbd_blksize_bits[i] = 10;
 		nbd_bytesizes[i] = 0x7ffffc00; /* 2GB */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/ide/ide-floppy.c linux/drivers/ide/ide-floppy.c
--- tmp/linux/drivers/ide/ide-floppy.c	Fri Dec 21 17:41:54 2001
+++ linux/drivers/ide/ide-floppy.c	Mon Feb 25 20:22:33 2002
@@ -1,8 +1,8 @@
 /*
- * linux/drivers/ide/ide-floppy.c	Version 0.97.sv	Jan 14 2001
+ * linux/drivers/ide/ide-floppy.c	Version 0.99	Feb 24 2002
  *
  * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il>
- * Copyright (C) 2000 - 2001 Paul Bristow <paul@paulbristow.net>
+ * Copyright (C) 2000 - 2002 Paul Bristow <paul@paulbristow.net>
  */
 
 /*
@@ -13,7 +13,7 @@
  *
  * This driver supports the following IDE floppy drives:
  *
- * LS-120 SuperDisk
+ * LS-120/240 SuperDisk
  * Iomega Zip 100/250
  * Iomega PC Card Clik!/PocketZip
  *
@@ -71,9 +71,11 @@
  *                       including set_bit patch from Rusty Russel
  * Ver 0.97  Jul 22 01   Merge 0.91-0.96 onto 0.9.sv for ac series
  * Ver 0.97.sv Aug 3 01  Backported from 2.4.7-ac3
+ * Ver 0.99  Feb 24 02   Remove duplicate code, modify clik! detection code 
+                         to support new PocketZip drives 
  */
 
-#define IDEFLOPPY_VERSION "0.97.sv"
+#define IDEFLOPPY_VERSION "0.99"
 
 #include <linux/config.h>
 #include <linux/module.h>
@@ -1962,25 +1964,12 @@
    *      above fix.  It makes nasty clicking noises without
    *      it, so please don't remove this.
    */
-  if (strcmp(drive->id->model, "IOMEGA Clik! 40 CZ ATAPI") == 0)
+	if (strncmp(drive->id->model, "IOMEGA Clik", 11) == 0) 
   {
     for (i = 0; i < 1 << PARTN_BITS; i++)
       max_sectors[major][minor + i] = 64;
     set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags);
   }
-
-	/*
-	*      Guess what?  The IOMEGA Clik! drive also needs the
-	*      above fix.  It makes nasty clicking noises without
-	*      it, so please don't remove this.
-	*/
-	if (strcmp(drive->id->model, "IOMEGA Clik! 40 CZ ATAPI") == 0) 
-	{
-		for (i = 0; i < 1 << PARTN_BITS; i++)
-			max_sectors[major][minor + i] = 64;
-		set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags);
-	}
-
 
 	(void) idefloppy_get_capacity (drive);
 	idefloppy_add_settings(drive);
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/media/video/meye.c linux/drivers/media/video/meye.c
--- tmp/linux/drivers/media/video/meye.c	Fri Dec 21 17:41:54 2001
+++ linux/drivers/media/video/meye.c	Mon Feb 25 19:16:14 2002
@@ -142,25 +142,6 @@
 	return ret;
 }
 
-static inline unsigned long uvirt_to_bus(unsigned long adr) {
-        unsigned long kva, ret;
-
-        kva = uvirt_to_kva(pgd_offset(current->mm, adr), adr);
-	ret = virt_to_bus((void *)kva);
-        MDEBUG(printk("uv2b(%lx-->%lx)\n", adr, ret));
-        return ret;
-}
-
-static inline unsigned long kvirt_to_bus(unsigned long adr) {
-        unsigned long va, kva, ret;
-
-        va = VMALLOC_VMADDR(adr);
-        kva = uvirt_to_kva(pgd_offset_k(va), va);
-	ret = virt_to_bus((void *)kva);
-        MDEBUG(printk("kv2b(%lx-->%lx)\n", adr, ret));
-        return ret;
-}
-
 /* Here we want the physical address of the memory.
  * This is used when initializing the contents of the
  * area and marking the pages as reserved.
@@ -209,31 +190,64 @@
 }
 
 /* return a page table pointing to N pages of locked memory */
-static void *ptable_alloc(int npages, u32 *pt_addr) {
+static int ptable_alloc(void) {
+	u32 *pt;
 	int i;
-	void *vmem;
-	u32 *ptable;
-	unsigned long adr;
-
-	vmem = rvmalloc((npages + 1) * PAGE_SIZE);
-	if (!vmem)
-		return NULL;
-
-        adr = (unsigned long)vmem;
-	ptable = (u32 *)(vmem + npages * PAGE_SIZE);
-	for (i = 0; i < npages; i++) {
-		ptable[i] = (u32) kvirt_to_bus(adr);
-		adr += PAGE_SIZE;
+
+	memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
+
+	meye.mchip_ptable[MCHIP_NB_PAGES] = pci_alloc_consistent(meye.mchip_dev, 
+								 PAGE_SIZE, 
+								 &meye.mchip_dmahandle);
+	if (!meye.mchip_ptable[MCHIP_NB_PAGES])
+		return -1;
+
+	pt = (u32 *)meye.mchip_ptable[MCHIP_NB_PAGES];
+	for (i = 0; i < MCHIP_NB_PAGES; i++) {
+		meye.mchip_ptable[i] = pci_alloc_consistent(meye.mchip_dev, 
+							    PAGE_SIZE,
+							    pt);
+		if (!meye.mchip_ptable[i])
+			return -1;
+		pt++;
 	}
+	return 0;
+}
+
+static void ptable_free(void) {
+	u32 *pt;
+	int i;
 
-	*pt_addr = (u32) kvirt_to_bus(adr);
-	return vmem;
+	pt = (u32 *)meye.mchip_ptable[MCHIP_NB_PAGES];
+	for (i = 0; i < MCHIP_NB_PAGES; i++)
+		if (meye.mchip_ptable[i])
+			pci_free_consistent(meye.mchip_dev, 
+					    PAGE_SIZE, 
+					    meye.mchip_ptable[i], *pt);
+
+	if (meye.mchip_ptable[MCHIP_NB_PAGES])
+		pci_free_consistent(meye.mchip_dev, 
+				    PAGE_SIZE, 
+				    meye.mchip_ptable[MCHIP_NB_PAGES], 
+				    meye.mchip_dmahandle);
+
+	memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
+	meye.mchip_dmahandle = 0;
 }
 
-static void ptable_free(void *vmem, int npages) {
-	rvfree(vmem, (npages + 1) * PAGE_SIZE);
+/* copy data from ptable into buf */
+static void ptable_copy(u8 *buf, int start, int size, int pt_pages) {
+	int i;
+	
+	for (i = 0; i < (size / PAGE_SIZE) * PAGE_SIZE; i += PAGE_SIZE) {
+		memcpy(buf + i, meye.mchip_ptable[start++], PAGE_SIZE);
+		if (start >= pt_pages)
+			start = 0;
+	}
+	memcpy(buf + i, meye.mchip_ptable[start], size % PAGE_SIZE);
 }
 
+
 /****************************************************************************/
 /* JPEG tables at different qualities to load into the VRJ chip             */
 /****************************************************************************/
@@ -587,29 +601,23 @@
 
 /* setup for DMA transfers - also zeros the framebuffer */
 static int mchip_dma_alloc(void) {
-	if (!meye.mchip_fbuffer) {
-		meye.mchip_fbuffer = ptable_alloc(MCHIP_NB_PAGES, 
-				                  &meye.mchip_ptaddr);
-		if (!meye.mchip_fbuffer)
+	if (!meye.mchip_dmahandle)
+		if (ptable_alloc())
 			return -1;
-	}
 	return 0;
 }
 
 /* frees the DMA buffer */
 static void mchip_dma_free(void) {
-	if (meye.mchip_fbuffer) {
-		ptable_free(meye.mchip_fbuffer, MCHIP_NB_PAGES);
-		meye.mchip_fbuffer = 0;
-		meye.mchip_ptaddr = 0;
-	}
+	if (meye.mchip_dmahandle)
+		ptable_free();
 }
 
 /* sets the DMA parameters into the chip */
 static void mchip_dma_setup(void) {
 	int i;
 
-	mchip_set(MCHIP_MM_PT_ADDR, meye.mchip_ptaddr);
+	mchip_set(MCHIP_MM_PT_ADDR, meye.mchip_dmahandle);
 	for (i = 0; i < 4; i++)
 		mchip_set(MCHIP_MM_FIR(i), 0);
 	meye.mchip_fnum = 0;
@@ -658,59 +666,40 @@
 	meye.mchip_fnum %= 4;
 }
 
-
 /* read one frame from the framebuffer assuming it was captured using
    a uncompressed transfer */
-static void  mchip_cont_read_frame(u32 v, u8 *buf, int size) {
+static void mchip_cont_read_frame(u32 v, u8 *buf, int size) {
 	int pt_id;
-	int avail;
 
 	pt_id = (v >> 17) & 0x3FF;
-	avail = MCHIP_NB_PAGES - pt_id;
 
-	if (size > avail*PAGE_SIZE) {
-		memcpy(buf, meye.mchip_fbuffer + pt_id * PAGE_SIZE, 
-		       avail * PAGE_SIZE);
-		memcpy(buf +avail * PAGE_SIZE, meye.mchip_fbuffer,
-		       size - avail * PAGE_SIZE);
-	}
-	else
-		memcpy(buf, meye.mchip_fbuffer + pt_id * PAGE_SIZE, size);
+	ptable_copy(buf, pt_id, size, MCHIP_NB_PAGES);
+
 }
 
 /* read a compressed frame from the framebuffer */
 static int mchip_comp_read_frame(u32 v, u8 *buf, int size) {
 	int pt_start, pt_end, trailer;
-	int fsize, fsize2;
+	int fsize;
 	int i;
 
 	pt_start = (v >> 19) & 0xFF;
 	pt_end = (v >> 11) & 0xFF;
 	trailer = (v >> 1) & 0x3FF;
 
-	if (pt_end < pt_start) {
-		fsize = (MCHIP_NB_PAGES_MJPEG - pt_start) * PAGE_SIZE;
-		fsize2 = pt_end * PAGE_SIZE + trailer * 4;
-		if (fsize + fsize2 > size) {
-			printk(KERN_WARNING "meye: oversized compressed frame %d %d\n", 
-			       fsize, fsize2);
-			return -1;
-		} else {
-			memcpy(buf, meye.mchip_fbuffer + pt_start * PAGE_SIZE, 
-			       fsize);
-			memcpy(buf + fsize, meye.mchip_fbuffer, fsize2); 
-			fsize += fsize2;
-		}
-	} else {
+	if (pt_end < pt_start)
+		fsize = (MCHIP_NB_PAGES_MJPEG - pt_start) * PAGE_SIZE +
+			pt_end * PAGE_SIZE + trailer * 4;
+	else
 		fsize = (pt_end - pt_start) * PAGE_SIZE + trailer * 4;
-		if (fsize > size) {
-			printk(KERN_WARNING "meye: oversized compressed frame %d\n", 
-			       fsize);
-			return -1;
-		} else
-			memcpy(buf, meye.mchip_fbuffer + pt_start * PAGE_SIZE, 
-			       fsize);
+
+	if (fsize > size) {
+		printk(KERN_WARNING "meye: oversized compressed frame %d\n", 
+		       fsize);
+		return -1;
 	}
+
+	ptable_copy(buf, pt_start, fsize, MCHIP_NB_PAGES_MJPEG);
 
 
 #ifdef MEYE_JPEG_CORRECTION
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/media/video/meye.h linux/drivers/media/video/meye.h
--- tmp/linux/drivers/media/video/meye.h	Sat Jul 28 19:35:55 2001
+++ linux/drivers/media/video/meye.h	Mon Feb 25 19:16:14 2002
@@ -29,7 +29,7 @@
 #define _MEYE_PRIV_H_
 
 #define MEYE_DRIVER_MAJORVERSION	1
-#define MEYE_DRIVER_MINORVERSION	1
+#define MEYE_DRIVER_MINORVERSION	2
 
 /****************************************************************************/
 /* Motion JPEG chip registers                                               */
@@ -292,8 +292,8 @@
 	u8 mchip_fnum;			/* current mchip frame number */
 
 	unsigned char *mchip_mmregs;	/* mchip: memory mapped registers */
-	unsigned char *mchip_fbuffer;	/* mchip: framebuffer */
-	u32 mchip_ptaddr;		/* mchip: pointer to framebuffer */
+	u8 *mchip_ptable[MCHIP_NB_PAGES+1];/* mchip: ptable + ptable toc */
+	dma_addr_t mchip_dmahandle;	/* mchip: dma handle to ptable toc */
 
 	unsigned char *grab_fbuffer;	/* capture framebuffer */
 					/* list of buffers */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/net/eepro100.c linux/drivers/net/eepro100.c
--- tmp/linux/drivers/net/eepro100.c	Mon Feb 25 20:28:50 2002
+++ linux/drivers/net/eepro100.c	Mon Feb 25 20:09:41 2002
@@ -1377,7 +1377,7 @@
 
 	/* workaround for hardware bug on 10 mbit half duplex */
 
-	if ((sp->partner == 0) || (sp->chip_id == 1)) {
+	if ((sp->partner==0) && (sp->chip_id==1)) {
 		wait_for_cmd_done(ioaddr + SCBCmd);
 		outb(0 , ioaddr + SCBCmd);
 	}
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/net/natsemi.c linux/drivers/net/natsemi.c
--- tmp/linux/drivers/net/natsemi.c	Mon Feb 25 20:28:50 2002
+++ linux/drivers/net/natsemi.c	Mon Feb 25 20:20:07 2002
@@ -1965,6 +1965,8 @@
 	/* get link status */
 	case ETHTOOL_GLINK: {
 		struct ethtool_value edata = {ETHTOOL_GLINK};
+		/* LSTATUS is latched low until a read - so read twice */
+		mdio_read(dev, 1, MII_BMSR);
 		edata.data = (mdio_read(dev, 1, MII_BMSR)&BMSR_LSTATUS) ? 1:0;
 		if (copy_to_user(useraddr, &edata, sizeof(edata)))
 			return -EFAULT;
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/sound/opl3sa2.c linux/drivers/sound/opl3sa2.c
--- tmp/linux/drivers/sound/opl3sa2.c	Mon Feb 25 20:28:50 2002
+++ linux/drivers/sound/opl3sa2.c	Mon Feb 25 19:53:27 2002
@@ -56,6 +56,7 @@
  * Scott Murray            Some small cleanups to the init code output.
  *                         (Jan 7, 2001)
  * Zwane Mwaikambo	   Added PM support. (Dec 4 2001)
+ * Zwane Mwaikambo	   Code, data structure cleanups. (Feb 15 2002)
  *
  */
 
@@ -71,6 +72,7 @@
 #include "mpu401.h"
 
 #define OPL3SA2_MODULE_NAME	"opl3sa2"
+#define PFX			OPL3SA2_MODULE_NAME ": "
 
 /* Useful control port indexes: */
 #define OPL3SA2_PM	     0x01
@@ -92,9 +94,10 @@
 #define DEFAULT_TIMBRE 0
 
 /* Power saving modes */
-#define OPL3SA2_PM_MODE1	0x05
-#define OPL3SA2_PM_MODE2	0x04
-#define OPL3SA2_PM_MODE3	0x03
+#define OPL3SA2_PM_MODE0	0x00
+#define OPL3SA2_PM_MODE1	0x04	/* PSV */
+#define OPL3SA2_PM_MODE2	0x05	/* PSV | PDX */
+#define OPL3SA2_PM_MODE3	0x27	/* ADOWN | PSV | PDN | PDX */
 
 /* For checking against what the card returns: */
 #define VERSION_UNKNOWN 0
@@ -108,6 +111,7 @@
 #define CHIPSET_UNKNOWN -1
 #define CHIPSET_OPL3SA2 0
 #define CHIPSET_OPL3SA3 1
+static const char *CHIPSET_TABLE[] = {"OPL3-SA2", "OPL3-SA3"};
 
 #if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
 #define OPL3SA2_CARDS_MAX 4
@@ -118,38 +122,40 @@
 /* This should be pretty obvious */
 static int opl3sa2_cards_num; /* = 0 */
 
-/* What's my version(s)? */
-static int chipset[OPL3SA2_CARDS_MAX] = { CHIPSET_UNKNOWN };
-
-/* Oh well, let's just cache the name(s) */
-static char chipset_name[OPL3SA2_CARDS_MAX][12];
+typedef struct {
+	/* device resources */
+	unsigned short cfg_port;
+	struct address_info cfg;
+	struct address_info cfg_mss;
+	struct address_info cfg_mpu;
 
-/* Where's my mixer(s)? */
-static int opl3sa2_mixer[OPL3SA2_CARDS_MAX] = { -1 };
+#if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
+	/* PnP Stuff */
+	struct pci_dev* pdev;
+	int activated;			/* Whether said devices have been activated */
+#endif
 
-/* Bag o' mixer data */
-typedef struct opl3sa2_mixerdata_tag {
-	unsigned short cfg_port;
-	unsigned short padding;
-	unsigned char  pm_reg;
-	unsigned int   in_suspend;
-	struct pm_dev  *pmdev;
-	unsigned int   card;
-	unsigned int   volume_l;
-	unsigned int   volume_r;
-	unsigned int   mic;
-	unsigned int   bass_l;
-	unsigned int   bass_r;
-	unsigned int   treble_l;
-	unsigned int   treble_r;
-	unsigned int   wide_l;
-	unsigned int   wide_r;
-} opl3sa2_mixerdata;
-static opl3sa2_mixerdata opl3sa2_data[OPL3SA2_CARDS_MAX];
-
-static struct address_info cfg[OPL3SA2_CARDS_MAX];
-static struct address_info cfg_mss[OPL3SA2_CARDS_MAX];
-static struct address_info cfg_mpu[OPL3SA2_CARDS_MAX];
+#ifdef CONFIG_PM
+	unsigned int	in_suspend;
+	struct pm_dev	*pmdev;
+#endif
+	unsigned int	card;
+	int		chipset;	/* What's my version(s)? */
+	char		*chipset_name;
+
+	/* mixer data */
+	int		mixer;
+	unsigned int	volume_l;
+	unsigned int	volume_r;
+	unsigned int	mic;
+	unsigned int	bass_l;
+	unsigned int	bass_r;
+	unsigned int	treble_l;
+	unsigned int	treble_r;
+	unsigned int	wide_l;
+	unsigned int	wide_r;
+} opl3sa2_state_t;
+static opl3sa2_state_t opl3sa2_state[OPL3SA2_CARDS_MAX];
 
 /* Our parameters */
 static int __initdata io	= -1;
@@ -166,11 +172,6 @@
 static int __initdata isapnp = 1;
 static int __initdata multiple = 1;
 
-/* PnP devices */
-struct pci_dev* opl3sa2_dev[OPL3SA2_CARDS_MAX];
-
-/* Whether said devices have been activated */
-static int opl3sa2_activated[OPL3SA2_CARDS_MAX];
 #else
 static int __initdata isapnp; /* = 0 */
 static int __initdata multiple; /* = 0 */
@@ -240,7 +241,7 @@
  * All of the mixer functions...
  */
 
-static void opl3sa2_set_volume(opl3sa2_mixerdata* devc, int left, int right)
+static void opl3sa2_set_volume(opl3sa2_state_t* devc, int left, int right)
 {
 	static unsigned char scale[101] = {
 		0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
@@ -275,7 +276,7 @@
 }
 
 
-static void opl3sa2_set_mic(opl3sa2_mixerdata* devc, int level)
+static void opl3sa2_set_mic(opl3sa2_state_t* devc, int level)
 {
 	unsigned char vol = 0x1F;
 
@@ -290,7 +291,7 @@
 }
 
 
-static void opl3sa3_set_bass(opl3sa2_mixerdata* devc, int left, int right)
+static void opl3sa3_set_bass(opl3sa2_state_t* devc, int left, int right)
 {
 	unsigned char bass;
 
@@ -301,7 +302,7 @@
 }
 
 
-static void opl3sa3_set_treble(opl3sa2_mixerdata* devc, int left, int right)
+static void opl3sa3_set_treble(opl3sa2_state_t* devc, int left, int right)
 {	
 	unsigned char treble;
 
@@ -312,7 +313,7 @@
 }
 
 
-static void opl3sa3_set_wide(opl3sa2_mixerdata* devc, int left, int right)
+static void opl3sa3_set_wide(opl3sa2_state_t* devc, int left, int right)
 {	
 	unsigned char wide;
 
@@ -323,7 +324,7 @@
 }
 
 
-static void opl3sa2_mixer_reset(opl3sa2_mixerdata* devc, int card)
+static void opl3sa2_mixer_reset(opl3sa2_state_t* devc)
 {
 	if(devc) {
 		opl3sa2_set_volume(devc, DEFAULT_VOLUME, DEFAULT_VOLUME);
@@ -332,7 +333,7 @@
 		opl3sa2_set_mic(devc, DEFAULT_MIC);
 		devc->mic = DEFAULT_MIC;
 
-		if(chipset[card] == CHIPSET_OPL3SA3) {
+		if(devc->chipset == CHIPSET_OPL3SA3) {
 			opl3sa3_set_bass(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
 			devc->bass_l = devc->bass_r = DEFAULT_TIMBRE;
 			opl3sa3_set_treble(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
@@ -342,13 +343,13 @@
 }
 
 
-static void opl3sa2_mixer_restore(opl3sa2_mixerdata* devc, int card)
+static void opl3sa2_mixer_restore(opl3sa2_state_t* devc)
 {
 	if (devc) {
 		opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
 		opl3sa2_set_mic(devc, devc->mic);
 
-		if (chipset[card] == CHIPSET_OPL3SA3) {
+		if (devc->chipset == CHIPSET_OPL3SA3) {
 			opl3sa3_set_bass(devc, devc->bass_l, devc->bass_r);
 			opl3sa3_set_treble(devc, devc->treble_l, devc->treble_r);
 		}
@@ -390,7 +391,7 @@
 {
 	int cmdf = cmd & 0xff;
 
-	opl3sa2_mixerdata* devc = (opl3sa2_mixerdata*) mixer_devs[dev]->devc;
+	opl3sa2_state_t* devc = (opl3sa2_state_t *) mixer_devs[dev]->devc;
 	
 	switch(cmdf) {
 		case SOUND_MIXER_VOLUME:
@@ -473,7 +474,7 @@
 {
 	int cmdf = cmd & 0xff;
 
-	opl3sa2_mixerdata* devc = (opl3sa2_mixerdata*) mixer_devs[dev]->devc;
+	opl3sa2_state_t* devc = (opl3sa2_state_t *) mixer_devs[dev]->devc;
 
 	switch(cmdf) {
 		case SOUND_MIXER_BASS:
@@ -616,7 +617,7 @@
 			AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
 		}
 		else {
-			printk(KERN_ERR "opl3sa2: MSS mixer not installed?\n");
+			printk(KERN_ERR PFX "MSS mixer not installed?\n");
 		}
 	}
 }
@@ -633,13 +634,12 @@
 	unsigned char misc;
 	unsigned char tmp;
 	unsigned char version;
-	char tag;
 
 	/*
 	 * Try and allocate our I/O port range.
 	 */
 	if(!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
-		printk(KERN_ERR "opl3sa2: Control I/O port %#x not free\n",
+		printk(KERN_ERR PFX "Control I/O port %#x not free\n",
 		       hw_config->io_base);
 		return 0;
 	}
@@ -652,7 +652,7 @@
 	opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc ^ 0x07);
 	opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &tmp);
 	if(tmp != misc) {
-		printk(KERN_ERR "opl3sa2: Control I/O port %#x is not a YMF7xx chipset!\n",
+		printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
 		       hw_config->io_base);
 		return 0;
 	}
@@ -665,7 +665,7 @@
 	opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
 	if((tmp & 0x9f) != 0x8a) {
 		printk(KERN_ERR
-		       "opl3sa2: Control I/O port %#x is not a YMF7xx chipset!\n",
+		       PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
 		       hw_config->io_base);
 		return 0;
 	}
@@ -678,47 +678,42 @@
 	 * of the miscellaneous register.
 	 */
 	version = misc & 0x07;
-	printk(KERN_DEBUG "opl3sa2: chipset version = %#x\n", version);
+	printk(KERN_DEBUG PFX "chipset version = %#x\n", version);
 	switch(version) {
 		case 0:
-			chipset[card] = CHIPSET_UNKNOWN;
-			tag = '?'; /* silence compiler warning */
+			opl3sa2_state[card].chipset = CHIPSET_UNKNOWN;
 			printk(KERN_ERR
-			       "opl3sa2: Unknown Yamaha audio controller version\n");
+			       PFX "Unknown Yamaha audio controller version\n");
 			break;
 
 		case VERSION_YMF711:
-			chipset[card] = CHIPSET_OPL3SA2;
-			tag = '2';
-			printk(KERN_INFO "opl3sa2: Found OPL3-SA2 (YMF711)\n");
+			opl3sa2_state[card].chipset = CHIPSET_OPL3SA2;
+			printk(KERN_INFO PFX "Found OPL3-SA2 (YMF711)\n");
 			break;
 
 		case VERSION_YMF715:
-			chipset[card] = CHIPSET_OPL3SA3;
-			tag = '3';
+			opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
 			printk(KERN_INFO
-			       "opl3sa2: Found OPL3-SA3 (YMF715 or YMF719)\n");
+			       PFX "Found OPL3-SA3 (YMF715 or YMF719)\n");
 			break;
 
 		case VERSION_YMF715B:
-			chipset[card] = CHIPSET_OPL3SA3;
-			tag = '3';
+			opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
 			printk(KERN_INFO
-			       "opl3sa2: Found OPL3-SA3 (YMF715B or YMF719B)\n");
+			       PFX "Found OPL3-SA3 (YMF715B or YMF719B)\n");
 			break;
 
 		case VERSION_YMF715E:
 		default:
-			chipset[card] = CHIPSET_OPL3SA3;
-			tag = '3';
+			opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
 			printk(KERN_INFO
-			       "opl3sa2: Found OPL3-SA3 (YMF715E or YMF719E)\n");
+			       PFX "Found OPL3-SA3 (YMF715E or YMF719E)\n");
 			break;
 	}
 
-	if(chipset[card] != CHIPSET_UNKNOWN) {
+	if(opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
 		/* Generate a pretty name */
-		sprintf(chipset_name[card], "OPL3-SA%c", tag);
+		opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
 		return 1;
 	}
 	return 0;
@@ -746,30 +741,28 @@
 static void __init attach_opl3sa2_mixer(struct address_info *hw_config, int card)
 {
 	struct mixer_operations* mixer_operations;
-	opl3sa2_mixerdata* devc;
+	opl3sa2_state_t* devc = &opl3sa2_state[card];
 
 	/* Install master mixer */
-	if(chipset[card] == CHIPSET_OPL3SA3) {
+	if(devc->chipset == CHIPSET_OPL3SA3) {
 		mixer_operations = &opl3sa3_mixer_operations;
 	}
 	else {
 		mixer_operations = &opl3sa2_mixer_operations;
 	}
 
-	if((devc = &opl3sa2_data[card])) {
-		devc->cfg_port = hw_config->io_base;
-
-		opl3sa2_mixer[card] = sound_install_mixer(MIXER_DRIVER_VERSION,
-							  mixer_operations->name,
-							  mixer_operations,
-							  sizeof(struct mixer_operations),
-							  devc);
-		if(opl3sa2_mixer[card] < 0) {
-			printk(KERN_ERR "opl3sa2: Could not install %s master mixer\n",
-				 mixer_operations->name);
-		}
-		else
-			opl3sa2_mixer_reset(devc, card);
+	devc->cfg_port = hw_config->io_base;
+	devc->mixer = sound_install_mixer(MIXER_DRIVER_VERSION,
+					  mixer_operations->name,
+					  mixer_operations,
+					  sizeof(struct mixer_operations),
+					  devc);
+	if(devc->mixer < 0) {
+		printk(KERN_ERR PFX "Could not install %s master mixer\n",
+			 mixer_operations->name);
+	}
+	else {
+			opl3sa2_mixer_reset(devc);
 	}
 }
 
@@ -803,7 +796,7 @@
 		opl3sa2_write(hw_config->io_base, OPL3SA2_SYS_CTRL, sys_ctrl);
 	}
 	else {
-		printk(KERN_ERR "opl3sa2: not setting ymode, it must be one of 0,1,2,3\n");
+		printk(KERN_ERR PFX "not setting ymode, it must be one of 0,1,2,3\n");
 	}
 }
 
@@ -818,7 +811,7 @@
 		opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc);
 	}
 	else {
-		printk(KERN_ERR "opl3sa2: not setting loopback, it must be either 0 or 1\n");
+		printk(KERN_ERR PFX "not setting loopback, it must be either 0 or 1\n");
 	}
 }
 
@@ -829,8 +822,8 @@
 	release_region(hw_config->io_base, 2);
 
 	/* Unload mixer */
-	if(opl3sa2_mixer[card] >= 0)
-		sound_unload_mixerdev(opl3sa2_mixer[card]);
+	if(opl3sa2_state[card].mixer >= 0)
+		sound_unload_mixerdev(opl3sa2_state[card].mixer);
 }
 
 
@@ -868,21 +861,21 @@
 	 */
 	ret = dev->prepare(dev);
 	if(ret && ret != -EBUSY) {
-		printk(KERN_ERR "opl3sa2: ISA PnP found device that could not be autoconfigured.\n");
+		printk(KERN_ERR PFX "ISA PnP found device that could not be autoconfigured.\n");
 		return -ENODEV;
 	}
 	if(ret == -EBUSY) {
-		opl3sa2_activated[card] = 1;
+		opl3sa2_state[card].activated = 1;
 	}
 	else {
 		if(dev->activate(dev) < 0) {
-			printk(KERN_WARNING "opl3sa2: ISA PnP activate failed\n");
-			opl3sa2_activated[card] = 0;
+			printk(KERN_WARNING PFX "ISA PnP activate failed\n");
+			opl3sa2_state[card].activated = 0;
 			return -ENODEV;
 		}
 
 		printk(KERN_DEBUG
-		       "opl3sa2: Activated ISA PnP card %d (active=%d)\n",
+		       PFX "Activated ISA PnP card %d (active=%d)\n",
 		       card, dev->active);
 
 	}
@@ -911,7 +904,7 @@
 	opl3sa2_clear_slots(mss_cfg);
 	opl3sa2_clear_slots(mpu_cfg);
 
-	opl3sa2_dev[card] = dev;
+	opl3sa2_state[card].pdev = dev;
 
 	return 0;
 }
@@ -919,11 +912,12 @@
 
 /* End of component functions */
 
+#ifdef CONFIG_PM
 /* Power Management support functions */
 static int opl3sa2_suspend(struct pm_dev *pdev, unsigned char pm_mode)
 {
 	unsigned long flags;
-	opl3sa2_mixerdata *p;
+	opl3sa2_state_t *p;
 
 	if (!pdev)
 		return -EINVAL;
@@ -931,7 +925,7 @@
 	save_flags(flags);
 	cli();
 
-	p = (opl3sa2_mixerdata *) pdev->data;
+	p = (opl3sa2_state_t *) pdev->data;
 
 	switch (pm_mode) {
 	case 1:
@@ -951,8 +945,7 @@
 
 	p->in_suspend = 1;
 	/* its supposed to automute before suspending, so we wont bother */
-	opl3sa2_read(p->cfg_port, OPL3SA2_PM, &p->pm_reg);
-	opl3sa2_write(p->cfg_port, OPL3SA2_PM, p->pm_reg | pm_mode);
+	opl3sa2_write(p->cfg_port, OPL3SA2_PM, pm_mode);
 	/* wait a while for the clock oscillator to stabilise */
 	mdelay(10);
 
@@ -963,18 +956,17 @@
 static int opl3sa2_resume(struct pm_dev *pdev)
 {
 	unsigned long flags;
-	opl3sa2_mixerdata *p;
+	opl3sa2_state_t *p;
 
 	if (!pdev)
 		return -EINVAL;
 
-	p = (opl3sa2_mixerdata *) pdev->data;
+	p = (opl3sa2_state_t *) pdev->data;
 	save_flags(flags);
 	cli();
 
-	/* I don't think this is necessary */
-	opl3sa2_write(p->cfg_port, OPL3SA2_PM, p->pm_reg);
-	opl3sa2_mixer_restore(p, p->card);
+	opl3sa2_write(p->cfg_port, OPL3SA2_PM, OPL3SA2_PM_MODE0);
+	opl3sa2_mixer_restore(p);
 	p->in_suspend = 0;
 
 	restore_flags(flags);
@@ -994,6 +986,7 @@
 	}
 	return 0;
 }
+#endif /* CONFIG_PM */
 
 /*
  * Install OPL3-SA2 based card(s).
@@ -1017,16 +1010,16 @@
 		 * should still be able to disable PNP support for this 
 		 * single driver!
 		 */
-		if(isapnp && opl3sa2_isapnp_probe(&cfg[card],
-						  &cfg_mss[card],
-						  &cfg_mpu[card],
+		if(isapnp && opl3sa2_isapnp_probe(&opl3sa2_state[card].cfg,
+						  &opl3sa2_state[card].cfg_mss,
+						  &opl3sa2_state[card].cfg_mpu,
 						  card) < 0) {
 			if(!opl3sa2_cards_num)
-				printk(KERN_INFO "opl3sa2: No PnP cards found\n");
+				printk(KERN_INFO PFX "No PnP cards found\n");
 			if(io == -1)
 				break;
 			isapnp=0;
-			printk(KERN_INFO "opl3sa2: Search for a card at 0x%d.\n", io);
+			printk(KERN_INFO PFX "Search for a card at 0x%d.\n", io);
 			/* Fall through */
 		}
 #endif
@@ -1036,7 +1029,7 @@
 			if(io == -1 || irq == -1 || dma == -1 ||
 			   dma2 == -1 || mss_io == -1) {
 				printk(KERN_ERR
-				       "opl3sa2: io, mss_io, irq, dma, and dma2 must be set\n");
+				       PFX "io, mss_io, irq, dma, and dma2 must be set\n");
 				return -EINVAL;
 			}
 
@@ -1045,31 +1038,31 @@
 			 * (NOTE: IRQ and DMA aren't used, so they're set to
 			 *  give pretty output from conf_printf. :)
 			 */
-			cfg[card].io_base = io;
-			cfg[card].irq     = irq;
-			cfg[card].dma     = dma;
-			cfg[card].dma2    = dma2;
+			opl3sa2_state[card].cfg.io_base = io;
+			opl3sa2_state[card].cfg.irq     = irq;
+			opl3sa2_state[card].cfg.dma     = dma;
+			opl3sa2_state[card].cfg.dma2    = dma2;
 	
 			/* The MSS config: */
-			cfg_mss[card].io_base      = mss_io;
-			cfg_mss[card].irq          = irq;
-			cfg_mss[card].dma          = dma;
-			cfg_mss[card].dma2         = dma2;
-			cfg_mss[card].card_subtype = 1; /* No IRQ or DMA setup */
-
-			cfg_mpu[card].io_base       = mpu_io;
-			cfg_mpu[card].irq           = irq;
-			cfg_mpu[card].dma           = -1;
-			cfg_mpu[card].always_detect = 1; /* Use shared IRQs */
+			opl3sa2_state[card].cfg_mss.io_base      = mss_io;
+			opl3sa2_state[card].cfg_mss.irq          = irq;
+			opl3sa2_state[card].cfg_mss.dma          = dma;
+			opl3sa2_state[card].cfg_mss.dma2         = dma2;
+			opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
+
+			opl3sa2_state[card].cfg_mpu.io_base       = mpu_io;
+			opl3sa2_state[card].cfg_mpu.irq           = irq;
+			opl3sa2_state[card].cfg_mpu.dma           = -1;
+			opl3sa2_state[card].cfg_mpu.always_detect = 1; /* Use shared IRQs */
 
 			/* Call me paranoid: */
-			opl3sa2_clear_slots(&cfg[card]);
-			opl3sa2_clear_slots(&cfg_mss[card]);
-			opl3sa2_clear_slots(&cfg_mpu[card]);
+			opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
+			opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
+			opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
 		}
 
-		if(!probe_opl3sa2(&cfg[card], card) ||
-		   !probe_opl3sa2_mss(&cfg_mss[card])) {
+		if(!probe_opl3sa2(&opl3sa2_state[card].cfg, card) ||
+		   !probe_opl3sa2_mss(&opl3sa2_state[card].cfg_mss)) {
 			/*
 			 * If one or more cards are already registered, don't
 			 * return an error but print a warning.  Note, this
@@ -1078,7 +1071,7 @@
 			 */
 			if(opl3sa2_cards_num) {
 				printk(KERN_WARNING
-				       "opl3sa2: There was a problem probing one "
+				       PFX "There was a problem probing one "
 				       " of the ISA PNP cards, continuing\n");
 				opl3sa2_cards_num--;
 				continue;
@@ -1086,47 +1079,51 @@
 				return -ENODEV;
 		}
 
-		attach_opl3sa2(&cfg[card], card);
-		conf_printf(chipset_name[card], &cfg[card]);
-		attach_opl3sa2_mss(&cfg_mss[card]);
-		attach_opl3sa2_mixer(&cfg[card], card);
+		attach_opl3sa2(&opl3sa2_state[card].cfg, card);
+		conf_printf(opl3sa2_state[card].chipset_name, &opl3sa2_state[card].cfg);
+		attach_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
+		attach_opl3sa2_mixer(&opl3sa2_state[card].cfg, card);
+
+		/* ewww =) */
+		opl3sa2_state[card].card = card;
 
-		opl3sa2_data[card].card = card;
+#ifdef CONFIG_PM
 		/* register our power management capabilities */
-		opl3sa2_data[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
-		if (opl3sa2_data[card].pmdev)
-			opl3sa2_data[card].pmdev->data = &opl3sa2_data[card];
+		opl3sa2_state[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
+		if (opl3sa2_state[card].pmdev)
+			opl3sa2_state[card].pmdev->data = &opl3sa2_state[card];
+#endif
 
 		/*
 		 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
 		 * it's supported.
 		 */
 		if(ymode != -1) {
-			if(chipset[card] == CHIPSET_OPL3SA2) {
+			if(opl3sa2_state[card].chipset == CHIPSET_OPL3SA2) {
 				printk(KERN_ERR
-				       "opl3sa2: ymode not supported on OPL3-SA2\n");
+				       PFX "ymode not supported on OPL3-SA2\n");
 			}
 			else {
-				opl3sa2_set_ymode(&cfg[card], ymode);
+				opl3sa2_set_ymode(&opl3sa2_state[card].cfg, ymode);
 			}
 		}
 
 
 		/* Set A/D input to Mono loopback if asked to. */
 		if(loopback != -1) {
-			opl3sa2_set_loopback(&cfg[card], loopback);
+			opl3sa2_set_loopback(&opl3sa2_state[card].cfg, loopback);
 		}
 		
 		/* Attach MPU if we've been asked to do so */
-		if(cfg_mpu[card].io_base != -1) {
-			if(probe_opl3sa2_mpu(&cfg_mpu[card])) {
-				attach_opl3sa2_mpu(&cfg_mpu[card]);
+		if(opl3sa2_state[card].cfg_mpu.io_base != -1) {
+			if(probe_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu)) {
+				attach_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
 			}
 		}
 	}
 
 	if(isapnp) {
-		printk(KERN_NOTICE "opl3sa2: %d PnP card(s) found.\n", opl3sa2_cards_num);
+		printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
 	}
 
 	return 0;
@@ -1141,22 +1138,23 @@
 	int card;
 
 	for(card = 0; card < opl3sa2_cards_num; card++) {
-		if (opl3sa2_data[card].pmdev)
-			pm_unregister(opl3sa2_data[card].pmdev);
-
-	        if(cfg_mpu[card].slots[1] != -1) {
-			unload_opl3sa2_mpu(&cfg_mpu[card]);
+#ifdef CONFIG_PM
+		if (opl3sa2_state[card].pmdev)
+			pm_unregister(opl3sa2_state[card].pmdev);
+#endif
+	        if(opl3sa2_state[card].cfg_mpu.slots[1] != -1) {
+			unload_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
 		}
-		unload_opl3sa2_mss(&cfg_mss[card]);
-		unload_opl3sa2(&cfg[card], card);
+		unload_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
+		unload_opl3sa2(&opl3sa2_state[card].cfg, card);
 
 #if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
-		if(opl3sa2_activated[card] && opl3sa2_dev[card]) {
-			opl3sa2_dev[card]->deactivate(opl3sa2_dev[card]);
+		if(opl3sa2_state[card].activated && opl3sa2_state[card].pdev) {
+			opl3sa2_state[card].pdev->deactivate(opl3sa2_state[card].pdev);
 
 			printk(KERN_DEBUG
-			       "opl3sa2: Deactivated ISA PnP card %d (active=%d)\n",
-			       card, opl3sa2_dev[card]->active);
+			       PFX "Deactivated ISA PnP card %d (active=%d)\n",
+			       card, opl3sa2_state[card].pdev->active);
 		}
 #endif
 	}
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/Config.in linux/drivers/video/Config.in
--- tmp/linux/drivers/video/Config.in	Mon Feb 25 20:28:50 2002
+++ linux/drivers/video/Config.in	Mon Feb 25 19:11:06 2002
@@ -26,6 +26,9 @@
 	    fi
 	 fi
       fi
+      if [ "$CONFIG_PCI" = "y" ]; then
+         tristate '  Permedia3 support (EXPERIMENTAL)' CONFIG_FB_PM3
+      fi
    fi
    if [ "$CONFIG_ARCH_ACORN" = "y" ]; then
       bool '  Acorn VIDC support' CONFIG_FB_ACORN
@@ -263,6 +266,7 @@
 	   "$CONFIG_FB_VALKYRIE" = "y" -o "$CONFIG_FB_PLATINUM" = "y" -o \
            "$CONFIG_FB_IGA" = "y" -o "$CONFIG_FB_MATROX" = "y" -o \
 	   "$CONFIG_FB_CT65550" = "y" -o "$CONFIG_FB_PM2" = "y" -o \
+           "$CONFIG_FB_PM3" = "y" -o \
 	   "$CONFIG_FB_P9100" = "y" -o "$CONFIG_FB_ATY128" = "y" -o \
 	   "$CONFIG_FB_RIVA" = "y" -o "$CONFIG_FB_RADEON" = "y" -o \
 	   "$CONFIG_FB_SGIVW" = "y" -o "$CONFIG_FB_CYBER2000" = "y" -o \
@@ -283,6 +287,7 @@
 	      "$CONFIG_FB_VALKYRIE" = "m" -o "$CONFIG_FB_PLATINUM" = "m" -o \
               "$CONFIG_FB_IGA" = "m" -o "$CONFIG_FB_MATROX" = "m" -o \
 	      "$CONFIG_FB_CT65550" = "m" -o "$CONFIG_FB_PM2" = "m" -o \
+              "$CONFIG_FB_PM3" = "m" -o \
 	      "$CONFIG_FB_P9100" = "m" -o "$CONFIG_FB_ATY128" = "m" -o \
 	      "$CONFIG_FB_RIVA" = "m" -o "$CONFIG_FB_3DFX" = "m" -o \
 	      "$CONFIG_FB_SGIVW" = "m" -o "$CONFIG_FB_CYBER2000" = "m" -o \
@@ -302,6 +307,7 @@
 	   "$CONFIG_FB_VALKYRIE" = "y" -o "$CONFIG_FB_PLATINUM" = "y" -o \
 	   "$CONFIG_FB_CT65550" = "y" -o "$CONFIG_FB_MATROX" = "y" -o \
 	   "$CONFIG_FB_PM2" = "y" -o "$CONFIG_FB_SGIVW" = "y" -o \
+           "$CONFIG_FB_PM3" = "y" -o \
 	   "$CONFIG_FB_RIVA" = "y" -o "$CONFIG_FB_ATY128" = "y" -o \
 	   "$CONFIG_FB_CYBER2000" = "y" -o "$CONFIG_FB_3DFX" = "y"  -o \
 	   "$CONFIG_FB_SIS" = "y" -o "$CONFIG_FB_SA1100" = "y" -o \
@@ -317,6 +323,7 @@
 	      "$CONFIG_FB_VALKYRIE" = "m" -o "$CONFIG_FB_PLATINUM" = "m" -o \
 	      "$CONFIG_FB_CT65550" = "m" -o "$CONFIG_FB_MATROX" = "m" -o \
 	      "$CONFIG_FB_PM2" = "m" -o "$CONFIG_FB_SGIVW" = "m" -o \
+              "$CONFIG_FB_PM3" = "m" -o \
 	      "$CONFIG_FB_RIVA" = "m" -o "$CONFIG_FB_ATY128" = "m" -o \
 	      "$CONFIG_FB_CYBER2000" = "m" -o "$CONFIG_FB_SIS" = "m" -o \
 	      "$CONFIG_FB_SA1100" = "m" -o "$CONFIG_FB_RADEON" = "m" -o \
@@ -346,6 +353,7 @@
 	   "$CONFIG_FB_CONTROL" = "y" -o "$CONFIG_FB_CLGEN" = "y" -o \
 	   "$CONFIG_FB_TGA" = "y" -o "$CONFIG_FB_PLATINUM" = "y" -o \
 	   "$CONFIG_FB_MATROX" = "y" -o "$CONFIG_FB_PM2" = "y" -o \
+           "$CONFIG_FB_PM3" = "y" -o \
 	   "$CONFIG_FB_RIVA" = "y" -o "$CONFIG_FB_ATY128" = "y" -o \
 	   "$CONFIG_FB_FM2" = "y" -o "$CONFIG_FB_SGIVW" = "y" -o \
 	   "$CONFIG_FB_RADEON" = "y" -o "$CONFIG_FB_PVR2" = "y" -o \
@@ -358,6 +366,7 @@
 	      "$CONFIG_FB_CONTROL" = "m" -o "$CONFIG_FB_CLGEN" = "m" -o \
 	      "$CONFIG_FB_TGA" = "m" -o "$CONFIG_FB_PLATINUM" = "m" -o \
 	      "$CONFIG_FB_MATROX" = "m" -o "$CONFIG_FB_PM2" = "m" -o \
+              "$CONFIG_FB_PM3" = "m" -o \
 	      "$CONFIG_FB_RIVA" = "m" -o "$CONFIG_FB_ATY128" = "m" -o \
 	      "$CONFIG_FB_3DFX" = "m" -o "$CONFIG_FB_RADEON" = "m" -o \
 	      "$CONFIG_FB_SGIVW" = "m" -o "$CONFIG_FB_SIS" = "m" -o \
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/Makefile linux/drivers/video/Makefile
--- tmp/linux/drivers/video/Makefile	Mon Feb 25 20:28:50 2002
+++ linux/drivers/video/Makefile	Mon Feb 25 19:11:06 2002
@@ -44,6 +44,7 @@
 obj-$(CONFIG_FB_ACORN)            += acornfb.o
 obj-$(CONFIG_FB_AMIGA)            += amifb.o
 obj-$(CONFIG_FB_PM2)              += pm2fb.o fbgen.o
+obj-$(CONFIG_FB_PM3)              += pm3fb.o fbgen.o
 obj-$(CONFIG_FB_APOLLO)           += dnfb.o
 obj-$(CONFIG_FB_Q40)              += q40fb.o
 obj-$(CONFIG_FB_ATARI)            += atafb.o
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/chipsfb.c linux/drivers/video/chipsfb.c
--- tmp/linux/drivers/video/chipsfb.c	Thu Sep 13 23:04:43 2001
+++ linux/drivers/video/chipsfb.c	Mon Feb 25 20:17:46 2002
@@ -79,7 +79,7 @@
 } while (0)
 #define read_ind(num, var, ap, dp)	do { \
 	outb((num), (ap)); var = inb((dp)); \
-} while (0);
+} while (0)
 
 /* extension registers */
 #define write_xr(num, val)	write_ind(num, val, 0x3d6, 0x3d7)
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/fbcon-cfb24.c linux/drivers/video/fbcon-cfb24.c
--- tmp/linux/drivers/video/fbcon-cfb24.c	Mon Oct 15 20:47:13 2001
+++ linux/drivers/video/fbcon-cfb24.c	Mon Feb 25 20:17:46 2002
@@ -76,14 +76,14 @@
 	out1 = (in1<<8)  | (in2>>16); \
 	out2 = (in2<<16) | (in3>>8); \
 	out3 = (in3<<24) | in4; \
-    } while (0);
+    } while (0)
 #elif defined(__LITTLE_ENDIAN)
 #define convert4to3(in1, in2, in3, in4, out1, out2, out3) \
     do { \
 	out1 = in1       | (in2<<24); \
 	out2 = (in2>> 8) | (in3<<16); \
 	out3 = (in3>>16) | (in4<< 8); \
-    } while (0);
+    } while (0)
 #else
 #error FIXME: No endianness??
 #endif
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/fbgen.c linux/drivers/video/fbgen.c
--- tmp/linux/drivers/video/fbgen.c	Sun Sep 30 19:26:08 2001
+++ linux/drivers/video/fbgen.c	Mon Feb 25 19:11:06 2002
@@ -106,6 +106,7 @@
     struct fb_info_gen *info2 = (struct fb_info_gen *)info;
     int err;
     int oldxres, oldyres, oldbpp, oldxres_virtual, oldyres_virtual, oldyoffset;
+    struct fb_bitfield oldred, oldgreen, oldblue;
 
     if ((err = fbgen_do_set_var(var, con == currcon, info2)))
 	return err;
@@ -115,12 +116,18 @@
 	oldxres_virtual = fb_display[con].var.xres_virtual;
 	oldyres_virtual = fb_display[con].var.yres_virtual;
 	oldbpp = fb_display[con].var.bits_per_pixel;
+	oldred = fb_display[con].var.red;
+	oldgreen = fb_display[con].var.green;
+	oldblue = fb_display[con].var.blue;
 	oldyoffset = fb_display[con].var.yoffset;
 	fb_display[con].var = *var;
 	if (oldxres != var->xres || oldyres != var->yres ||
 	    oldxres_virtual != var->xres_virtual ||
 	    oldyres_virtual != var->yres_virtual ||
 	    oldbpp != var->bits_per_pixel ||
+	    (!(memcmp(&oldred, &(var->red), sizeof(struct fb_bitfield)))) || 
+	    (!(memcmp(&oldgreen, &(var->green), sizeof(struct fb_bitfield)))) ||
+	    (!(memcmp(&oldblue, &(var->blue), sizeof(struct fb_bitfield)))) ||
 	    oldyoffset != var->yoffset) {
 	    fbgen_set_disp(con, info2);
 	    if (info->changevar)
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/fbmem.c linux/drivers/video/fbmem.c
--- tmp/linux/drivers/video/fbmem.c	Mon Feb 25 20:28:50 2002
+++ linux/drivers/video/fbmem.c	Mon Feb 25 19:11:06 2002
@@ -59,6 +59,8 @@
 extern int cyberfb_setup(char*);
 extern int pm2fb_init(void);
 extern int pm2fb_setup(char*);
+extern int pm3fb_init(void);
+extern int pm3fb_setup(char*);
 extern int cyber2000fb_init(void);
 extern int retz3fb_init(void);
 extern int retz3fb_setup(char*);
@@ -161,6 +163,9 @@
 #endif
 #ifdef CONFIG_FB_PM2
 	{ "pm2fb", pm2fb_init, pm2fb_setup },
+#endif
+#ifdef CONFIG_FB_PM3
+	{ "pm3fb", pm3fb_init, pm3fb_setup },
 #endif
 #ifdef CONFIG_FB_CLGEN
 	{ "clgen", clgenfb_init, clgenfb_setup },
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/pm3fb.c linux/drivers/video/pm3fb.c
--- tmp/linux/drivers/video/pm3fb.c	Thu Jan  1 00:00:00 1970
+++ linux/drivers/video/pm3fb.c	Mon Feb 25 19:11:06 2002
@@ -0,0 +1,3848 @@
+/*
+ *  linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device
+ *  
+ *  Copyright (C) 2001 Romain Dolbeau <dolbeau@irisa.fr>
+ *  Based on code written by:
+ *           Sven Luther, <luther@dpt-info.u-strasbg.fr>
+ *           Alan Hourihane, <alanh@fairlite.demon.co.uk>
+ *           Russel King, <rmk@arm.linux.org.uk>
+ *  Based on linux/drivers/video/skeletonfb.c:
+ *	Copyright (C) 1997 Geert Uytterhoeven
+ *  Based on linux/driver/video/pm2fb.c:
+ *      Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
+ *      Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License. See the file COPYING in the main directory of this archive for
+ *  more details.
+ *
+ *  $Header: /cvsroot/linux/drivers/video/pm3fb.c,v 1.1 2002/02/25 19:11:06 marcelo Exp $
+ *
+ *  CHANGELOG:
+ *  Mon Feb 11 10:35:48 MET 2002, v 1.4.11B: Cosmetic update.
+ *  Wed Jan 23 14:16:59 MET 2002, v 1.4.11: Preliminary 2.5.x support, patch for 2.5.2.
+ *  Wed Nov 28 11:08:29 MET 2001, v 1.4.10: potential bug fix for SDRAM-based board, patch for 2.4.16.
+ *  Thu Sep 20 10:24:42 MET DST 2001, v 1.4.9: sync bug fix, preliminary flatpanel support, better timings.
+ *  Tue Aug 28 10:13:01 MET DST 2001, v 1.4.8: memory timings check, minor bug fixes.
+ *  Wed Jul 18 19:06:14 CEST 2001, v 1.4.7: Mode fix (800x600-100, 1024x768-100 changed), using HW panning + accel bug fix.
+ *  Mon Jun 25 10:33:56 MET DST 2001, v 1.4.6: Depth 12 fix, chip reset ioctl, moved memory erase ioctl to DEBUG.
+ *  Wed Jun 20 11:13:08 MET DST 2001, v 1.4.5: Fixed missing blinking cursor in 8bpp, code cleaning, memory erase IOCTL.
+ *  Mon Jun 18 16:00:27 CEST 2001, v 1.4.4: Depth 12 (RGBA 4444) support, code cleaning.
+ *  Fri Jun 15 13:53:01 CEST 2001, v 1.4.3: Removed warnings, depth 15 support, add 'depth' option.
+ *  Thu Jun 14 10:13:52 MET DST 2001, v 1.4.2: Fixed depth switching bug, preliminary 15bpp (RGB5551) support.
+ *  Thu Apr 12 11:16:45 MET DST 2001, v 1.4.1B: Doc updates.
+ *  Fri Apr  6 11:12:53 MET DST 2001, v 1.4.1: Configure.help, minor cleanup
+ *  Thu Mar 29 10:56:50 MET DST 2001, v 1.4.0: Module & module options support (note: linux patch changed, 2.2.19 added).
+ *  Thu Mar 15 15:30:31 MET 2001, v 1.3.2: Fixed mirroring bug on little-endian.
+ *  Wed Mar 14 21:25:54 CET 2001, v 1.3.1: Fixed bug in BlockMove (_bmov).
+ *  Tue Mar 13 10:53:19 MET 2001, v 1.3.0: Character drawing hardware support (in all width between 1 and 16), fixes.
+ *  Thu Mar  8 10:20:16 MET 2001, v 1.2.2: Better J2000 support, "font:" option.
+ *  Tue Mar  6 21:25:04 CET 2001, v 1.2.1: Better acceleration support.
+ *  Mon Mar  5 21:54:17 CET 2001, v 1.2.0: Partial acceleration support (clear & bmove)
+ *  Mon Mar  5 12:52:15 CET 2001, v 1.1.3: Big pan_display fix.
+ *  Sun Mar  4 22:21:50 CET 2001, v 1.1.2: (numerous) bug fixes.
+ *  Fri Mar  2 15:54:07 CET 2001, v 1.1.1: Might have Appian J2000 support, resource mangement in 2.4
+ *  Wed Feb 28 18:21:35 CET 2001, v 1.1.0: Might have multiple boards support (added, but not yest tested)
+ *  Tue Feb 27 17:31:12 CET 2001, v 1.0.6: fixes boot-time mode select, add more default mode
+ *  Tue Feb 27 14:01:36 CET 2001, v 1.0.5: fixes (1.0.4 was broken for 2.2), cleaning up
+ *  Mon Feb 26 23:17:36 CET 2001, v 1.0.4: preliminary 2.4.x support, dropped (useless on pm3) partial product, more OF fix
+ *  Mon Feb 26 20:59:05 CET 2001, v 1.0.3: No more shadow register (and wasted memory), endianess fix, use OF-preset resolution by default
+ *  Wed Feb 21 22:09:30 CET 2001, v 1.0.2: Code cleaning for future multiboard support, better OF support, bugs fix
+ *  Wed Feb 21 19:58:56 CET 2001, v 1.0.1: OpenFirmware support, fixed memory detection, better debug support, code cleaning
+ *  Wed Feb 21 14:47:06 CET 2001, v 1.0.0: First working version
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/tty.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/fb.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/ioport.h>
+
+#include <video/fbcon.h>
+#include <video/fbcon-mfb.h>
+#include <video/fbcon-cfb2.h>
+#include <video/fbcon-cfb4.h>
+#include <video/fbcon-cfb8.h>
+#include <video/fbcon-cfb16.h>
+#include <video/fbcon-cfb24.h>
+#include <video/fbcon-cfb32.h>
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+
+#ifdef CONFIG_FB_OF
+#include <asm/prom.h>
+#endif
+
+#include "pm3fb.h"
+
+/* ************************************* */
+/* ***** The various "global" data ***** */
+/* ************************************* */
+
+/* those will need a rework for multiple board support */
+/* Driver name */
+static const char permedia3_name[16] = "Permedia3";
+
+/* the fb_par struct, mandatory */
+struct pm3fb_par {
+	u32 pixclock;		/* pixclock in KHz */
+
+	u32 width;		/* width of virtual screen */
+	u32 height;		/* height of virtual screen */
+
+	u32 hsstart;		/* horiz. sync start */
+	u32 hsend;		/* horiz. sync end */
+	u32 hbend;		/* horiz. blank end (also gate end) */
+	u32 htotal;		/* total width (w/ sync & blank) */
+
+	u32 vsstart;		/* vert. sync start */
+	u32 vsend;		/* vert. sync end */
+	u32 vbend;		/* vert. blank end */
+	u32 vtotal;		/* total height (w/ sync & blank) */
+
+	u32 stride;		/* screen stride */
+	u32 base;		/* screen base (xoffset+yoffset) in 128 bits unit */
+	/* NOTE : unlike other pm3 stuff above, stored *after* shiftbpp. don't ask */
+	u32 depth;		/* screen depth (8, 12, 15, 16 or 32) */
+	u32 video;		/* video control (hsync,vsync) */
+};
+
+/* memory timings */
+struct pm3fb_timings
+{
+	unsigned long caps;
+	unsigned long timings;
+	unsigned long control;
+	unsigned long refresh;
+	unsigned long powerdown;
+};
+typedef enum pm3fb_timing_result { pm3fb_timing_ok, pm3fb_timing_problem, pm3fb_timing_retry } pm3fb_timing_result;
+#define PM3FB_UNKNOWN_TIMING_VALUE ((unsigned long)-1)
+#define PM3FB_UNKNOWN_TIMINGS { PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE }
+
+/* the fb_info struct, mandatory */
+struct pm3fb_info {
+	struct fb_info_gen gen;
+	unsigned long board_num; /* internal board number */
+	unsigned long use_current;
+	struct pm3fb_par *current_par;
+	struct pci_dev *dev;    /* PCI device */
+#ifdef SUPPORT_FB_OF
+	struct device_node *dn; /* OF node for the PCI device */
+#endif /* SUPPORT_FB_OF */
+	unsigned long board_type; /* index in the cardbase */
+	unsigned char *fb_base;	/* framebuffer memory base */
+	u32 fb_size;		/* framebuffer memory size */
+	unsigned char *p_fb;	/* physical address of frame buffer */
+	unsigned char *v_fb;	/* virtual address of frame buffer */
+	unsigned char *pIOBase;	/* physical address of registers region, must be rg_base or rg_base+PM2_REGS_SIZE depending on the host endianness */
+	unsigned char *vIOBase;	/* address of registers after ioremap() */
+	struct {
+		u8 transp;
+		u8 red;
+		u8 green;
+		u8 blue;
+	} palette[256];
+	union {
+#ifdef FBCON_HAS_CFB16
+		u16 cmap12[16]; /* RGBA 4444 */
+		u16 cmap15[16]; /* RGBA 5551 */
+		u16 cmap16[16]; /* RGBA 5650 */
+#endif
+#ifdef FBCON_HAS_CFB32
+		u32 cmap32[16];
+#endif
+	} cmap;
+	struct pm3fb_timings memt;
+};
+
+/* regular resolution database*/
+static struct {
+	char name[16];
+	struct pm3fb_par user_mode;
+} mode_base[] __initdata = {
+	{
+		"default-800x600", {
+	49500, 800, 600, 16, 96, 256, 1056, 1, 4, 25, 625,
+			    800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}}, {
+		"1024x768-74", {
+	78752, 1024, 768, 32, 128, 304, 1328, 1, 4, 38,
+			    806, 1024, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}}, {
+		"1024x768-74-32", {
+			78752, 1024, 768, 32, 128, 304, 1328, 1, 4, 38,
+			806, 1024, 0, 32,
+			PM3VideoControl_ENABLE |
+			PM3VideoControl_HSYNC_ACTIVE_HIGH
+			|
+			PM3VideoControl_VSYNC_ACTIVE_HIGH
+			| PM3VideoControl_PIXELSIZE_32BIT}},
+/* Generated mode : "1600x1024", for the SGI 1600SW flat panel*/
+	{
+		"SGI1600SW", {
+			108000, 1600, 1024, 16, 56, 104, 1704, 3, 6, 32,
+			1056, 1600, 0, 8,
+			PM3VideoControl_ENABLE|
+			PM3VideoControl_HSYNC_ACTIVE_LOW|PM3VideoControl_VSYNC_ACTIVE_LOW|
+			PM3VideoControl_PIXELSIZE_32BIT}}, 
+/* ##### auto-generated mode, by fbtimings2pm3 */
+/* Generated mode : "640x480-60" */
+	{
+		"640x480-60", {
+	25174, 640, 480, 16, 112, 160, 800, 10, 12, 45,
+			    525, 640, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "640x480-72" */
+	{
+		"640x480-72", {
+	31199, 640, 480, 24, 64, 192, 832, 9, 12, 40, 520,
+			    640, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "640x480-75" */
+	{
+		"640x480-75", {
+	31499, 640, 480, 16, 80, 200, 840, 1, 4, 20, 500,
+			    640, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "640x480-90" */
+	{
+		"640x480-90", {
+	39909, 640, 480, 32, 72, 192, 832, 25, 39, 53, 533,
+			    640, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "640x480-100" */
+	{
+		"640x480-100", {
+	44899, 640, 480, 32, 160, 208, 848, 22, 34, 51,
+			    531, 640, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-48-lace" */
+/* INTERLACED NOT SUPPORTED
+  {"800x600-48-lace", {35999, 800, 600, 80, 208, 264, 1064, 11, 23, 102, 702, 800, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}}, 
+   INTERLACED NOT SUPPORTED */
+/* Generated mode : "800x600-56" */
+	{
+		"800x600-56", {
+	35999, 800, 600, 24, 96, 224, 1024, 1, 3, 25, 625,
+			    800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-60" */
+	{
+		"800x600-60", {
+	40000, 800, 600, 40, 168, 256, 1056, 1, 5, 28, 628,
+			    800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-70" */
+	{
+		"800x600-70", {
+	44899, 800, 600, 24, 168, 208, 1008, 9, 21, 36,
+			    636, 800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-72" */
+	{
+		"800x600-72", {
+	50000, 800, 600, 56, 176, 240, 1040, 37, 43, 66,
+			    666, 800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-75" */
+	{
+		"800x600-75", {
+	49497, 800, 600, 16, 96, 256, 1056, 1, 4, 25, 625,
+			    800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-90" */
+	{
+		"800x600-90", {
+	56637, 800, 600, 8, 72, 192, 992, 8, 19, 35, 635,
+			    800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "800x600-100", from /etc/fb.modes */
+/* DISABLED, hsstart == 0
+	{
+		"800x600-100", {
+	67499, 800, 600, 0, 64, 280, 1080, 7, 11, 25, 625,
+			    800, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+*/
+/* Generated mode : "800x600-100", from ??? */
+	{
+		"800x600-100", {
+			69650, 800, 600, 64, 128, 288, 1088, 4, 10, 40, 640, 800, 0, 8,
+			PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_LOW|
+			PM3VideoControl_VSYNC_ACTIVE_LOW|PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1024x768-43-lace" */
+/* INTERLACED NOT SUPPORTED
+  {"1024x768-43-lace", {44899, 1024, 768, 8, 184, 240, 1264, 1, 9, 49, 817, 1024, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}}, 
+   INTERLACED NOT SUPPORTED */
+/* Generated mode : "1024x768-60" */
+	{
+		"1024x768-60", {
+	64998, 1024, 768, 24, 160, 320, 1344, 3, 9, 38,
+			    806, 1024, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1024x768-70" */
+	{
+		"1024x768-70", {
+	74996, 1024, 768, 24, 160, 304, 1328, 3, 9, 38,
+			    806, 1024, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1024x768-72" */
+	{
+		"1024x768-72", {
+	74996, 10224, 768, 24, 160, 264, 10488, 3, 9, 38,
+			    806, 10224, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1024x768-75" */
+	{
+		"1024x768-75", {
+	78746, 1024, 768, 16, 112, 288, 1312, 1, 4, 32,
+			    800, 1024, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1024x768-90" */
+	{
+		"1024x768-90", {
+	100000, 1024, 768, 0, 96, 288, 1312, 21, 36, 77,
+			    845, 1024, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1024x768-100", from /etc/fb.modes */
+/* DISABLED, vsstart == 0
+	{
+		"1024x768-100", {
+	109998, 1024, 768, 0, 88, 368, 1392, 0, 8, 24, 792,
+			    1024, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+*/
+/* Generated mode : "1024x768-100", from ??? */
+	{
+		"1024x768-100", {
+			115500, 1024, 768, 32, 224, 416, 1440, 3, 13, 34, 802, 1024, 0, 8,
+			PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_LOW|
+			PM3VideoControl_VSYNC_ACTIVE_LOW|PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1152x864-43-lace" */
+/* INTERLACED NOT SUPPORTED
+  {"1152x864-43-lace", {64998, 1152, 864, 72, 200, 264, 1416, 78, 87, 191, 1055, 1152, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}}, 
+   INTERLACED NOT SUPPORTED */
+/* Generated mode : "1152x864-47-lace" */
+/* INTERLACED NOT SUPPORTED
+  {"1152x864-47-lace", {64998, 1152, 864, 88, 216, 296, 1448, 30, 39, 83, 947, 1152, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}}, 
+   INTERLACED NOT SUPPORTED */
+/* Generated mode : "1152x864-60" */
+	{
+		"1152x864-60", {
+	80000, 1152, 864, 64, 176, 304, 1456, 6, 11, 52,
+			    916, 1152, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1152x864-70" */
+	{
+		"1152x864-70", {
+	100000, 1152, 864, 40, 192, 360, 1512, 13, 24, 81,
+			    945, 1152, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1152x864-75" */
+	{
+		"1152x864-75", {
+	109998, 1152, 864, 24, 168, 312, 1464, 45, 53, 138,
+			    1002, 1152, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1152x864-80" */
+	{
+		"1152x864-80", {
+	109998, 1152, 864, 16, 128, 288, 1440, 30, 37, 94,
+			    958, 1152, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1280x1024-43-lace" */
+/* INTERLACED NOT SUPPORTED
+  {"1280x1024-43-lace", {80000, 1024, 1024, 80, 160, 320, 1344, 50, 60, 125, 1149, 1024, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}}, 
+   INTERLACED NOT SUPPORTED */
+/* Generated mode : "1280x1024-47-lace" */
+/* INTERLACED NOT SUPPORTED
+  {"1280x1024-47-lace", {80000, 1280, 1024, 80, 160, 320, 1600, 1, 11, 29, 1053, 1280, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}}, 
+   INTERLACED NOT SUPPORTED */
+/* Generated mode : "1280x1024-60" */
+	{
+		"1280x1024-60", {
+	107991, 1280, 1024, 48, 160, 408, 1688, 1, 4, 42,
+			    1066, 1280, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1280x1024-70" */
+	{
+		"1280x1024-70", {
+	125992, 1280, 1024, 80, 192, 408, 1688, 1, 6, 42,
+			    1066, 1280, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1280x1024-74" */
+	{
+		"1280x1024-74", {
+	134989, 1280, 1024, 32, 176, 432, 1712, 0, 30, 40,
+			    1064, 1280, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1280x1024-75" */
+	{
+		"1280x1024-75", {
+	134989, 1280, 1024, 16, 160, 408, 1688, 1, 4, 42,
+			    1066, 1280, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_HIGH
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_HIGH
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1600x1200-60" */
+	{
+		"1600x1200-60", {
+	155981, 1600, 1200, 32, 192, 448, 2048, 10, 18, 70,
+			    1270, 1600, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1600x1200-66" */
+	{
+		"1600x1200-66", {
+	171998, 1600, 1200, 40, 176, 480, 2080, 3, 6, 53,
+			    1253, 1600, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* Generated mode : "1600x1200-76" */
+	{
+		"1600x1200-76", {
+	197980, 1600, 1200, 40, 176, 480, 2080, 3, 8, 50,
+			    1250, 1600, 0, 8,
+			    PM3VideoControl_ENABLE |
+			    PM3VideoControl_HSYNC_ACTIVE_LOW
+			    |
+			    PM3VideoControl_VSYNC_ACTIVE_LOW
+			    | PM3VideoControl_PIXELSIZE_8BIT}},
+/* ##### end of auto-generated mode */
+	{
+	"\0",}
+};
+
+/* more mandatory stuff (see skeletonfb.c + framebuffer driver HOWTO */
+static struct pm3fb_info fb_info[PM3_MAX_BOARD];
+static struct pm3fb_par current_par[PM3_MAX_BOARD];
+static int current_par_valid[PM3_MAX_BOARD];
+/* to allow explicit filtering of board */
+short bus[PM3_MAX_BOARD];
+short slot[PM3_MAX_BOARD];
+short func[PM3_MAX_BOARD];
+short disable[PM3_MAX_BOARD];
+short noaccel[PM3_MAX_BOARD];
+char fontn[PM3_MAX_BOARD][PM3_FONTNAME_SIZE];
+short depth[PM3_MAX_BOARD];
+short flatpanel[PM3_MAX_BOARD];
+static struct display disp[PM3_MAX_BOARD];
+static char g_options[PM3_OPTIONS_SIZE] __initdata = "pm3fb,dummy";
+short printtimings = 0;
+short forcesize[PM3_MAX_BOARD];
+
+/* ********************* */
+/* ***** prototype ***** */
+/* ********************* */
+/* card-specific */
+static void pm3fb_j2000_setup(struct pm3fb_info *l_fb_info);
+/* permedia3-specific */
+static pm3fb_timing_result pm3fb_preserve_memory_timings(struct pm3fb_info *l_fb_info);
+static pm3fb_timing_result pm3fb_try_memory_timings(struct pm3fb_info *l_fb_info);
+static void pm3fb_write_memory_timings(struct pm3fb_info *l_fb_info);
+static unsigned long pm3fb_read_dac_reg(struct pm3fb_info *l_fb_info,
+					unsigned long r);
+static unsigned long pm3fb_CalculateClock(struct pm3fb_info *l_fb_info, unsigned long reqclock,	/* In kHz units */
+					  unsigned long refclock,	/* In kHz units */
+					  unsigned char *prescale,	/* ClkPreScale */
+					  unsigned char *feedback,	/* ClkFeedBackScale */
+					  unsigned char *postscale
+					  /* ClkPostScale */ );
+static void pm3fb_clear_memory(struct pm3fb_info *l_fb_info, u32 cc);
+static void pm3fb_clear_colormap(struct pm3fb_info *l_fb_info, unsigned char r, unsigned char g, unsigned char b);
+static void pm3fb_common_init(struct pm3fb_info *l_fb_info);
+static int pm3fb_Shiftbpp(struct pm3fb_info *l_fb_info,
+			  unsigned long depth, int v);
+static int pm3fb_Unshiftbpp(struct pm3fb_info *l_fb_info,
+			    unsigned long depth, int v);
+static void pm3fb_mapIO(struct pm3fb_info *l_fb_info);
+static void pm3fb_unmapIO(struct pm3fb_info *l_fb_info);
+#if defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2)
+static void pm3fb_show_cur_mode(struct pm3fb_info *l_fb_info);
+#endif
+static void pm3fb_show_cur_timing(struct pm3fb_info *l_fb_info);
+static void pm3fb_write_mode(struct pm3fb_info *l_fb_info);
+static void pm3fb_read_mode(struct pm3fb_info *l_fb_info,
+			    struct pm3fb_par *curpar);
+static unsigned long pm3fb_size_memory(struct pm3fb_info *l_fb_info);
+/* accelerated permedia3-specific */
+#ifdef PM3FB_USE_ACCEL
+static void pm3fb_wait_pm3(struct pm3fb_info *l_fb_info);
+static void pm3fb_init_engine(struct pm3fb_info *l_fb_info);
+#ifdef FBCON_HAS_CFB32
+static void pm3fb_cfb32_clear(struct vc_data *conp,
+			      struct display *p,
+			      int sy, int sx, int height, int width);
+static void pm3fb_cfb32_clear_margins(struct vc_data *conp,
+				      struct display *p, int bottom_only);
+#endif /* FBCON_HAS_CFB32 */
+#ifdef FBCON_HAS_CFB16
+static void pm3fb_cfb16_clear(struct vc_data *conp,
+			      struct display *p,
+			      int sy, int sx, int height, int width);
+static void pm3fb_cfb16_clear_margins(struct vc_data *conp,
+				      struct display *p, int bottom_only);
+#endif /* FBCON_HAS_CFB16 */
+#ifdef FBCON_HAS_CFB8
+static void pm3fb_cfb8_clear(struct vc_data *conp,
+			     struct display *p,
+			     int sy, int sx, int height, int width);
+static void pm3fb_cfb8_clear_margins(struct vc_data *conp,
+				     struct display *p, int bottom_only);
+#endif /* FBCON_HAS_CFB8 */
+#if defined(FBCON_HAS_CFB8) || defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
+static void pm3fb_cfbX_bmove(struct display *p,
+			     int sy, int sx,
+			     int dy, int dx, int height, int width);
+static void pm3fb_cfbX_putc(struct vc_data *conp, struct display *p,
+			    int c, int yy, int xx);
+static void pm3fb_cfbX_putcs(struct vc_data *conp, struct display *p,
+			     const unsigned short *s, int count, int yy,
+			     int xx);
+static void pm3fb_cfbX_revc(struct display *p, int xx, int yy);
+#endif /* FBCON_HAS_CFB8 || FBCON_HAS_CFB16 || FBCON_HAS_CFB32 */
+#endif /* PM3FB_USE_ACCEL */
+/* pre-init */
+static void pm3fb_mode_setup(char *mode, unsigned long board_num);
+static void pm3fb_pciid_setup(char *pciid, unsigned long board_num);
+static char *pm3fb_boardnum_setup(char *options, unsigned long *bn);
+static void pm3fb_real_setup(char *options);
+/* fbdev */
+static int pm3fb_open(struct fb_info *info, int user);
+static int pm3fb_release(struct fb_info *info, int user);
+static int pm3fb_encode_fix(struct fb_fix_screeninfo *fix,
+			    const void *par, struct fb_info_gen *info);
+static int pm3fb_decode_var(const struct fb_var_screeninfo *var,
+			    void *par, struct fb_info_gen *info);
+static void pm3fb_encode_depth(struct fb_var_screeninfo *var, long d);
+static int pm3fb_encode_var(struct fb_var_screeninfo *var,
+			    const void *par, struct fb_info_gen *info);
+static void pm3fb_get_par(void *par, struct fb_info_gen *info);
+static void pm3fb_set_par(const void *par, struct fb_info_gen *info);
+static void pm3fb_set_color(struct pm3fb_info *l_fb_info,
+			    unsigned char regno, unsigned char r,
+			    unsigned char g, unsigned char b);
+static int pm3fb_getcolreg(unsigned regno, unsigned *red, unsigned *green,
+			   unsigned *blue, unsigned *transp,
+			   struct fb_info *info);
+static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
+			   unsigned blue, unsigned transp,
+			   struct fb_info *info);
+static int pm3fb_blank(int blank_mode, struct fb_info_gen *info);
+static void pm3fb_set_disp(const void *par, struct display *disp,
+			   struct fb_info_gen *info);
+static void pm3fb_detect(void);
+static int pm3fb_pan_display(const struct fb_var_screeninfo *var,
+			     struct fb_info_gen *info);
+static int pm3fb_ioctl(struct inode *inode, struct file *file,
+                       u_int cmd, u_long arg, int con,
+		       struct fb_info *info);
+
+
+/* the struct that hold them together */
+#ifdef KERNEL_2_2
+struct fbgen_hwswitch pm3fb_switch = {
+	pm3fb_detect, pm3fb_encode_fix, pm3fb_decode_var, pm3fb_encode_var,
+	pm3fb_get_par, pm3fb_set_par, pm3fb_getcolreg, pm3fb_setcolreg,
+	pm3fb_pan_display, pm3fb_blank, pm3fb_set_disp
+};
+
+static struct fb_ops pm3fb_ops = {
+	pm3fb_open, pm3fb_release,
+	fbgen_get_fix, fbgen_get_var, fbgen_set_var,
+	fbgen_get_cmap, fbgen_set_cmap, fbgen_pan_display, pm3fb_ioctl,
+	    NULL, NULL
+};
+#endif /* KERNEL_2_2 */
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+struct fbgen_hwswitch pm3fb_switch = {
+	pm3fb_detect, pm3fb_encode_fix, pm3fb_decode_var, pm3fb_encode_var,
+	pm3fb_get_par, pm3fb_set_par, pm3fb_getcolreg, pm3fb_setcolreg,
+	pm3fb_pan_display, pm3fb_blank, pm3fb_set_disp
+};
+
+static struct fb_ops pm3fb_ops = {
+	THIS_MODULE,
+	pm3fb_open, pm3fb_release,
+	fbgen_get_fix, fbgen_get_var, fbgen_set_var,
+	fbgen_get_cmap, fbgen_set_cmap, fbgen_pan_display, pm3fb_ioctl, NULL, NULL
+};
+#endif /* KERNEL_2_4 or KERNEL_2_5 */
+#ifdef PM3FB_USE_ACCEL
+#ifdef FBCON_HAS_CFB32
+static struct display_switch pm3fb_cfb32 = {
+	fbcon_cfb32_setup, pm3fb_cfbX_bmove, pm3fb_cfb32_clear,
+	pm3fb_cfbX_putc, pm3fb_cfbX_putcs, pm3fb_cfbX_revc,
+	NULL /* cursor() */ , NULL /* set_font() */ ,
+	pm3fb_cfb32_clear_margins,
+	FONTWIDTHRANGE(1, 16)	/* true only if accelerated... */
+};
+#endif /* FBCON_HAS_CFB32 */
+#ifdef FBCON_HAS_CFB16
+static struct display_switch pm3fb_cfb16 = {
+	fbcon_cfb16_setup, pm3fb_cfbX_bmove, pm3fb_cfb16_clear,
+	pm3fb_cfbX_putc, pm3fb_cfbX_putcs, pm3fb_cfbX_revc,
+	NULL /* cursor() */ , NULL /* set_font() */ ,
+	pm3fb_cfb16_clear_margins,
+	FONTWIDTHRANGE(1, 16)	/* true only if accelerated... */
+};
+#endif /* FBCON_HAS_CFB16 */
+#ifdef FBCON_HAS_CFB8
+static struct display_switch pm3fb_cfb8 = {
+	fbcon_cfb8_setup, pm3fb_cfbX_bmove, pm3fb_cfb8_clear,
+	pm3fb_cfbX_putc, pm3fb_cfbX_putcs, pm3fb_cfbX_revc,
+	NULL /* cursor() */ , NULL /* set_font() */ ,
+	pm3fb_cfb8_clear_margins,
+	FONTWIDTHRANGE(1, 16)	/* true only if accelerated... */
+};
+#endif /* FBCON_HAS_CFB8 */
+#endif /* PM3FB_USE_ACCEL */
+
+/* ****************************** */
+/* ***** card-specific data ***** */
+/* ****************************** */
+struct pm3fb_card_timings {
+	unsigned long memsize; /* 0 for last value (i.e. default) */
+	struct pm3fb_timings memt;
+};
+
+static struct pm3fb_card_timings t_FormacProFormance3[] = {
+	{ 16, { 0x02e311b8, 0x06100205, 0x08000002, 0x00000079, 0x00000000} },
+	{ 0, { 0x02e311b8, 0x06100205, 0x08000002, 0x00000079, 0x00000000} } /* from 16 MB PF3 */
+};
+
+static struct pm3fb_card_timings t_AppianJeronimo2000[] = {
+	{ 32, { 0x02e311B8, 0x07424905, 0x0c000003, 0x00000061, 0x00000000} },
+	{ 0, { 0x02e311B8, 0x07424905, 0x0c000003, 0x00000061, 0x00000000} } /* from 32MB J2000 */
+};
+
+static struct pm3fb_card_timings t_3DLabsOxygenVX1[] = {
+	{ 32, { 0x30e311b8, 0x08501204, 0x08000002, 0x0000006b, 0x00000000} },
+	{ 0, { 0x30e311b8, 0x08501204, 0x08000002, 0x0000006b, 0x00000000} } /* from 32MB VX1 */
+};
+
+static struct {
+		char cardname[32]; /* recognized card name */
+		u16 subvendor; /* subvendor of the card */
+		u16 subdevice; /* subdevice of the card */
+		u8  func; /* function of the card to which the extra init apply */
+		void (*specific_setup)(struct pm3fb_info *l_fb_info); /* card/func specific setup, done before _any_ FB access */
+	struct pm3fb_card_timings *c_memt; /* defauls timings for the boards */
+} cardbase[] = {
+	{ "Unknown Permedia3 board", 0xFFFF, 0xFFFF, 0xFF, NULL, NULL },
+	{ "Appian Jeronimo 2000 head 1", 0x1097, 0x3d32, 1, NULL,
+	  t_AppianJeronimo2000
+	},
+	{ "Appian Jeronimo 2000 head 2", 0x1097, 0x3d32, 2, pm3fb_j2000_setup,
+	  t_AppianJeronimo2000
+	},
+	{ "Formac ProFormance 3", PCI_VENDOR_ID_3DLABS, 0x000a, 0, NULL, /* Formac use 3DLabs ID ?!? */
+	  t_FormacProFormance3
+	},
+	{ "3DLabs Permedia3 Create!", PCI_VENDOR_ID_3DLABS, 0x0127, 0, NULL, NULL },
+	{ "3DLabs Oxygen VX1 PCI", PCI_VENDOR_ID_3DLABS, 0x0121, 0, NULL,
+	  t_3DLabsOxygenVX1
+	},
+	{ "3DLabs Oxygen VX1 AGP", PCI_VENDOR_ID_3DLABS, 0x0125, 0, NULL, NULL },
+	{ "3DLabs Oxygen VX1-16 AGP", PCI_VENDOR_ID_3DLABS, 0x0140, 0, NULL, NULL },
+	{ "3DLabs Oxygen VX1-1600SW PCI", PCI_VENDOR_ID_3DLABS, 0x0800, 0, NULL, NULL },
+	{ "\0", 0x0, 0x0, 0, NULL, NULL }
+};
+
+/* ********************************** */
+/* ***** card-specific function ***** */
+/* ********************************** */
+static void pm3fb_j2000_setup(struct pm3fb_info *l_fb_info)
+{       /* the appian j2000 require more initialization of the second head */
+	/* l_fb_info must point to the _second_ head of the J2000 */
+	
+	DTRACE;
+
+	l_fb_info->memt = t_AppianJeronimo2000[0].memt; /* 32 MB, first and only j2000 ? */
+	
+	pm3fb_write_memory_timings(l_fb_info);
+}
+
+/* *************************************** */
+/* ***** permedia3-specific function ***** */
+/* *************************************** */
+static pm3fb_timing_result pm3fb_preserve_memory_timings(struct pm3fb_info *l_fb_info)
+{
+	l_fb_info->memt.caps = PM3_READ_REG(PM3LocalMemCaps);
+	l_fb_info->memt.timings = PM3_READ_REG(PM3LocalMemTimings);
+	l_fb_info->memt.control = PM3_READ_REG(PM3LocalMemControl);
+	l_fb_info->memt.refresh = PM3_READ_REG(PM3LocalMemRefresh);
+	l_fb_info->memt.powerdown = PM3_READ_REG(PM3LocalMemPowerDown);
+
+	if ((l_fb_info->memt.caps == PM3FB_UNKNOWN_TIMING_VALUE) ||
+	    (l_fb_info->memt.timings == PM3FB_UNKNOWN_TIMING_VALUE) ||
+	    (l_fb_info->memt.control == PM3FB_UNKNOWN_TIMING_VALUE) ||
+	    (l_fb_info->memt.refresh == PM3FB_UNKNOWN_TIMING_VALUE) ||
+	    (l_fb_info->memt.powerdown == PM3FB_UNKNOWN_TIMING_VALUE))
+	{
+		printk(KERN_ERR "pm3fb: invalid memory timings in permedia3 board #%ld\n", l_fb_info->board_num);
+		return(pm3fb_try_memory_timings(l_fb_info));
+	}
+	return(pm3fb_timing_ok);
+}
+
+static pm3fb_timing_result pm3fb_try_memory_timings(struct pm3fb_info *l_fb_info)
+{
+	if (cardbase[l_fb_info->board_type].c_memt)
+	{
+		int i = 0, done = 0;
+		while (!done)
+		{
+			if ((cardbase[l_fb_info->board_type].c_memt[i].memsize == l_fb_info->fb_size)
+			    || !(cardbase[l_fb_info->board_type].c_memt[i].memsize))
+			{ /* will use the 0-sized timings by default */
+				done = 1;
+				l_fb_info->memt = cardbase[l_fb_info->board_type].c_memt[i].memt;
+				printk(KERN_WARNING  "pm3fb: trying to use predefined memory timings for permedia3 board #%ld (%s, %ld MB)\n",
+				       l_fb_info->board_num,
+				       cardbase[l_fb_info->board_type].cardname,
+				       cardbase[l_fb_info->board_type].c_memt[i].memsize);
+				pm3fb_write_memory_timings(l_fb_info);
+				return(pm3fb_timing_retry);
+			}
+			i++;
+		}
+	} else
+		return(pm3fb_timing_problem);
+	return(pm3fb_timing_ok);
+}
+
+static void pm3fb_write_memory_timings(struct pm3fb_info *l_fb_info)
+{
+	unsigned char m, n, p;
+	unsigned long clockused;
+	
+	PM3_SLOW_WRITE_REG(PM3LocalMemCaps, l_fb_info->memt.caps);
+	PM3_SLOW_WRITE_REG(PM3LocalMemTimings, l_fb_info->memt.timings);
+	PM3_SLOW_WRITE_REG(PM3LocalMemControl, l_fb_info->memt.control);
+	PM3_SLOW_WRITE_REG(PM3LocalMemRefresh, l_fb_info->memt.refresh);
+	PM3_SLOW_WRITE_REG(PM3LocalMemPowerDown, l_fb_info->memt.powerdown);
+
+	clockused =
+	    pm3fb_CalculateClock(l_fb_info, 2 * 105000, PM3_REF_CLOCK, &m,
+				 &n, &p);
+
+	PM3_WRITE_DAC_REG(PM3RD_KClkPreScale, m);
+	PM3_WRITE_DAC_REG(PM3RD_KClkFeedbackScale, n);
+	PM3_WRITE_DAC_REG(PM3RD_KClkPostScale, p);
+	PM3_WRITE_DAC_REG(PM3RD_KClkControl,
+			  PM3RD_KClkControl_STATE_RUN |
+			  PM3RD_KClkControl_SOURCE_PLL |
+			  PM3RD_KClkControl_ENABLE);
+	PM3_WRITE_DAC_REG(PM3RD_MClkControl,
+			  PM3RD_MClkControl_STATE_RUN |
+			  PM3RD_MClkControl_SOURCE_KCLK |
+			  PM3RD_MClkControl_ENABLE);
+	PM3_WRITE_DAC_REG(PM3RD_SClkControl,
+			  PM3RD_SClkControl_STATE_RUN |
+			  PM3RD_SClkControl_SOURCE_PCLK |
+			  PM3RD_SClkControl_ENABLE);
+}
+
+static unsigned long pm3fb_read_dac_reg(struct pm3fb_info *l_fb_info,
+					unsigned long r)
+{
+	DASSERT((l_fb_info->vIOBase != (unsigned char *) (-1)),
+		"l_fb_info->vIOBase mapped in read dac reg\n");
+	PM3_SET_INDEX(r);
+	mb();
+	return (PM3_READ_REG(PM3RD_IndexedData));
+}
+
+/* Calculating various clock parameter */
+static unsigned long pm3fb_CalculateClock(struct pm3fb_info *l_fb_info, unsigned long reqclock,	/* In kHz units */
+					  unsigned long refclock,	/* In kHz units */
+					  unsigned char *prescale,	/* ClkPreScale */
+					  unsigned char *feedback,	/* ClkFeedBackScale */
+					  unsigned char *postscale
+					  /* ClkPostScale */ )
+{
+	int f, pre, post;
+	unsigned long freq;
+	long freqerr = 1000;
+	unsigned long actualclock = 0;
+
+	DTRACE;
+
+	for (f = 1; f < 256; f++) {
+		for (pre = 1; pre < 256; pre++) {
+			for (post = 0; post < 5; post++) {
+				freq =
+				    ((2 * refclock * f) /
+				     (pre * (1 << post)));
+				if ((reqclock > freq - freqerr)
+				    && (reqclock < freq + freqerr)) {
+					freqerr =
+					    (reqclock >
+					     freq) ? reqclock -
+					    freq : freq - reqclock;
+					*feedback = f;
+					*prescale = pre;
+					*postscale = post;
+					actualclock = freq;
+				}
+			}
+		}
+	}
+
+	return (actualclock);
+}
+
+static int pm3fb_Shiftbpp(struct pm3fb_info *l_fb_info,
+			  unsigned long depth, int v)
+{
+	DTRACE;
+	
+	switch (depth) {
+	case 8:
+		return (v >> 4);
+	case 12:
+	case 15:
+	case 16:
+		return (v >> 3);
+	case 32:
+		return (v >> 2);
+	}
+	DPRINTK(1, "Unsupported depth %ld\n", depth);
+	return (0);
+}
+
+static int pm3fb_Unshiftbpp(struct pm3fb_info *l_fb_info,
+			    unsigned long depth, int v)
+{
+	DTRACE;
+
+	switch (depth) {
+	case 8:
+		return (v << 4);
+	case 12:	
+	case 15:
+	case 16:
+		return (v << 3);
+	case 32:
+		return (v << 2);
+	}
+	DPRINTK(1, "Unsupported depth %ld\n", depth);
+	return (0);
+}
+
+static void pm3fb_mapIO(struct pm3fb_info *l_fb_info)
+{
+	DTRACE;
+
+	l_fb_info->vIOBase =
+	    ioremap((unsigned long) l_fb_info->pIOBase, PM3_REGS_SIZE);
+	l_fb_info->v_fb =
+	    ioremap((unsigned long) l_fb_info->p_fb, l_fb_info->fb_size);
+	DPRINTK(2, "IO mapping : IOBase %lx / %lx, fb %lx / %lx\n",
+		(unsigned long) l_fb_info->pIOBase,
+		(unsigned long) l_fb_info->vIOBase,
+		(unsigned long) l_fb_info->p_fb,
+		(unsigned long) l_fb_info->v_fb);
+}
+
+static void pm3fb_unmapIO(struct pm3fb_info *l_fb_info)
+{
+	DTRACE;
+
+	iounmap(l_fb_info->vIOBase);
+	iounmap(l_fb_info->v_fb);
+	l_fb_info->vIOBase = (unsigned char *) -1;
+	l_fb_info->v_fb = (unsigned char *) -1;
+}
+
+#if defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2)
+static void pm3fb_show_cur_mode(struct pm3fb_info *l_fb_info)
+{
+	DPRINTK(2, "PM3Aperture0: 0x%08x\n", PM3_READ_REG(PM3Aperture0));
+	DPRINTK(2, "PM3Aperture1: 0x%08x\n", PM3_READ_REG(PM3Aperture1));
+	DPRINTK(2, "PM3ByAperture1Mode: 0x%08x\n",
+		PM3_READ_REG(PM3ByAperture1Mode));
+	DPRINTK(2, "PM3ByAperture2Mode: 0x%08x\n",
+		PM3_READ_REG(PM3ByAperture2Mode));
+	DPRINTK(2, "PM3ChipConfig: 0x%08x\n", PM3_READ_REG(PM3ChipConfig));
+	DPRINTK(2, "PM3FIFODis: 0x%08x\n", PM3_READ_REG(PM3FIFODis));
+	DPRINTK(2, "PM3HTotal: 0x%08x\n", PM3_READ_REG(PM3HTotal));
+	DPRINTK(2, "PM3HbEnd: 0x%08x\n", PM3_READ_REG(PM3HbEnd));
+	DPRINTK(2, "PM3HgEnd: 0x%08x\n", PM3_READ_REG(PM3HgEnd));
+	DPRINTK(2, "PM3HsEnd: 0x%08x\n", PM3_READ_REG(PM3HsEnd));
+	DPRINTK(2, "PM3HsStart: 0x%08x\n", PM3_READ_REG(PM3HsStart));
+	DPRINTK(2, "PM3MemBypassWriteMask: 0x%08x\n",
+		PM3_READ_REG(PM3MemBypassWriteMask));
+	DPRINTK(2, "PM3RD_IndexControl: 0x%08x\n",
+		PM3_READ_REG(PM3RD_IndexControl));
+	DPRINTK(2, "PM3ScreenBase: 0x%08x\n", PM3_READ_REG(PM3ScreenBase));
+	DPRINTK(2, "PM3ScreenStride: 0x%08x\n",
+		PM3_READ_REG(PM3ScreenStride));
+	DPRINTK(2, "PM3VClkCtl: 0x%08x\n", PM3_READ_REG(PM3VClkCtl));
+	DPRINTK(2, "PM3VTotal: 0x%08x\n", PM3_READ_REG(PM3VTotal));
+	DPRINTK(2, "PM3VbEnd: 0x%08x\n", PM3_READ_REG(PM3VbEnd));
+	DPRINTK(2, "PM3VideoControl: 0x%08x\n",
+		PM3_READ_REG(PM3VideoControl));
+	DPRINTK(2, "PM3VsEnd: 0x%08x\n", PM3_READ_REG(PM3VsEnd));
+	DPRINTK(2, "PM3VsStart: 0x%08x\n", PM3_READ_REG(PM3VsStart));
+
+	DPRINTK(2, "PM3RD_ColorFormat: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_ColorFormat));
+	DPRINTK(2, "PM3RD_DACControl: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_DACControl));
+	DPRINTK(2, "PM3RD_DClk0FeedbackScale: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_DClk0FeedbackScale));
+	DPRINTK(2, "PM3RD_DClk0PostScale: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_DClk0PostScale));
+	DPRINTK(2, "PM3RD_DClk0PreScale: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_DClk0PreScale));
+	DPRINTK(2, "[not set] PM3RD_IndexControl: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_IndexControl));
+	DPRINTK(2, "PM3RD_MiscControl: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_MiscControl));
+	DPRINTK(2, "PM3RD_PixelSize: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_PixelSize));
+	DPRINTK(2, "PM3RD_SyncControl: %ld\n",
+		PM3_READ_DAC_REG(PM3RD_SyncControl));
+}
+
+#endif /* defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2) */
+static void pm3fb_show_cur_timing(struct pm3fb_info *l_fb_info)
+{
+	u16 subvendor, subdevice;
+
+	if ((!pci_read_config_word
+	     (l_fb_info->dev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor))
+	    &&
+	    (!pci_read_config_word
+	     (l_fb_info->dev, PCI_SUBSYSTEM_ID, &subdevice))) {
+		/* well, nothing... */
+	} else {
+		subvendor = subdevice = (u16)-1;
+	}
+
+	printk(KERN_INFO "pm3fb: memory timings for board #%ld (subvendor: 0x%hx, subdevice: 0x%hx)\n", l_fb_info->board_num, subvendor, subdevice);
+	printk(KERN_INFO " PM3LocalMemCaps: 0x%08x\n",
+	       PM3_READ_REG(PM3LocalMemCaps));
+	printk(KERN_INFO " PM3LocalMemTimings: 0x%08x\n",
+	       PM3_READ_REG(PM3LocalMemTimings));
+	printk(KERN_INFO " PM3LocalMemControl: 0x%08x\n",
+	       PM3_READ_REG(PM3LocalMemControl));
+	printk(KERN_INFO " PM3LocalMemRefresh: 0x%08x\n",
+	       PM3_READ_REG(PM3LocalMemRefresh));
+	printk(KERN_INFO " PM3LocalMemPowerDown: 0x%08x\n",
+	       PM3_READ_REG(PM3LocalMemPowerDown));
+}
+
+/* write the mode to registers */
+static void pm3fb_write_mode(struct pm3fb_info *l_fb_info)
+{
+	char tempsync = 0x00, tempmisc = 0x00;
+	DTRACE;
+
+	PM3_SLOW_WRITE_REG(PM3MemBypassWriteMask, 0xffffffff);
+	PM3_SLOW_WRITE_REG(PM3Aperture0, 0x00000000);
+	PM3_SLOW_WRITE_REG(PM3Aperture1, 0x00000000);
+	PM3_SLOW_WRITE_REG(PM3FIFODis, 0x00000007);
+
+	PM3_SLOW_WRITE_REG(PM3HTotal,
+			   pm3fb_Shiftbpp(l_fb_info,
+					  l_fb_info->current_par->depth,
+					  l_fb_info->current_par->htotal -
+					  1));
+	PM3_SLOW_WRITE_REG(PM3HsEnd,
+			   pm3fb_Shiftbpp(l_fb_info,
+					  l_fb_info->current_par->depth,
+					  l_fb_info->current_par->hsend));
+	PM3_SLOW_WRITE_REG(PM3HsStart,
+			   pm3fb_Shiftbpp(l_fb_info,
+					  l_fb_info->current_par->depth,
+					  l_fb_info->current_par->
+					  hsstart));
+	PM3_SLOW_WRITE_REG(PM3HbEnd,
+			   pm3fb_Shiftbpp(l_fb_info,
+					  l_fb_info->current_par->depth,
+					  l_fb_info->current_par->hbend));
+	PM3_SLOW_WRITE_REG(PM3HgEnd,
+			   pm3fb_Shiftbpp(l_fb_info,
+					  l_fb_info->current_par->depth,
+					  l_fb_info->current_par->hbend));
+	PM3_SLOW_WRITE_REG(PM3ScreenStride,
+			   pm3fb_Shiftbpp(l_fb_info,
+					  l_fb_info->current_par->depth,
+					  l_fb_info->current_par->stride));
+	PM3_SLOW_WRITE_REG(PM3VTotal, l_fb_info->current_par->vtotal - 1);
+	PM3_SLOW_WRITE_REG(PM3VsEnd, l_fb_info->current_par->vsend - 1);
+	PM3_SLOW_WRITE_REG(PM3VsStart,
+			   l_fb_info->current_par->vsstart - 1);
+	PM3_SLOW_WRITE_REG(PM3VbEnd, l_fb_info->current_par->vbend);
+
+	switch (l_fb_info->current_par->depth) {
+	case 8:
+		PM3_SLOW_WRITE_REG(PM3ByAperture1Mode,
+				   PM3ByApertureMode_PIXELSIZE_8BIT);
+		PM3_SLOW_WRITE_REG(PM3ByAperture2Mode,
+				   PM3ByApertureMode_PIXELSIZE_8BIT);
+		break;
+
+	case 12:
+	case 15:
+	case 16:
+#ifndef __BIG_ENDIAN
+		PM3_SLOW_WRITE_REG(PM3ByAperture1Mode,
+				   PM3ByApertureMode_PIXELSIZE_16BIT);
+		PM3_SLOW_WRITE_REG(PM3ByAperture2Mode,
+				   PM3ByApertureMode_PIXELSIZE_16BIT);
+#else
+		PM3_SLOW_WRITE_REG(PM3ByAperture1Mode,
+				   PM3ByApertureMode_PIXELSIZE_16BIT |
+				   PM3ByApertureMode_BYTESWAP_BADC);
+		PM3_SLOW_WRITE_REG(PM3ByAperture2Mode,
+				   PM3ByApertureMode_PIXELSIZE_16BIT |
+				   PM3ByApertureMode_BYTESWAP_BADC);
+#endif /* ! __BIG_ENDIAN */
+		break;
+
+	case 32:
+#ifndef __BIG_ENDIAN
+		PM3_SLOW_WRITE_REG(PM3ByAperture1Mode,
+				   PM3ByApertureMode_PIXELSIZE_32BIT);
+		PM3_SLOW_WRITE_REG(PM3ByAperture2Mode,
+				   PM3ByApertureMode_PIXELSIZE_32BIT);
+#else
+		PM3_SLOW_WRITE_REG(PM3ByAperture1Mode,
+				   PM3ByApertureMode_PIXELSIZE_32BIT |
+				   PM3ByApertureMode_BYTESWAP_DCBA);
+		PM3_SLOW_WRITE_REG(PM3ByAperture2Mode,
+				   PM3ByApertureMode_PIXELSIZE_32BIT |
+				   PM3ByApertureMode_BYTESWAP_DCBA);
+#endif /* ! __BIG_ENDIAN */
+		break;
+
+	default:
+		DPRINTK(1, "Unsupported depth %d\n",
+			l_fb_info->current_par->depth);
+		break;
+	}
+
+	/*
+	 * Oxygen VX1 - it appears that setting PM3VideoControl and
+	 * then PM3RD_SyncControl to the same SYNC settings undoes
+	 * any net change - they seem to xor together.  Only set the
+	 * sync options in PM3RD_SyncControl.  --rmk
+	 */
+	{
+		unsigned int video = l_fb_info->current_par->video;
+
+		video &= ~(PM3VideoControl_HSYNC_MASK |
+			   PM3VideoControl_VSYNC_MASK);
+		video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
+			 PM3VideoControl_VSYNC_ACTIVE_HIGH;
+		PM3_SLOW_WRITE_REG(PM3VideoControl, video);
+	}
+	PM3_SLOW_WRITE_REG(PM3VClkCtl,
+			   (PM3_READ_REG(PM3VClkCtl) & 0xFFFFFFFC));
+	PM3_SLOW_WRITE_REG(PM3ScreenBase, l_fb_info->current_par->base);
+	PM3_SLOW_WRITE_REG(PM3ChipConfig,
+			   (PM3_READ_REG(PM3ChipConfig) & 0xFFFFFFFD));
+
+	{
+		unsigned char m;	/* ClkPreScale */
+		unsigned char n;	/* ClkFeedBackScale */
+		unsigned char p;	/* ClkPostScale */
+		(void)pm3fb_CalculateClock(l_fb_info, l_fb_info->current_par->pixclock, PM3_REF_CLOCK, &m, &n, &p);
+
+		DPRINTK(2,
+			"Pixclock: %d, Pre: %d, Feedback: %d, Post: %d\n",
+			l_fb_info->current_par->pixclock, (int) m, (int) n,
+			(int) p);
+
+		PM3_WRITE_DAC_REG(PM3RD_DClk0PreScale, m);
+		PM3_WRITE_DAC_REG(PM3RD_DClk0FeedbackScale, n);
+		PM3_WRITE_DAC_REG(PM3RD_DClk0PostScale, p);
+	}
+	/*
+	   PM3_WRITE_DAC_REG(PM3RD_IndexControl, 0x00);
+	 */
+	/*
+	   PM3_SLOW_WRITE_REG(PM3RD_IndexControl, 0x00);
+	 */
+	if ((l_fb_info->current_par->video & PM3VideoControl_HSYNC_MASK) ==
+	    PM3VideoControl_HSYNC_ACTIVE_HIGH)
+		tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
+	if ((l_fb_info->current_par->video & PM3VideoControl_VSYNC_MASK) ==
+	    PM3VideoControl_VSYNC_ACTIVE_HIGH)
+		tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
+	
+	PM3_WRITE_DAC_REG(PM3RD_SyncControl, tempsync);
+	DPRINTK(2, "PM3RD_SyncControl: %d\n", tempsync);
+	
+	if (flatpanel[l_fb_info->board_num])
+	{
+		PM3_WRITE_DAC_REG(PM3RD_DACControl, PM3RD_DACControl_BLANK_PEDESTAL_ENABLE);
+		PM3_WAIT(2);
+		PM3_WRITE_REG(PM3VSConfiguration, 0x06);
+		PM3_WRITE_REG(0x5a00, 1 << 14); /* black magic... */
+		tempmisc = PM3RD_MiscControl_VSB_OUTPUT_ENABLE;
+	}
+	else
+		PM3_WRITE_DAC_REG(PM3RD_DACControl, 0x00);
+
+	switch (l_fb_info->current_par->depth) {
+	case 8:
+		PM3_WRITE_DAC_REG(PM3RD_PixelSize,
+				  PM3RD_PixelSize_8_BIT_PIXELS);
+		PM3_WRITE_DAC_REG(PM3RD_ColorFormat,
+				  PM3RD_ColorFormat_CI8_COLOR |
+				  PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
+		tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
+		break;
+	case 12:
+		PM3_WRITE_DAC_REG(PM3RD_PixelSize,
+				  PM3RD_PixelSize_16_BIT_PIXELS);
+		PM3_WRITE_DAC_REG(PM3RD_ColorFormat,
+				  PM3RD_ColorFormat_4444_COLOR |
+				  PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
+				  PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
+		tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
+			PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
+		break;		
+	case 15:
+		PM3_WRITE_DAC_REG(PM3RD_PixelSize,
+				  PM3RD_PixelSize_16_BIT_PIXELS);
+		PM3_WRITE_DAC_REG(PM3RD_ColorFormat,
+				  PM3RD_ColorFormat_5551_FRONT_COLOR |
+				  PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
+				  PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
+		tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
+			PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
+		break;		
+	case 16:
+		PM3_WRITE_DAC_REG(PM3RD_PixelSize,
+				  PM3RD_PixelSize_16_BIT_PIXELS);
+		PM3_WRITE_DAC_REG(PM3RD_ColorFormat,
+				  PM3RD_ColorFormat_565_FRONT_COLOR |
+				  PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
+				  PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
+		tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
+			PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
+		break;
+	case 32:
+		PM3_WRITE_DAC_REG(PM3RD_PixelSize,
+				  PM3RD_PixelSize_32_BIT_PIXELS);
+		PM3_WRITE_DAC_REG(PM3RD_ColorFormat,
+				  PM3RD_ColorFormat_8888_COLOR |
+				  PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
+		tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
+			PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
+		break;
+	}
+	PM3_WRITE_DAC_REG(PM3RD_MiscControl, tempmisc);
+	
+	PM3_SHOW_CUR_MODE;
+}
+
+static void pm3fb_read_mode(struct pm3fb_info *l_fb_info,
+			    struct pm3fb_par *curpar)
+{
+	unsigned long pixsize1, pixsize2, clockused;
+	unsigned long pre, feedback, post;
+
+	DTRACE;
+
+	clockused = PM3_READ_REG(PM3VClkCtl);
+
+	switch (clockused) {
+	case 3:
+		pre = PM3_READ_DAC_REG(PM3RD_DClk3PreScale);
+		feedback = PM3_READ_DAC_REG(PM3RD_DClk3FeedbackScale);
+		post = PM3_READ_DAC_REG(PM3RD_DClk3PostScale);
+
+		DPRINTK(2,
+			"DClk3 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n",
+			pre, feedback, post, PM3_SCALE_TO_CLOCK(pre,
+								feedback,
+								post));
+		break;
+	case 2:
+		pre = PM3_READ_DAC_REG(PM3RD_DClk2PreScale);
+		feedback = PM3_READ_DAC_REG(PM3RD_DClk2FeedbackScale);
+		post = PM3_READ_DAC_REG(PM3RD_DClk2PostScale);
+
+		DPRINTK(2,
+			"DClk2 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n",
+			pre, feedback, post, PM3_SCALE_TO_CLOCK(pre,
+								feedback,
+								post));
+		break;
+	case 1:
+		pre = PM3_READ_DAC_REG(PM3RD_DClk1PreScale);
+		feedback = PM3_READ_DAC_REG(PM3RD_DClk1FeedbackScale);
+		post = PM3_READ_DAC_REG(PM3RD_DClk1PostScale);
+
+		DPRINTK(2,
+			"DClk1 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n",
+			pre, feedback, post, PM3_SCALE_TO_CLOCK(pre,
+								feedback,
+								post));
+		break;
+	case 0:
+		pre = PM3_READ_DAC_REG(PM3RD_DClk0PreScale);
+		feedback = PM3_READ_DAC_REG(PM3RD_DClk0FeedbackScale);
+		post = PM3_READ_DAC_REG(PM3RD_DClk0PostScale);
+
+		DPRINTK(2,
+			"DClk0 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n",
+			pre, feedback, post, PM3_SCALE_TO_CLOCK(pre,
+								feedback,
+								post));
+		break;
+	default:
+		pre = feedback = post = 0;
+		DPRINTK(1, "Unknowk D clock used : %ld\n", clockused);
+		break;
+	}
+
+	curpar->pixclock = PM3_SCALE_TO_CLOCK(pre, feedback, post);
+
+	pixsize1 =
+	    PM3ByApertureMode_PIXELSIZE_MASK &
+	    (PM3_READ_REG(PM3ByAperture1Mode));
+	pixsize2 =
+	    PM3ByApertureMode_PIXELSIZE_MASK &
+	    (PM3_READ_REG(PM3ByAperture2Mode));
+
+	DASSERT((pixsize1 == pixsize2),
+		"pixsize the same in both aperture\n");
+
+	if (pixsize1 & PM3ByApertureMode_PIXELSIZE_32BIT)
+		curpar->depth = 32;
+	else if (pixsize1 & PM3ByApertureMode_PIXELSIZE_16BIT)
+	{
+		curpar->depth = 16;
+	}
+	else
+		curpar->depth = 8;
+
+	/* not sure if I need to add one on the next ; it give better result with */
+	curpar->htotal =
+	    pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
+			     1 + PM3_READ_REG(PM3HTotal));
+	curpar->hsend =
+	    pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
+			     PM3_READ_REG(PM3HsEnd));
+	curpar->hsstart =
+	    pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
+			     PM3_READ_REG(PM3HsStart));
+	curpar->hbend =
+	    pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
+			     PM3_READ_REG(PM3HbEnd));
+
+	curpar->stride =
+	    pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
+			     PM3_READ_REG(PM3ScreenStride));
+
+	curpar->vtotal = 1 + PM3_READ_REG(PM3VTotal);
+	curpar->vsend = 1 + PM3_READ_REG(PM3VsEnd);
+	curpar->vsstart = 1 + PM3_READ_REG(PM3VsStart);
+	curpar->vbend = PM3_READ_REG(PM3VbEnd);
+
+	curpar->video = PM3_READ_REG(PM3VideoControl);
+
+	curpar->base = PM3_READ_REG(PM3ScreenBase);
+	curpar->width = curpar->htotal - curpar->hbend; /* make virtual == displayed resolution */
+	curpar->height = curpar->vtotal - curpar->vbend;
+
+	DPRINTK(2, "Found : %d * %d, %d Khz, stride is %08x\n",
+		curpar->width, curpar->height, curpar->pixclock,
+		curpar->stride);
+}
+
+static unsigned long pm3fb_size_memory(struct pm3fb_info *l_fb_info)
+{
+	unsigned long memsize = 0, tempBypass, i, temp1, temp2;
+	u16 subvendor, subdevice;
+	pm3fb_timing_result ptr;
+
+	DTRACE;
+
+	l_fb_info->fb_size = 64 * 1024 * 1024;	/* pm3 aperture always 64 MB */
+	pm3fb_mapIO(l_fb_info);	/* temporary map IO */
+
+	DASSERT((l_fb_info->vIOBase != NULL),
+		"IO successfully mapped before mem detect\n");
+	DASSERT((l_fb_info->v_fb != NULL),
+		"FB successfully mapped before mem detect\n");
+
+	/* card-specific stuff, *before* accessing *any* FB memory */
+	if ((!pci_read_config_word
+	     (l_fb_info->dev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor))
+	    &&
+	    (!pci_read_config_word
+	     (l_fb_info->dev, PCI_SUBSYSTEM_ID, &subdevice))) {
+		i = 0; l_fb_info->board_type = 0;
+		while ((cardbase[i].cardname[0]) && !(l_fb_info->board_type)) {
+			if ((cardbase[i].subvendor == subvendor) &&
+			    (cardbase[i].subdevice == subdevice) &&
+			    (cardbase[i].func == PCI_FUNC(l_fb_info->dev->devfn))) {
+				DPRINTK(2, "Card #%ld is an %s\n",
+					l_fb_info->board_num,
+					cardbase[i].cardname);
+				if (cardbase[i].specific_setup)
+					cardbase[i].specific_setup(l_fb_info);
+				l_fb_info->board_type = i;
+			}
+			i++;
+		}
+		if (!l_fb_info->board_type) {
+			DPRINTK(1, "Card #%ld is an unknown 0x%04x / 0x%04x\n",
+				l_fb_info->board_num, subvendor, subdevice);
+		}
+	} else {
+		printk(KERN_ERR "pm3fb: Error: pci_read_config_word failed, board #%ld\n",
+		       l_fb_info->board_num);
+	}
+
+	if (printtimings)
+		pm3fb_show_cur_timing(l_fb_info);
+	
+	/* card-specific setup is done, we preserve the final
+           memory timing for future reference */
+	if ((ptr = pm3fb_preserve_memory_timings(l_fb_info)) == pm3fb_timing_problem) { /* memory timings were wrong ! oops.... */
+		return(0);
+	}
+	
+	tempBypass = PM3_READ_REG(PM3MemBypassWriteMask);
+
+	DPRINTK(2, "PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
+
+	PM3_SLOW_WRITE_REG(PM3MemBypassWriteMask, 0xFFFFFFFF);
+
+	/* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
+	for (i = 0; i < 32; i++) {
+#ifdef KERNEL_2_2
+#ifdef MUST_BYTESWAP
+		writel(__swab32(i * 0x00345678),
+		       (l_fb_info->v_fb + (i * 1048576)));
+#else
+		writel(i * 0x00345678, (l_fb_info->v_fb + (i * 1048576)));
+#endif
+		mb();
+#ifdef MUST_BYTESWAP
+		temp1 = __swab32(readl((l_fb_info->v_fb + (i * 1048576))));
+#else
+		temp1 = readl((l_fb_info->v_fb + (i * 1048576)));
+#endif
+#endif	/* KERNEL_2_2 */
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+		fb_writel(i * 0x00345678,
+			  (l_fb_info->v_fb + (i * 1048576)));
+		mb();
+		temp1 = fb_readl((l_fb_info->v_fb + (i * 1048576)));
+#endif /* KERNEL_2_4 or KERNEL_2_5 */
+		/* Let's check for wrapover, write will fail at 16MB boundary */
+		if (temp1 == (i * 0x00345678))
+			memsize = i;
+		else
+			break;
+	}
+
+	DPRINTK(2, "First detect pass already got %ld MB\n", memsize + 1);
+
+	if (memsize == i) {
+		for (i = 0; i < 32; i++) {
+			/* Clear first 32MB ; 0 is 0, no need to byteswap */
+			writel(0x0000000,
+			       (l_fb_info->v_fb + (i * 1048576)));
+			mb();
+		}
+
+		for (i = 32; i < 64; i++) {
+#ifdef KERNEL_2_2
+#ifdef MUST_BYTESWAP
+			writel(__swab32(i * 0x00345678),
+			       (l_fb_info->v_fb + (i * 1048576)));
+#else
+			writel(i * 0x00345678,
+			       (l_fb_info->v_fb + (i * 1048576)));
+#endif
+			mb();
+#ifdef MUST_BYTESWAP
+			temp1 =
+			    __swab32(readl
+				     ((l_fb_info->v_fb + (i * 1048576))));
+			temp2 =
+			    __swab32(readl
+				     ((l_fb_info->v_fb +
+				       ((i - 32) * 1048576))));
+#else
+			temp1 = readl((l_fb_info->v_fb + (i * 1048576)));
+			temp2 =
+			    readl((l_fb_info->v_fb +
+				   ((i - 32) * 1048576)));
+#endif
+#endif /* KERNEL_2_2 */
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+			fb_writel(i * 0x00345678,
+				  (l_fb_info->v_fb + (i * 1048576)));
+			mb();
+			temp1 =
+			    fb_readl((l_fb_info->v_fb + (i * 1048576)));
+			temp2 =
+			    fb_readl((l_fb_info->v_fb +
+				      ((i - 32) * 1048576)));
+#endif /* KERNEL_2_4 or KERNEL_2_5 */
+			if ((temp1 == (i * 0x00345678)) && (temp2 == 0))	/* different value, different RAM... */
+				memsize = i;
+			else
+				break;
+		}
+	}
+
+	DPRINTK(2, "Second detect pass got %ld MB\n", memsize + 1);
+
+	PM3_SLOW_WRITE_REG(PM3MemBypassWriteMask, tempBypass);
+
+	pm3fb_unmapIO(l_fb_info);
+	memsize = 1048576 * (memsize + 1);
+
+	DPRINTK(2, "Returning 0x%08lx bytes\n", memsize);
+
+	if (forcesize[l_fb_info->board_num] && ((forcesize[l_fb_info->board_num] * 1048576) != memsize))
+	{
+		printk(KERN_WARNING "pm3fb: mismatch between probed (%ld MB) and specified (%hd MB) memory size, using SPECIFIED !\n", memsize, forcesize[l_fb_info->board_num]);
+		memsize = 1048576 * forcesize[l_fb_info->board_num];
+	}
+	
+	l_fb_info->fb_size = memsize;
+	
+	if (ptr == pm3fb_timing_retry)
+	{
+		printk(KERN_WARNING "pm3fb: retrying memory timings check");
+		if (pm3fb_try_memory_timings(l_fb_info) == pm3fb_timing_problem)
+			return(0);
+	}
+	
+	return (memsize);
+}
+
+static void pm3fb_clear_memory(struct pm3fb_info *l_fb_info, u32 cc)
+{
+	int i;
+
+	DTRACE;
+
+	for (i = 0; i < (l_fb_info->fb_size / sizeof(u32)) ; i++) /* clear entire FB memory to black */
+	{
+#ifdef KERNEL_2_2
+#ifdef MUST_BYTESWAP
+		writel(__swab32(cc), (l_fb_info->v_fb + (i * sizeof(u32))));
+#else
+		writel(cc, (l_fb_info->v_fb + (i * sizeof(u32))));
+#endif
+#endif
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+		fb_writel(cc, (l_fb_info->v_fb + (i * sizeof(u32))));
+#endif
+	}
+}
+
+static void pm3fb_clear_colormap(struct pm3fb_info *l_fb_info, unsigned char r, unsigned char g, unsigned char b)
+{
+	int i;
+
+	DTRACE;
+
+	for (i = 0; i < 256 ; i++) /* fill color map with white */
+		pm3fb_set_color(l_fb_info, i, r, g, b);
+
+}
+
+/* common initialisation */
+static void pm3fb_common_init(struct pm3fb_info *l_fb_info)
+{
+	DTRACE;
+
+	DPRINTK(2, "Initializing board #%ld @ %lx\n", l_fb_info->board_num,
+		(unsigned long) l_fb_info);
+
+	strcpy(l_fb_info->gen.info.modename, permedia3_name);
+	disp[l_fb_info->board_num].scrollmode = 0;	/* SCROLL_YNOMOVE; *//* 0 means "let fbcon choose" */
+	l_fb_info->gen.parsize = sizeof(struct pm3fb_par);
+	l_fb_info->gen.info.changevar = NULL;
+	l_fb_info->gen.info.node = B_FREE;
+	l_fb_info->gen.info.fbops = &pm3fb_ops;
+	l_fb_info->gen.info.disp = &(disp[l_fb_info->board_num]);
+	if (fontn[l_fb_info->board_num][0])
+		strcpy(l_fb_info->gen.info.fontname,
+		       fontn[l_fb_info->board_num]);
+	l_fb_info->gen.info.switch_con = &fbgen_switch;
+	l_fb_info->gen.info.updatevar = &fbgen_update_var;	/* */
+	l_fb_info->gen.info.blank = &fbgen_blank;	/* */
+	l_fb_info->gen.info.flags = FBINFO_FLAG_DEFAULT;
+
+	pm3fb_mapIO(l_fb_info);
+
+	pm3fb_clear_memory(l_fb_info, 0);
+	pm3fb_clear_colormap(l_fb_info, 0, 0, 0);
+
+	(void) fbgen_get_var(&(disp[l_fb_info->board_num]).var, -1,
+			     &l_fb_info->gen.info);
+
+	if (depth[l_fb_info->board_num]) /* override mode-defined depth */
+	{
+		pm3fb_encode_depth(&(disp[l_fb_info->board_num]).var, depth[l_fb_info->board_num]);
+		(disp[l_fb_info->board_num]).var.bits_per_pixel = depth2bpp(depth[l_fb_info->board_num]);
+	}
+
+	(void) fbgen_do_set_var(&(disp[l_fb_info->board_num]).var, 1,
+				&l_fb_info->gen);
+
+	fbgen_set_disp(-1, &l_fb_info->gen);
+
+	fbgen_install_cmap(0, &l_fb_info->gen);
+
+	if (register_framebuffer(&l_fb_info->gen.info) < 0) {
+		DPRINTK(1, "Couldn't register framebuffer\n");
+		return;
+	}
+
+	PM3_WRITE_DAC_REG(PM3RD_CursorMode,
+			  PM3RD_CursorMode_CURSOR_DISABLE);
+	
+	PM3_SHOW_CUR_MODE;
+	
+	pm3fb_write_mode(l_fb_info);
+	
+	printk("fb%d: %s, using %uK of video memory (%s)\n",
+	       GET_FB_IDX(l_fb_info->gen.info.node),
+	       permedia3_name, (u32) (l_fb_info->fb_size >> 10),
+	       cardbase[l_fb_info->board_type].cardname);
+}
+
+/* **************************************************** */
+/* ***** accelerated permedia3-specific functions ***** */
+/* **************************************************** */
+#ifdef PM3FB_USE_ACCEL
+static void pm3fb_wait_pm3(struct pm3fb_info *l_fb_info)
+{
+	DTRACE;
+
+	PM3_SLOW_WRITE_REG(PM3FilterMode, PM3FilterModeSync);
+	PM3_SLOW_WRITE_REG(PM3Sync, 0);
+	mb();
+	do {
+		while ((PM3_READ_REG(PM3OutFIFOWords)) == 0);
+		rmb();
+	} while ((PM3_READ_REG(PM3OutputFifo)) != PM3Sync_Tag);
+}
+
+static void pm3fb_init_engine(struct pm3fb_info *l_fb_info)
+{
+	PM3_SLOW_WRITE_REG(PM3FilterMode, PM3FilterModeSync);
+	PM3_SLOW_WRITE_REG(PM3StatisticMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3DeltaMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3RasterizerMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3ScissorMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3LineStippleMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3AreaStippleMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3GIDMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3DepthMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3StencilMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3StencilData, 0x0);
+	PM3_SLOW_WRITE_REG(PM3ColorDDAMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureCoordMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureIndexMode0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureIndexMode1, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureReadMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3LUTMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureFilterMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureCompositeMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureApplicationMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureCompositeColorMode1, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureCompositeAlphaMode1, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureCompositeColorMode0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3TextureCompositeAlphaMode0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FogMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3ChromaTestMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3AlphaTestMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3AntialiasMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3YUVMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3AlphaBlendColorMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3AlphaBlendAlphaMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3DitherMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3LogicalOpMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3RouterMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3Window, 0x0);
+
+	PM3_SLOW_WRITE_REG(PM3Config2D, 0x0);
+
+	PM3_SLOW_WRITE_REG(PM3SpanColorMask, 0xffffffff);
+
+	PM3_SLOW_WRITE_REG(PM3XBias, 0x0);
+	PM3_SLOW_WRITE_REG(PM3YBias, 0x0);
+	PM3_SLOW_WRITE_REG(PM3DeltaControl, 0x0);
+
+	PM3_SLOW_WRITE_REG(PM3BitMaskPattern, 0xffffffff);
+
+	PM3_SLOW_WRITE_REG(PM3FBDestReadEnables,
+			   PM3FBDestReadEnables_E(0xff) |
+			   PM3FBDestReadEnables_R(0xff) |
+			   PM3FBDestReadEnables_ReferenceAlpha(0xff));
+	PM3_SLOW_WRITE_REG(PM3FBDestReadBufferAddr0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FBDestReadBufferOffset0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FBDestReadBufferWidth0,
+			   PM3FBDestReadBufferWidth_Width(l_fb_info->
+							  current_par->
+							  width));
+
+	PM3_SLOW_WRITE_REG(PM3FBDestReadMode,
+			   PM3FBDestReadMode_ReadEnable |
+			   PM3FBDestReadMode_Enable0);
+	PM3_SLOW_WRITE_REG(PM3FBSourceReadBufferAddr, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FBSourceReadBufferOffset, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FBSourceReadBufferWidth,
+			   PM3FBSourceReadBufferWidth_Width(l_fb_info->
+							    current_par->
+							    width));
+	PM3_SLOW_WRITE_REG(PM3FBSourceReadMode,
+			   PM3FBSourceReadMode_Blocking |
+			   PM3FBSourceReadMode_ReadEnable);
+
+	{
+		unsigned long rm = 1;
+		switch (l_fb_info->current_par->depth) {
+		case 8:
+			PM3_SLOW_WRITE_REG(PM3PixelSize,
+					   PM3PixelSize_GLOBAL_8BIT);
+			break;
+		case 12:
+		case 15:
+		case 16:
+			PM3_SLOW_WRITE_REG(PM3PixelSize,
+					   PM3PixelSize_GLOBAL_16BIT);
+			break;
+		case 32:
+			PM3_SLOW_WRITE_REG(PM3PixelSize,
+					   PM3PixelSize_GLOBAL_32BIT);
+			break;
+		default:
+			DPRINTK(1, "Unsupported depth %d\n",
+				l_fb_info->current_par->depth);
+			break;
+		}
+		PM3_SLOW_WRITE_REG(PM3RasterizerMode, rm);
+	}
+
+	PM3_SLOW_WRITE_REG(PM3FBSoftwareWriteMask, 0xffffffff);
+	PM3_SLOW_WRITE_REG(PM3FBHardwareWriteMask, 0xffffffff);
+	PM3_SLOW_WRITE_REG(PM3FBWriteMode,
+			   PM3FBWriteMode_WriteEnable |
+			   PM3FBWriteMode_OpaqueSpan |
+			   PM3FBWriteMode_Enable0);
+	PM3_SLOW_WRITE_REG(PM3FBWriteBufferAddr0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FBWriteBufferOffset0, 0x0);
+	PM3_SLOW_WRITE_REG(PM3FBWriteBufferWidth0,
+			   PM3FBWriteBufferWidth_Width(l_fb_info->
+						       current_par->
+						       width));
+
+	PM3_SLOW_WRITE_REG(PM3SizeOfFramebuffer, 0x0);
+	{
+		unsigned long sofb = (8UL * l_fb_info->fb_size) /
+			((depth2bpp(l_fb_info->current_par->depth))
+			 * l_fb_info->current_par->width);	/* size in lines of FB */
+		if (sofb > 4095)
+			PM3_SLOW_WRITE_REG(PM3SizeOfFramebuffer, 4095);
+		else
+			PM3_SLOW_WRITE_REG(PM3SizeOfFramebuffer, sofb);
+		
+		switch (l_fb_info->current_par->depth) {
+		case 8:
+			PM3_SLOW_WRITE_REG(PM3DitherMode,
+					   (1 << 10) | (2 << 3));
+			break;
+		case 12:
+		case 15:
+		case 16:
+			PM3_SLOW_WRITE_REG(PM3DitherMode,
+					   (1 << 10) | (1 << 3));
+			break;
+		case 32:
+			PM3_SLOW_WRITE_REG(PM3DitherMode,
+					   (1 << 10) | (0 << 3));
+			break;
+		default:
+			DPRINTK(1, "Unsupported depth %d\n",
+				l_fb_info->current_par->depth);
+			break;
+		}
+	}
+
+	PM3_SLOW_WRITE_REG(PM3dXDom, 0x0);
+	PM3_SLOW_WRITE_REG(PM3dXSub, 0x0);
+	PM3_SLOW_WRITE_REG(PM3dY, (1 << 16));
+	PM3_SLOW_WRITE_REG(PM3StartXDom, 0x0);
+	PM3_SLOW_WRITE_REG(PM3StartXSub, 0x0);
+	PM3_SLOW_WRITE_REG(PM3StartY, 0x0);
+	PM3_SLOW_WRITE_REG(PM3Count, 0x0);
+	
+/* Disable LocalBuffer. better safe than sorry */
+	PM3_SLOW_WRITE_REG(PM3LBDestReadMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3LBDestReadEnables, 0x0);
+	PM3_SLOW_WRITE_REG(PM3LBSourceReadMode, 0x0);
+	PM3_SLOW_WRITE_REG(PM3LBWriteMode, 0x0);
+	
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+#ifdef FBCON_HAS_CFB32
+static void pm3fb_cfb32_clear(struct vc_data *conp,
+			      struct display *p,
+			      int sy, int sx, int height, int width)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	u32 c;
+
+	DTRACE;
+
+	sx = sx * fontwidth(p);
+	width = width * fontwidth(p);
+	sy = sy * fontheight(p);
+	height = height * fontheight(p);
+	c = ((u32 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
+
+	/* block fills in 32bpp are hard, but in low res (width <= 1600 :-)
+	   we can use 16bpp operations, but not if NoWriteMask is on (SDRAM)  */
+	if ((l_fb_info->current_par->width > 1600) ||
+	    (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)) {
+		PM3_WAIT(4);
+
+		PM3_WRITE_REG(PM3Config2D,
+					  PM3Config2D_UseConstantSource |
+					  PM3Config2D_ForegroundROPEnable |
+					  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+					  PM3Config2D_FBWriteEnable);
+
+		PM3_WRITE_REG(PM3ForegroundColor, c);
+
+		PM3_WRITE_REG(PM3RectanglePosition,
+			      (PM3RectanglePosition_XOffset(sx)) |
+			      (PM3RectanglePosition_YOffset(sy)));
+
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      PM3Render2D_SpanOperation |
+			      (PM3Render2D_Width(width)) |
+			      (PM3Render2D_Height(height)));
+	} else {
+		PM3_WAIT(8);
+
+		PM3_WRITE_REG(PM3FBBlockColor, c);
+
+		PM3_WRITE_REG(PM3PixelSize, PM3PixelSize_GLOBAL_16BIT);
+
+		PM3_WRITE_REG(PM3FBWriteBufferWidth0,
+			      PM3FBWriteBufferWidth_Width(l_fb_info->
+							  current_par->
+							  width << 1));
+
+		PM3_WRITE_REG(PM3Config2D,
+					  PM3Config2D_UseConstantSource |
+					  PM3Config2D_ForegroundROPEnable |
+					  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+					  PM3Config2D_FBWriteEnable);
+
+		PM3_WRITE_REG(PM3RectanglePosition,
+			      (PM3RectanglePosition_XOffset(sx << 1)) |
+			      (PM3RectanglePosition_YOffset(sy)));
+
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      (PM3Render2D_Width(width << 1)) |
+			      (PM3Render2D_Height(height)));
+
+		PM3_WRITE_REG(PM3FBWriteBufferWidth0,
+			      PM3FBWriteBufferWidth_Width(l_fb_info->
+							  current_par->
+							  width));
+
+		PM3_WRITE_REG(PM3PixelSize, PM3PixelSize_GLOBAL_32BIT);
+	}
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+static void pm3fb_cfb32_clear_margins(struct vc_data *conp,
+				      struct display *p, int bottom_only)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	int sx, sy;
+	u32 c;
+
+	DTRACE;
+
+	sx = conp->vc_cols * fontwidth(p);	/* right margin */
+	sy = conp->vc_rows * fontheight(p);	/* bottom margin */
+	c = ((u32 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
+
+	if (!bottom_only) {	/* right margin top->bottom */
+		PM3_WAIT(4);
+
+		PM3_WRITE_REG(PM3Config2D,
+					  PM3Config2D_UseConstantSource |
+					  PM3Config2D_ForegroundROPEnable |
+					  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+					  PM3Config2D_FBWriteEnable);
+
+		PM3_WRITE_REG(PM3ForegroundColor, c);
+
+		PM3_WRITE_REG(PM3RectanglePosition,
+			      (PM3RectanglePosition_XOffset
+			       (p->var.xoffset +
+				sx)) | (PM3RectanglePosition_YOffset(p->
+								     var.
+								     yoffset)));
+
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      PM3Render2D_SpanOperation |
+			      (PM3Render2D_Width(p->var.xres - sx)) |
+			      (PM3Render2D_Height(p->var.yres)));
+	}
+
+	/* bottom margin left -> right */
+	PM3_WAIT(4);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable);
+
+	PM3_WRITE_REG(PM3ForegroundColor, c);
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(p->var.xoffset)) |
+		      (PM3RectanglePosition_YOffset(p->var.yoffset + sy)));
+
+	PM3_WRITE_REG(PM3Render2D,
+		      PM3Render2D_XPositive |
+		      PM3Render2D_YPositive |
+		      PM3Render2D_Operation_Normal |
+		      PM3Render2D_SpanOperation |
+		      (PM3Render2D_Width(p->var.xres)) |
+		      (PM3Render2D_Height(p->var.yres - sy)));
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+#endif /* FBCON_HAS_CFB32 */
+#ifdef FBCON_HAS_CFB16
+static void pm3fb_cfb16_clear(struct vc_data *conp,
+			      struct display *p,
+			      int sy, int sx, int height, int width)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	u32 c;
+
+	DTRACE;
+
+	sx = sx * fontwidth(p);
+	width = width * fontwidth(p);
+	sy = sy * fontheight(p);
+	height = height * fontheight(p);
+	c = ((u16 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
+	c = c | (c << 16);
+
+	PM3_WAIT(4);
+
+	if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+		PM3_WRITE_REG(PM3ForegroundColor, c);
+	else
+		PM3_WRITE_REG(PM3FBBlockColor, c);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable);
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(sx)) |
+		      (PM3RectanglePosition_YOffset(sy)));
+	
+	if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      PM3Render2D_SpanOperation |
+			      (PM3Render2D_Width(width)) |
+			      (PM3Render2D_Height(height)));
+	else
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      (PM3Render2D_Width(width)) |
+			      (PM3Render2D_Height(height)));
+	
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+static void pm3fb_cfb16_clear_margins(struct vc_data *conp,
+				      struct display *p, int bottom_only)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	int sx, sy;
+	u32 c;
+
+	DTRACE;
+
+	sx = conp->vc_cols * fontwidth(p);	/* right margin */
+	sy = conp->vc_rows * fontheight(p);	/* bottom margin */
+	c = ((u16 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
+	c = c | (c << 16);
+
+	if (!bottom_only) {	/* right margin top->bottom */
+		PM3_WAIT(4);
+
+		PM3_WRITE_REG(PM3Config2D,
+					  PM3Config2D_UseConstantSource |
+					  PM3Config2D_ForegroundROPEnable |
+					  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+					  PM3Config2D_FBWriteEnable);
+		
+		if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+			PM3_WRITE_REG(PM3ForegroundColor, c);
+		else
+			PM3_WRITE_REG(PM3FBBlockColor, c);
+		
+		PM3_WRITE_REG(PM3RectanglePosition,
+			      (PM3RectanglePosition_XOffset
+			       (p->var.xoffset +
+				sx)) | (PM3RectanglePosition_YOffset(p->
+								     var.
+								     yoffset)));
+		if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+			PM3_WRITE_REG(PM3Render2D,
+				      PM3Render2D_XPositive |
+				      PM3Render2D_YPositive |
+				      PM3Render2D_Operation_Normal |
+				      PM3Render2D_SpanOperation |
+				      (PM3Render2D_Width(p->var.xres - sx)) |
+				      (PM3Render2D_Height(p->var.yres)));
+		else
+			PM3_WRITE_REG(PM3Render2D,
+				      PM3Render2D_XPositive |
+				      PM3Render2D_YPositive |
+				      PM3Render2D_Operation_Normal |
+				      (PM3Render2D_Width(p->var.xres - sx)) |
+				      (PM3Render2D_Height(p->var.yres)));
+	}
+	
+	/* bottom margin left -> right */
+	PM3_WAIT(4);
+	
+	PM3_WRITE_REG(PM3Config2D,
+		      PM3Config2D_UseConstantSource |
+		      PM3Config2D_ForegroundROPEnable |
+		      (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+		      PM3Config2D_FBWriteEnable);
+	
+	if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+		PM3_WRITE_REG(PM3ForegroundColor, c);
+	else
+		PM3_WRITE_REG(PM3FBBlockColor, c);
+	
+	
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(p->var.xoffset)) |
+		      (PM3RectanglePosition_YOffset(p->var.yoffset + sy)));
+	
+	if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      PM3Render2D_SpanOperation |
+			      (PM3Render2D_Width(p->var.xres)) |
+			      (PM3Render2D_Height(p->var.yres - sy)));
+	else
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      (PM3Render2D_Width(p->var.xres)) |
+			      (PM3Render2D_Height(p->var.yres - sy)));
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+#endif /* FBCON_HAS_CFB16 */
+#ifdef FBCON_HAS_CFB8
+static void pm3fb_cfb8_clear(struct vc_data *conp,
+			     struct display *p,
+			     int sy, int sx, int height, int width)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	u32 c;
+
+	DTRACE;
+
+	sx = sx * fontwidth(p);
+	width = width * fontwidth(p);
+	sy = sy * fontheight(p);
+	height = height * fontheight(p);
+
+	c = attr_bgcol_ec(p, conp);
+	c |= c << 8;
+	c |= c << 16;
+
+	PM3_WAIT(4);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable);
+
+	PM3_WRITE_REG(PM3ForegroundColor, c);
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(sx)) |
+		      (PM3RectanglePosition_YOffset(sy)));
+
+	PM3_WRITE_REG(PM3Render2D,
+		      PM3Render2D_XPositive |
+		      PM3Render2D_YPositive |
+		      PM3Render2D_Operation_Normal |
+		      PM3Render2D_SpanOperation |
+		      (PM3Render2D_Width(width)) |
+		      (PM3Render2D_Height(height)));
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+static void pm3fb_cfb8_clear_margins(struct vc_data *conp,
+				     struct display *p, int bottom_only)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	int sx, sy;
+	u32 c;
+
+	DTRACE;
+
+	sx = conp->vc_cols * fontwidth(p);	/* right margin */
+	sy = conp->vc_rows * fontheight(p);	/* bottom margin */
+	c = attr_bgcol_ec(p, conp);
+	c |= c << 8;
+	c |= c << 16;
+
+	if (!bottom_only) {	/* right margin top->bottom */
+		PM3_WAIT(4);
+
+		PM3_WRITE_REG(PM3Config2D,
+					  PM3Config2D_UseConstantSource |
+					  PM3Config2D_ForegroundROPEnable |
+					  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+					  PM3Config2D_FBWriteEnable);
+
+		PM3_WRITE_REG(PM3ForegroundColor, c);
+
+		PM3_WRITE_REG(PM3RectanglePosition,
+			      (PM3RectanglePosition_XOffset
+			       (p->var.xoffset +
+				sx)) | (PM3RectanglePosition_YOffset(p->
+								     var.
+								     yoffset)));
+
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      PM3Render2D_SpanOperation |
+			      (PM3Render2D_Width(p->var.xres - sx)) |
+			      (PM3Render2D_Height(p->var.yres)));
+	}
+
+	/* bottom margin left -> right */
+	PM3_WAIT(4);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable);
+
+	PM3_WRITE_REG(PM3ForegroundColor, c);
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(p->var.xoffset)) |
+		      (PM3RectanglePosition_YOffset(p->var.yoffset + sy)));
+
+	PM3_WRITE_REG(PM3Render2D,
+		      PM3Render2D_XPositive |
+		      PM3Render2D_YPositive |
+		      PM3Render2D_Operation_Normal |
+		      PM3Render2D_SpanOperation |
+		      (PM3Render2D_Width(p->var.xres)) |
+		      (PM3Render2D_Height(p->var.yres - sy)));
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+#endif /* FBCON_HAS_CFB8 */
+#if defined(FBCON_HAS_CFB8) || defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
+static void pm3fb_cfbX_bmove(struct display *p,
+			     int sy, int sx,
+			     int dy, int dx, int height, int width)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	int x_align, o_x, o_y;
+
+	DTRACE;
+
+	sx = sx * fontwidth(p);
+	dx = dx * fontwidth(p);
+	width = width * fontwidth(p);
+	sy = sy * fontheight(p);
+	dy = dy * fontheight(p);
+	height = height * fontheight(p);
+
+	o_x = sx - dx;		/*(sx > dx ) ? (sx - dx) : (dx - sx); */
+	o_y = sy - dy;		/*(sy > dy ) ? (sy - dy) : (dy - sy); */
+
+	x_align = (sx & 0x1f);
+
+	PM3_WAIT(6);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UserScissorEnable |
+				  PM3Config2D_ForegroundROPEnable |
+				  PM3Config2D_Blocking |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable);
+
+	PM3_WRITE_REG(PM3ScissorMinXY,
+		      ((dy & 0x0fff) << 16) | (dx & 0x0fff));
+	PM3_WRITE_REG(PM3ScissorMaxXY,
+				  (((dy + height) & 0x0fff) << 16) |
+				  ((dx + width) & 0x0fff));
+
+	PM3_WRITE_REG(PM3FBSourceReadBufferOffset,
+		      PM3FBSourceReadBufferOffset_XOffset(o_x) |
+		      PM3FBSourceReadBufferOffset_YOffset(o_y));
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(dx - x_align)) |
+		      (PM3RectanglePosition_YOffset(dy)));
+
+	PM3_WRITE_REG(PM3Render2D,
+		      ((sx > dx) ? PM3Render2D_XPositive : 0) |
+		      ((sy > dy) ? PM3Render2D_YPositive : 0) |
+		      PM3Render2D_Operation_Normal |
+		      PM3Render2D_SpanOperation |
+		      PM3Render2D_FBSourceReadEnable |
+		      (PM3Render2D_Width(width + x_align)) |
+		      (PM3Render2D_Height(height)));
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+static void pm3fb_cfbX_putc(struct vc_data *conp, struct display *p,
+			    int c, int yy, int xx)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	u8 *cdat, asx = 0, asy = 0, o_x = 0, o_y = 0;
+	u32 fgx, bgx, ldat;
+	int sx, sy, i;
+
+	DTRACE;
+
+	if (l_fb_info->current_par->depth == 8)
+		fgx = attr_fgcol(p, c);
+	else if (depth2bpp(l_fb_info->current_par->depth) == 16)
+		fgx = ((u16 *) p->dispsw_data)[attr_fgcol(p, c)];
+	else
+		fgx = ((u32 *) p->dispsw_data)[attr_fgcol(p, c)];
+
+	PM3_COLOR(fgx);
+
+	if (l_fb_info->current_par->depth == 8)
+		bgx = attr_bgcol(p, c);
+	else if (depth2bpp(l_fb_info->current_par->depth) == 16)
+		bgx = ((u16 *) p->dispsw_data)[attr_bgcol(p, c)];
+	else
+		bgx = ((u32 *) p->dispsw_data)[attr_bgcol(p, c)];
+
+	PM3_COLOR(bgx);
+
+	PM3_WAIT(4);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable | PM3Config2D_OpaqueSpan);
+
+	PM3_WRITE_REG(PM3ForegroundColor, fgx);
+	PM3_WRITE_REG(PM3FillBackgroundColor, bgx);
+
+	/* WARNING : adress select X need to specify 8 bits for fontwidth <= 8 */
+	/* and 16 bits for fontwidth <= 16 */
+	/* same in _putcs, same for Y and fontheight */
+	if (fontwidth(p) <= 8)
+		asx = 2;
+	else if (fontwidth(p) <= 16)
+		asx = 3;	/* look OK */
+	if (fontheight(p) <= 8)
+		asy = 2;
+	else if (fontheight(p) <= 16)
+		asy = 3;	/* look OK */
+	else if (fontheight(p) <= 32)
+		asy = 4;	/* look OK */
+
+	sx = xx * fontwidth(p);
+	sy = yy * fontheight(p);
+
+	if (fontwidth(p) <= 8)
+		o_x = (8 - (sx & 0x7)) & 0x7;
+	else if (fontwidth(p) <= 16)
+		o_x = (16 - (sx & 0xF)) & 0xF;
+	if (fontheight(p) <= 8)
+		o_y = (8 - (sy & 0x7)) & 0x7;
+	else if (fontheight(p) <= 16)
+		o_y = (16 - (sy & 0xF)) & 0xF;
+	else if (fontheight(p) <= 32)
+		o_y = (32 - (sy & 0x1F)) & 0x1F;
+
+	PM3_WRITE_REG(PM3AreaStippleMode, (o_x << 7) | (o_y << 12) |	/* x_offset, y_offset in pattern */
+		      (1 << 18) |	/* BE */
+		      1 | (asx << 1) | (asy << 4) |	/* address select x/y */
+		      (1 << 20));	/* OpaqueSpan */
+
+	if (fontwidth(p) <= 8) {
+		cdat = p->fontdata + (c & p->charmask) * fontheight(p);
+	} else {
+		cdat =
+		    p->fontdata +
+		    ((c & p->charmask) * (fontheight(p) << 1));
+	}
+
+	PM3_WAIT(2 + fontheight(p));
+
+	for (i = 0; i < fontheight(p); i++) {	/* assume fontheight <= 32 */
+		if (fontwidth(p) <= 8) {
+			ldat = *cdat++;
+		} else {	/* assume fontwidth <= 16 ATM */
+
+			ldat = ((*cdat++) << 8);
+			ldat |= *cdat++;
+		}
+		PM3_WRITE_REG(AreaStipplePattern_indexed(i), ldat);
+	}
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(sx)) |
+		      (PM3RectanglePosition_YOffset(sy)));
+
+	PM3_WRITE_REG(PM3Render2D,
+		      PM3Render2D_AreaStippleEnable |
+		      PM3Render2D_XPositive |
+		      PM3Render2D_YPositive |
+		      PM3Render2D_Operation_Normal |
+		      PM3Render2D_SpanOperation |
+		      (PM3Render2D_Width(fontwidth(p))) |
+		      (PM3Render2D_Height(fontheight(p))));
+
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+static void pm3fb_cfbX_putcs(struct vc_data *conp, struct display *p,
+			     const unsigned short *s, int count, int yy,
+			     int xx)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+	u8 *cdat, asx = 0, asy = 0, o_x = 0, o_y = 0;
+	u32 fgx, bgx, ldat;
+	int sx, sy, i, j;
+	u16 sc;
+
+	DTRACE;
+
+	sc = scr_readw(s);
+	if (l_fb_info->current_par->depth == 8)
+		fgx = attr_fgcol(p, sc);
+	else if (depth2bpp(l_fb_info->current_par->depth) == 16)
+		fgx = ((u16 *) p->dispsw_data)[attr_fgcol(p, sc)];
+	else
+		fgx = ((u32 *) p->dispsw_data)[attr_fgcol(p, sc)];
+	
+	PM3_COLOR(fgx);
+	
+	if (l_fb_info->current_par->depth == 8)
+		bgx = attr_bgcol(p, sc);
+	else if (depth2bpp(l_fb_info->current_par->depth) == 16)
+		bgx = ((u16 *) p->dispsw_data)[attr_bgcol(p, sc)];
+	else
+		bgx = ((u32 *) p->dispsw_data)[attr_bgcol(p, sc)];
+	
+	PM3_COLOR(bgx);
+
+	PM3_WAIT(4);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0x3)) |	/* Ox3 is GXcopy */
+				  PM3Config2D_FBWriteEnable |
+				  PM3Config2D_OpaqueSpan);
+
+	PM3_WRITE_REG(PM3ForegroundColor, fgx);
+	PM3_WRITE_REG(PM3FillBackgroundColor, bgx);
+
+	/* WARNING : adress select X need to specify 8 bits for fontwidth <= 8 */
+	/* and 16 bits for fontwidth <= 16 */
+	/* same in _putc, same for Y and fontheight */
+	if (fontwidth(p) <= 8)
+		asx = 2;
+	else if (fontwidth(p) <= 16)
+		asx = 3;	/* look OK */
+	if (fontheight(p) <= 8)
+		asy = 2;
+	else if (fontheight(p) <= 16)
+		asy = 3;	/* look OK */
+	else if (fontheight(p) <= 32)
+		asy = 4;	/* look OK */
+
+	sy = yy * fontheight(p);
+
+	if (fontheight(p) <= 8)
+		o_y = (8 - (sy & 0x7)) & 0x7;
+	else if (fontheight(p) <= 16)
+		o_y = (16 - (sy & 0xF)) & 0xF;
+	else if (fontheight(p) <= 32)
+		o_y = (32 - (sy & 0x1F)) & 0x1F;
+
+	for (j = 0; j < count; j++) {
+		sc = scr_readw(s + j);
+		if (fontwidth(p) <= 8)
+			cdat = p->fontdata +
+				(sc & p->charmask) * fontheight(p);
+		else
+			cdat = p->fontdata +
+				((sc & p->charmask) * fontheight(p) << 1);
+		
+		sx = (xx + j) * fontwidth(p);
+
+		if (fontwidth(p) <= 8)
+			o_x = (8 - (sx & 0x7)) & 0x7;
+		else if (fontwidth(p) <= 16)
+			o_x = (16 - (sx & 0xF)) & 0xF;
+
+		PM3_WAIT(3 + fontheight(p));
+
+		PM3_WRITE_REG(PM3AreaStippleMode, (o_x << 7) | (o_y << 12) | /* x_offset, y_offset in pattern */
+			      (1 << 18) | /* BE */
+			      1 | (asx << 1) | (asy << 4) | /* address select x/y */
+			      (1 << 20)); /* OpaqueSpan */
+
+		for (i = 0; i < fontheight(p); i++) { /* assume fontheight <= 32 */
+			if (fontwidth(p) <= 8) {
+				ldat = *cdat++;
+			} else { /* assume fontwidth <= 16 ATM */
+				ldat = ((*cdat++) << 8);
+				ldat |= *cdat++;
+			}
+			PM3_WRITE_REG(AreaStipplePattern_indexed(i), ldat);
+		}
+
+		PM3_WRITE_REG(PM3RectanglePosition,
+			      (PM3RectanglePosition_XOffset(sx)) |
+			      (PM3RectanglePosition_YOffset(sy)));
+
+		PM3_WRITE_REG(PM3Render2D,
+			      PM3Render2D_AreaStippleEnable |
+			      PM3Render2D_XPositive |
+			      PM3Render2D_YPositive |
+			      PM3Render2D_Operation_Normal |
+			      PM3Render2D_SpanOperation |
+			      (PM3Render2D_Width(fontwidth(p))) |
+			      (PM3Render2D_Height(fontheight(p))));
+	}
+	pm3fb_wait_pm3(l_fb_info);
+}
+
+static void pm3fb_cfbX_revc(struct display *p, int xx, int yy)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
+
+	xx = xx * fontwidth(p);
+	yy = yy * fontheight(p);
+
+	if (l_fb_info->current_par->depth == 8)
+	{
+		if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+			PM3_SLOW_WRITE_REG(PM3FBSoftwareWriteMask, 0x0F0F0F0F);
+		else
+			PM3_SLOW_WRITE_REG(PM3FBHardwareWriteMask, 0x0F0F0F0F);
+	}
+
+	PM3_WAIT(3);
+
+	PM3_WRITE_REG(PM3Config2D,
+				  PM3Config2D_UseConstantSource |
+				  PM3Config2D_ForegroundROPEnable |
+				  (PM3Config2D_ForegroundROP(0xa)) |	/* Oxa is GXinvert */
+				  PM3Config2D_FBDestReadEnable |
+				  PM3Config2D_FBWriteEnable);
+
+	PM3_WRITE_REG(PM3RectanglePosition,
+		      (PM3RectanglePosition_XOffset(xx)) |
+		      (PM3RectanglePosition_YOffset(yy)));
+
+	PM3_WRITE_REG(PM3Render2D,
+		      PM3Render2D_XPositive |
+		      PM3Render2D_YPositive |
+		      PM3Render2D_Operation_Normal |
+		      PM3Render2D_SpanOperation |
+		      (PM3Render2D_Width(fontwidth(p))) |
+		      (PM3Render2D_Height(fontheight(p))));
+
+	pm3fb_wait_pm3(l_fb_info);
+
+	if (l_fb_info->current_par->depth == 8)
+	{
+		if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
+			PM3_SLOW_WRITE_REG(PM3FBSoftwareWriteMask, 0xFFFFFFFF);
+		else
+			PM3_SLOW_WRITE_REG(PM3FBHardwareWriteMask, 0xFFFFFFFF);
+	}
+}
+
+#endif /* FBCON_HAS_CFB8 || FBCON_HAS_CFB16 || FBCON_HAS_CFB32 */
+#endif /* PM3FB_USE_ACCEL */
+/* *********************************** */
+/* ***** pre-init board(s) setup ***** */
+/* *********************************** */
+
+static void pm3fb_mode_setup(char *mode, unsigned long board_num)
+{
+	struct pm3fb_info *l_fb_info = &(fb_info[board_num]);
+	struct pm3fb_par *l_fb_par = &(current_par[board_num]);
+	unsigned long i = 0;
+
+	current_par_valid[board_num] = 0;
+
+	if (!strncmp(mode, "current", 7)) {
+		l_fb_info->use_current = 1;	/* default w/ OpenFirmware */
+	} else {
+		while ((mode_base[i].name[0])
+		       && (!current_par_valid[board_num])) {
+			if (!
+			    (strncmp
+			     (mode, mode_base[i].name,
+			      strlen(mode_base[i].name)))) {
+				memcpy(l_fb_par, &(mode_base[i].user_mode),
+				       sizeof(struct pm3fb_par));
+				current_par_valid[board_num] = 1;
+				DPRINTK(2, "Mode set to %s\n",
+					mode_base[i].name);
+			}
+			i++;
+		}
+		DASSERT(current_par_valid[board_num],
+			"Valid mode on command line\n");
+	}
+}
+
+static void pm3fb_pciid_setup(char *pciid, unsigned long board_num)
+{
+	short l_bus = -1, l_slot = -1, l_func = -1;
+	char *next;
+
+	if (pciid) {
+		l_bus = simple_strtoul(pciid, &next, 10);
+		if (next && (next[0] == ':')) {
+			pciid = next + 1;
+			l_slot = simple_strtoul(pciid, &next, 10);
+			if (next && (next[0] == ':')) {
+				pciid = next + 1;
+				l_func =
+				    simple_strtoul(pciid, (char **) NULL,
+						   10);
+			}
+		}
+	} else
+		return;
+
+	if ((l_bus >= 0) && (l_slot >= 0) && (l_func >= 0)) {
+		bus[board_num] = l_bus;
+		slot[board_num] = l_slot;
+		func[board_num] = l_func;
+		DPRINTK(2, "Board #%ld will be PciId: %hd:%hd:%hd\n",
+			board_num, l_bus, l_slot, l_func);
+	} else {
+		DPRINTK(1, "Invalid PciId: %hd:%hd:%hd for board #%ld\n",
+			l_bus, l_slot, l_func, board_num);
+	}
+}
+
+static void pm3fb_font_setup(char *lf, unsigned long board_num)
+{
+	unsigned long lfs = strlen(lf);
+
+	if (lfs > (PM3_FONTNAME_SIZE - 1)) {
+		DPRINTK(1, "Fontname %s too long\n", lf);
+		return;
+	}
+	strncpy(fontn[board_num], lf, lfs);
+	fontn[board_num][lfs] = '\0';
+}
+
+static void pm3fb_bootdepth_setup(char *bds, unsigned long board_num)
+{
+	unsigned long bd = simple_strtoul(bds, (char **) NULL, 10);
+
+	if (!(depth_supported(bd))) {
+		printk(KERN_WARNING "pm3fb: ignoring invalid depth %s for board #%ld\n",
+		       bds, board_num);
+		return;
+	}
+	depth[board_num] = bd;
+}
+
+static void pm3fb_forcesize_setup(char *bds, unsigned long board_num)
+{
+	unsigned long bd = simple_strtoul(bds, (char **) NULL, 10);
+
+	if (bd > 64) {
+		printk(KERN_WARNING "pm3fb: ignoring invalid memory size %s for board #%ld\n",
+		       bds, board_num);
+		return;
+	}
+	forcesize[board_num] = bd;
+}
+
+static char *pm3fb_boardnum_setup(char *options, unsigned long *bn)
+{
+	char *next;
+
+	if (!(CHAR_IS_NUM(options[0]))) {
+		(*bn) = 0;
+		return (options);
+	}
+
+	(*bn) = simple_strtoul(options, &next, 10);
+
+	if (next && (next[0] == ':') && ((*bn) >= 0)
+	    && ((*bn) <= PM3_MAX_BOARD)) {
+		DPRINTK(2, "Board_num seen as %ld\n", (*bn));
+		return (next + 1);
+	} else {
+		(*bn) = 0;
+		DPRINTK(2, "Board_num default to %ld\n", (*bn));
+		return (options);
+	}
+}
+
+static void pm3fb_real_setup(char *options)
+{
+	char *next;
+	unsigned long i, bn;
+	struct pm3fb_info *l_fb_info;
+
+	DTRACE;
+
+	DPRINTK(2, "Options : %s\n", options);
+
+	for (i = 0; i < PM3_MAX_BOARD; i++) {
+		l_fb_info = &(fb_info[i]);
+		memset(l_fb_info, 0, sizeof(struct pm3fb_info));
+		l_fb_info->gen.fbhw = &pm3fb_switch;
+		l_fb_info->board_num = i;
+		current_par_valid[i] = 0;
+		slot[i] = -1;
+		func[i] = -1;
+		bus[i] = -1;
+		disable[i] = 0;
+		noaccel[i] = 0;
+		fontn[i][0] = '\0';
+		depth[i] = 0;
+		l_fb_info->current_par = &(current_par[i]);
+	}
+
+	/* eat up prefix pm3fb and whatever is used as separator i.e. :,= */
+	if (!strncmp(options, "pm3fb", 5)) {
+		options += 5;
+		while (((*options) == ',') || ((*options) == ':')
+		       || ((*options) == '='))
+			options++;
+	}
+
+	while (options) {
+		bn = 0;
+		if ((next = strchr(options, ','))) {
+			(*next) = '\0';
+			next++;
+		}
+
+		if (!strncmp(options, "mode:", 5)) {
+			options = pm3fb_boardnum_setup(options + 5, &bn);
+			DPRINTK(2, "Setting mode for board #%ld\n", bn);
+			pm3fb_mode_setup(options, bn);
+		} else if (!strncmp(options, "off:", 4)) {
+			options = pm3fb_boardnum_setup(options + 4, &bn);
+			DPRINTK(2, "Disabling board #%ld\n", bn);
+			disable[bn] = 1;
+		} else if (!strncmp(options, "off", 3)) {	/* disable everything */
+			for (i = 0; i < PM3_MAX_BOARD; i++)
+				disable[i] = 1;
+		} else if (!strncmp(options, "disable:", 8)) {
+			options = pm3fb_boardnum_setup(options + 8, &bn);
+			DPRINTK(2, "Disabling board #%ld\n", bn);
+			disable[bn] = 1;
+		} else if (!strncmp(options, "pciid:", 6)) {
+			options = pm3fb_boardnum_setup(options + 6, &bn);
+			DPRINTK(2, "Setting PciID for board #%ld\n", bn);
+			pm3fb_pciid_setup(options, bn);
+		} else if (!strncmp(options, "noaccel:", 8)) {
+			options = pm3fb_boardnum_setup(options + 8, &bn);
+			noaccel[bn] = 1;
+		} else if (!strncmp(options, "font:", 5)) {
+			options = pm3fb_boardnum_setup(options + 5, &bn);
+			pm3fb_font_setup(options, bn);
+		} else if (!strncmp(options, "depth:", 6)) {
+			options = pm3fb_boardnum_setup(options + 6, &bn);
+			pm3fb_bootdepth_setup(options, bn);
+		} else if (!strncmp(options, "printtimings", 12)) {
+			printtimings = 1;
+		} else if (!strncmp(options, "flatpanel:", 10)) {
+			options = pm3fb_boardnum_setup(options + 10, &bn);
+			flatpanel[bn] = 1;
+		} else if (!strncmp(options, "forcesize:", 10)) {
+			options = pm3fb_boardnum_setup(options + 10, &bn);
+			pm3fb_forcesize_setup(options, bn);
+		}
+		options = next;
+	}
+}
+
+/* ********************************************** */
+/* ***** framebuffer API standard functions ***** */
+/* ********************************************** */
+
+static int pm3fb_open(struct fb_info *info, int user)
+{
+	DTRACE;
+
+	MOD_INC_USE_COUNT;
+
+	return (0);
+}
+
+static int pm3fb_release(struct fb_info *info, int user)
+{
+	DTRACE;
+
+	MOD_DEC_USE_COUNT;
+
+	return (0);
+}
+
+static int pm3fb_encode_fix(struct fb_fix_screeninfo *fix,
+			    const void *par, struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+	struct pm3fb_par *p = (struct pm3fb_par *) par;
+
+	DTRACE;
+
+	strcpy(fix->id, permedia3_name);
+	fix->smem_start = (unsigned long)l_fb_info->p_fb;
+	fix->smem_len = l_fb_info->fb_size;
+	fix->mmio_start = (unsigned long)l_fb_info->pIOBase;
+	fix->mmio_len = PM3_REGS_SIZE;
+#ifdef PM3FB_USE_ACCEL
+	if (!(noaccel[l_fb_info->board_num]))
+		fix->accel = FB_ACCEL_3DLABS_PERMEDIA3;
+	else
+#endif /* PM3FB_USE_ACCEL */
+		fix->accel = FB_ACCEL_NONE;
+	fix->type = FB_TYPE_PACKED_PIXELS;
+	fix->visual =
+	    (p->depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
+	if (current_par_valid[l_fb_info->board_num])
+		fix->line_length =
+			l_fb_info->current_par->width *
+			depth2ByPP(l_fb_info->current_par->depth);
+	else
+		fix->line_length = 0;
+	fix->xpanstep = 64 / depth2bpp(p->depth);
+	fix->ypanstep = 1;
+	fix->ywrapstep = 0;
+	return (0);
+}
+
+static int pm3fb_decode_var(const struct fb_var_screeninfo *var,
+			    void *par, struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+	struct pm3fb_par *p = (struct pm3fb_par *) par;
+	struct pm3fb_par temp_p;
+	u32 xres;
+
+	DTRACE;
+
+	DASSERT((var != NULL), "fb_var_screeninfo* not NULL");
+	DASSERT((p != NULL), "pm3fb_par* not NULL");
+	DASSERT((l_fb_info != NULL), "pm3fb_info* not NULL");
+
+	memset(&temp_p, 0, sizeof(struct pm3fb_par));
+	temp_p.width = (var->xres_virtual + 7) & ~7;
+	temp_p.height = var->yres_virtual;
+
+	if (!(depth_supported(var->bits_per_pixel))) /* round unsupported up to a multiple of 8 */
+		temp_p.depth = depth2bpp(var->bits_per_pixel);
+	else
+		temp_p.depth = var->bits_per_pixel;
+
+	temp_p.depth = (temp_p.depth > 32) ? 32 : temp_p.depth; /* max 32 */
+	temp_p.depth = (temp_p.depth == 24) ? 32 : temp_p.depth; /* 24 unsupported, round-up to 32 */
+
+	if ((temp_p.depth == 16) && (var->red.length == 5) && (var->green.length == 5) && (var->blue.length == 5))
+		temp_p.depth = 15; /* RGBA 5551 is stored as depth 15 */
+
+	if ((temp_p.depth == 16) && (var->red.length == 4) && (var->green.length == 4) && (var->blue.length == 4))
+		temp_p.depth = 12; /* RGBA 4444  is stored as depth 12 */
+
+
+	DPRINTK(2,
+		"xres: %d, yres: %d, vxres: %d, vyres: %d ; xoffset:%d, yoffset: %d\n",
+		var->xres, var->yres, var->xres_virtual, var->yres_virtual,
+		var->xoffset, var->yoffset);
+
+	xres = (var->xres + 31) & ~31;
+	if (temp_p.width < xres + var->xoffset)
+		temp_p.width = xres + var->xoffset;
+	if (temp_p.height < var->yres + var->yoffset)
+		temp_p.height = var->yres + var->yoffset;
+
+	if (temp_p.width > 2048) {
+		DPRINTK(1, "virtual width not supported: %u\n",
+			temp_p.width);
+		return (-EINVAL);
+	}
+	if (var->yres < 200) {
+		DPRINTK(1, "height not supported: %u\n", (u32) var->yres);
+		return (-EINVAL);
+	}
+	if (temp_p.height < 200 || temp_p.height > 4095) {
+		DPRINTK(1, "virtual height not supported: %u\n",
+			temp_p.height);
+		return (-EINVAL);
+	}
+	if (!(depth_supported(temp_p.depth))) {
+		DPRINTK(1, "depth not supported: %u\n", temp_p.depth);
+		return (-EINVAL);
+	}
+	if ((temp_p.width * temp_p.height * depth2ByPP(temp_p.depth)) >
+	    l_fb_info->fb_size) {
+		DPRINTK(1, "no memory for screen (%ux%ux%u)\n",
+			temp_p.width, temp_p.height, temp_p.depth);
+		return (-EINVAL);
+	}
+
+	if ((!var->pixclock) ||
+	    (!var->right_margin) ||
+	    (!var->hsync_len) ||
+	    (!var->left_margin) ||
+	    (!var->lower_margin) ||
+	    (!var->vsync_len) || (!var->upper_margin)
+	    ) {
+		unsigned long i = 0, done = 0;
+		printk(KERN_WARNING "pm3fb: refusing to use a likely wrong timing\n");
+
+		while ((mode_base[i].user_mode.width) && !done) {
+			if ((mode_base[i].user_mode.width == temp_p.width)
+			    && (mode_base[i].user_mode.height ==
+				temp_p.height)) {
+				printk(KERN_NOTICE "pm3fb: using close match %s\n",
+				       mode_base[i].name);
+				temp_p = mode_base[i].user_mode;
+				done = 1;
+			}
+			i++;
+		}
+		if (!done)
+			return (-EINVAL);
+	} else {
+		temp_p.pixclock = PICOS2KHZ(var->pixclock);
+		if (temp_p.pixclock > PM3_MAX_PIXCLOCK) {
+			DPRINTK(1, "pixclock too high (%uKHz)\n",
+				temp_p.pixclock);
+			return (-EINVAL);
+		}
+
+		temp_p.hsstart = var->right_margin;
+		temp_p.hsend = var->right_margin + var->hsync_len;
+		temp_p.hbend =
+		    var->right_margin + var->hsync_len + var->left_margin;
+		temp_p.htotal = xres + temp_p.hbend;
+
+		temp_p.vsstart = var->lower_margin;
+		temp_p.vsend = var->lower_margin + var->vsync_len;
+		temp_p.vbend =
+		    var->lower_margin + var->vsync_len + var->upper_margin;
+		temp_p.vtotal = var->yres + temp_p.vbend;
+
+		temp_p.stride = temp_p.width;
+
+		DPRINTK(2, "Using %d * %d, %d Khz, stride is %08x\n",
+			temp_p.width, temp_p.height, temp_p.pixclock,
+			temp_p.stride);
+
+		temp_p.base =
+		    pm3fb_Shiftbpp(l_fb_info, temp_p.depth,
+				   (var->yoffset * xres) + var->xoffset);
+
+		temp_p.video = 0;
+
+		if (var->sync & FB_SYNC_HOR_HIGH_ACT)
+			temp_p.video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
+		else
+			temp_p.video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
+
+		if (var->sync & FB_SYNC_VERT_HIGH_ACT)
+			temp_p.video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
+		else
+			temp_p.video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
+
+		if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
+			DPRINTK(1, "Interlaced mode not supported\n\n");
+			return (-EINVAL);
+		}
+
+		if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
+			temp_p.video |= PM3VideoControl_LINE_DOUBLE_ON;
+		else
+			temp_p.video |= PM3VideoControl_LINE_DOUBLE_OFF;
+
+		if (var->activate == FB_ACTIVATE_NOW)
+			temp_p.video |= PM3VideoControl_ENABLE;
+		else {
+			temp_p.video |= PM3VideoControl_DISABLE;
+			DPRINTK(2, "PM3Video disabled\n");
+		}
+
+		switch (temp_p.depth) {
+		case 8:
+			temp_p.video |= PM3VideoControl_PIXELSIZE_8BIT;
+			break;
+		case 12:
+		case 15:
+		case 16:
+			temp_p.video |= PM3VideoControl_PIXELSIZE_16BIT;
+			break;
+		case 32:
+			temp_p.video |= PM3VideoControl_PIXELSIZE_32BIT;
+			break;
+		default:
+			DPRINTK(1, "Unsupported depth\n");
+			break;
+		}
+	}
+	(*p) = temp_p;
+
+#ifdef PM3FB_USE_ACCEL
+	if (var->accel_flags & FB_ACCELF_TEXT)
+		noaccel[l_fb_info->board_num] = 0;
+	else
+		noaccel[l_fb_info->board_num] = 1;
+#endif /* PM3FB_USE_ACCEL */
+
+	return (0);
+}
+
+static void pm3fb_encode_depth(struct fb_var_screeninfo *var, long d)
+{
+	switch (d) {
+	case 8:
+		var->red.length = var->green.length = var->blue.length = 8;
+		var->red.offset = var->green.offset = var->blue.offset = 0;
+		var->transp.offset = var->transp.length = 0;
+		break;
+
+	case 12:
+		var->red.offset = 8;
+		var->red.length = 4;
+		var->green.offset = 4;
+		var->green.length = 4;
+		var->blue.offset = 0;
+		var->blue.length = 4;
+		var->transp.offset = 12;
+		var->transp.length = 4;
+		break;
+
+	case 15:
+		var->red.offset = 10;
+		var->red.length = 5;
+		var->green.offset = 5;
+		var->green.length = 5;
+		var->blue.offset = 0;
+		var->blue.length = 5;
+		var->transp.offset = 15;
+		var->transp.length = 1;
+		break;
+
+	case 16:
+		var->red.offset = 11;
+		var->red.length = 5;
+		var->green.offset = 5;
+		var->green.length = 6;
+		var->blue.offset = 0;
+		var->blue.length = 5;
+		var->transp.offset = var->transp.length = 0;
+		break;
+
+	case 32:
+		var->transp.offset = 24;
+		var->red.offset = 16;
+		var->green.offset = 8;
+		var->blue.offset = 0;
+		var->red.length = var->green.length =
+			var->blue.length = var->transp.length = 8;
+		break;
+
+	default:
+		DPRINTK(1, "Unsupported depth %ld\n", d);
+		break;
+	}
+}
+
+static int pm3fb_encode_var(struct fb_var_screeninfo *var,
+			    const void *par, struct fb_info_gen *info)
+{
+	struct pm3fb_par *p = (struct pm3fb_par *) par;
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+
+	u32 base;
+
+	DTRACE;
+
+	DASSERT((var != NULL), "fb_var_screeninfo* not NULL");
+	DASSERT((p != NULL), "pm3fb_par* not NULL");
+	DASSERT((info != NULL), "fb_info_gen* not NULL");
+
+	memset(var, 0, sizeof(struct fb_var_screeninfo));
+
+#ifdef PM3FB_USE_ACCEL
+	if (!(noaccel[l_fb_info->board_num]))
+		var->accel_flags |= FB_ACCELF_TEXT;
+#endif /* PM3FB_USE_ACCEL */
+
+	var->xres_virtual = p->width;
+	var->yres_virtual = p->height;
+	var->xres = p->htotal - p->hbend;
+	var->yres = p->vtotal - p->vbend;
+
+	DPRINTK(2, "xres = %d, yres : %d\n", var->xres, var->yres);
+
+	var->right_margin = p->hsstart;
+	var->hsync_len = p->hsend - p->hsstart;
+	var->left_margin = p->hbend - p->hsend;
+	var->lower_margin = p->vsstart;
+	var->vsync_len = p->vsend - p->vsstart;
+	var->upper_margin = p->vbend - p->vsend;
+	var->bits_per_pixel = depth2bpp(p->depth);
+	
+	pm3fb_encode_depth(var, p->depth);
+
+	base = pm3fb_Unshiftbpp(l_fb_info, p->depth, p->base);
+
+	var->xoffset = base % var->xres;
+	var->yoffset = base / var->xres;
+
+	var->height = var->width = -1;
+
+	var->pixclock = KHZ2PICOS(p->pixclock);
+
+	if ((p->video & PM3VideoControl_HSYNC_MASK) ==
+	    PM3VideoControl_HSYNC_ACTIVE_HIGH)
+		var->sync |= FB_SYNC_HOR_HIGH_ACT;
+	if ((p->video & PM3VideoControl_VSYNC_MASK) ==
+	    PM3VideoControl_VSYNC_ACTIVE_HIGH)
+		var->sync |= FB_SYNC_VERT_HIGH_ACT;
+	if (p->video & PM3VideoControl_LINE_DOUBLE_ON)
+		var->vmode = FB_VMODE_DOUBLE;
+
+	return (0);
+}
+
+static void pm3fb_get_par(void *par, struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+
+	DTRACE;
+
+	if (!current_par_valid[l_fb_info->board_num]) {
+		if (l_fb_info->use_current)
+			pm3fb_read_mode(l_fb_info, l_fb_info->current_par);
+		else
+			memcpy(l_fb_info->current_par,
+			       &(mode_base[0].user_mode),
+			       sizeof(struct pm3fb_par));
+		current_par_valid[l_fb_info->board_num] = 1;
+	}
+	*((struct pm3fb_par *) par) = *(l_fb_info->current_par);
+}
+
+static void pm3fb_set_par(const void *par, struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+
+	DTRACE;
+
+	*(l_fb_info->current_par) = *((struct pm3fb_par *) par);
+	current_par_valid[l_fb_info->board_num] = 1;
+
+	pm3fb_write_mode(l_fb_info);
+
+#ifdef PM3FB_USE_ACCEL
+	pm3fb_init_engine(l_fb_info);
+#endif /* PM3FB_USE_ACCEL */
+}
+
+static void pm3fb_set_color(struct pm3fb_info *l_fb_info,
+			    unsigned char regno, unsigned char r,
+			    unsigned char g, unsigned char b)
+{
+	DTRACE;
+
+	PM3_SLOW_WRITE_REG(PM3RD_PaletteWriteAddress, regno);
+	PM3_SLOW_WRITE_REG(PM3RD_PaletteData, r);
+	PM3_SLOW_WRITE_REG(PM3RD_PaletteData, g);
+	PM3_SLOW_WRITE_REG(PM3RD_PaletteData, b);
+}
+
+static int pm3fb_getcolreg(unsigned regno, unsigned *red, unsigned *green,
+			   unsigned *blue, unsigned *transp,
+			   struct fb_info *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+
+	DTRACE;
+
+	if (regno < 256) {
+		*red =
+		    l_fb_info->palette[regno].red << 8 | l_fb_info->
+		    palette[regno].red;
+		*green =
+		    l_fb_info->palette[regno].green << 8 | l_fb_info->
+		    palette[regno].green;
+		*blue =
+		    l_fb_info->palette[regno].blue << 8 | l_fb_info->
+		    palette[regno].blue;
+		*transp =
+		    l_fb_info->palette[regno].transp << 8 | l_fb_info->
+		    palette[regno].transp;
+	}
+	return (regno > 255);
+}
+
+static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
+			   unsigned blue, unsigned transp,
+			   struct fb_info *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+
+	DTRACE;
+
+	if (regno < 16) {
+		switch (l_fb_info->current_par->depth) {
+#ifdef FBCON_HAS_CFB8
+		case 8:
+			break;
+#endif
+#ifdef FBCON_HAS_CFB16
+		case 12:
+			l_fb_info->cmap.cmap12[regno] =
+				(((u32) red & 0xf000) >> 4) |
+				(((u32) green & 0xf000) >> 8) |
+				(((u32) blue & 0xf000) >> 12);
+			break;
+
+		case 15:
+			l_fb_info->cmap.cmap15[regno] =
+				(((u32) red & 0xf800) >> 1) |
+				(((u32) green & 0xf800) >> 6) |
+				(((u32) blue & 0xf800) >> 11);
+			break;
+
+		case 16:
+			l_fb_info->cmap.cmap16[regno] =
+			    ((u32) red & 0xf800) |
+			    (((u32) green & 0xfc00) >> 5) |
+			    (((u32) blue & 0xf800) >> 11);
+			break;
+#endif
+#ifdef FBCON_HAS_CFB32
+		case 32:
+			l_fb_info->cmap.cmap32[regno] =
+			    (((u32) transp & 0xff00) << 16) |
+			    (((u32) red & 0xff00) << 8) |
+			    (((u32) green & 0xff00)) |
+			    (((u32) blue & 0xff00) >> 8);
+			break;
+#endif
+		default:
+			DPRINTK(1, "bad depth %u\n",
+				l_fb_info->current_par->depth);
+			break;
+		}
+	}
+	if (regno < 256) {
+		l_fb_info->palette[regno].red = red >> 8;
+		l_fb_info->palette[regno].green = green >> 8;
+		l_fb_info->palette[regno].blue = blue >> 8;
+		l_fb_info->palette[regno].transp = transp >> 8;
+		if (l_fb_info->current_par->depth == 8)
+			pm3fb_set_color(l_fb_info, regno, red >> 8,
+					green >> 8, blue >> 8);
+	}
+	return (regno > 255);
+}
+
+static int pm3fb_blank(int blank_mode, struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+	u32 video;
+
+	DTRACE;
+
+	if (!current_par_valid[l_fb_info->board_num])
+		return (1);
+
+	video = l_fb_info->current_par->video;
+
+	/*
+	 * Oxygen VX1 - it appears that setting PM3VideoControl and
+	 * then PM3RD_SyncControl to the same SYNC settings undoes
+	 * any net change - they seem to xor together.  Only set the
+	 * sync options in PM3RD_SyncControl.  --rmk
+	 */
+	video &= ~(PM3VideoControl_HSYNC_MASK |
+		   PM3VideoControl_VSYNC_MASK);
+	video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
+		 PM3VideoControl_VSYNC_ACTIVE_HIGH;
+
+	if (blank_mode > 0) {
+		switch (blank_mode - 1) {
+
+		case VESA_NO_BLANKING:	/* FIXME */
+			video = video & ~(PM3VideoControl_ENABLE);
+			break;
+
+		case VESA_HSYNC_SUSPEND:
+			video = video & ~(PM3VideoControl_HSYNC_MASK |
+					  PM3VideoControl_BLANK_ACTIVE_LOW);
+			break;
+		case VESA_VSYNC_SUSPEND:
+			video = video & ~(PM3VideoControl_VSYNC_MASK |
+					  PM3VideoControl_BLANK_ACTIVE_LOW);
+			break;
+		case VESA_POWERDOWN:
+			video = video & ~(PM3VideoControl_HSYNC_MASK |
+					  PM3VideoControl_VSYNC_MASK |
+					  PM3VideoControl_BLANK_ACTIVE_LOW);
+			break;
+		default:
+			DPRINTK(1, "Unsupported blanking %d\n",
+				blank_mode);
+			return (1);
+			break;
+		}
+	}
+
+	PM3_SLOW_WRITE_REG(PM3VideoControl, video);
+
+	return (0);
+}
+
+static void pm3fb_set_disp(const void *par, struct display *disp,
+			   struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+	struct pm3fb_par *p = (struct pm3fb_par *) par;
+	u32 flags;
+
+	DTRACE;
+
+	save_flags(flags);
+	cli();
+	disp->screen_base = l_fb_info->v_fb;
+	switch (p->depth) {
+#ifdef FBCON_HAS_CFB8
+	case 8:
+#ifdef PM3FB_USE_ACCEL
+		if (!(noaccel[l_fb_info->board_num]))
+			disp->dispsw = &pm3fb_cfb8;
+		else
+#endif /* PM3FB_USE_ACCEL */
+			disp->dispsw = &fbcon_cfb8;
+		break;
+#endif
+#ifdef FBCON_HAS_CFB16
+	case 12:
+#ifdef PM3FB_USE_ACCEL
+		if (!(noaccel[l_fb_info->board_num]))
+			disp->dispsw = &pm3fb_cfb16;
+		else
+#endif /* PM3FB_USE_ACCEL */
+			disp->dispsw = &fbcon_cfb16;
+		disp->dispsw_data = l_fb_info->cmap.cmap12;
+		break;
+	case 15:
+#ifdef PM3FB_USE_ACCEL
+		if (!(noaccel[l_fb_info->board_num]))
+			disp->dispsw = &pm3fb_cfb16;
+		else
+#endif /* PM3FB_USE_ACCEL */
+			disp->dispsw = &fbcon_cfb16;
+		disp->dispsw_data = l_fb_info->cmap.cmap15;
+		break;
+	case 16:
+#ifdef PM3FB_USE_ACCEL
+		if (!(noaccel[l_fb_info->board_num]))
+			disp->dispsw = &pm3fb_cfb16;
+		else
+#endif /* PM3FB_USE_ACCEL */
+			disp->dispsw = &fbcon_cfb16;
+		disp->dispsw_data = l_fb_info->cmap.cmap16;
+		break;
+#endif
+#ifdef FBCON_HAS_CFB32
+	case 32:
+#ifdef PM3FB_USE_ACCEL
+		if (!(noaccel[l_fb_info->board_num]))
+			disp->dispsw = &pm3fb_cfb32;
+		else
+#endif /* PM3FB_USE_ACCEL */
+			disp->dispsw = &fbcon_cfb32;
+		disp->dispsw_data = l_fb_info->cmap.cmap32;
+		break;
+#endif /* FBCON_HAS_CFB32 */
+	default:
+		disp->dispsw = &fbcon_dummy;
+		DPRINTK(1, "Invalid depth, using fbcon_dummy\n");
+		break;
+	}
+	restore_flags(flags);
+}
+
+/* */
+static void pm3fb_detect(void)
+{
+	struct pci_dev *dev_array[PM3_MAX_BOARD];
+	struct pci_dev *dev = NULL;
+	struct pm3fb_info *l_fb_info = &(fb_info[0]);
+	unsigned long i, j, done;
+
+	DTRACE;
+
+	for (i = 0; i < PM3_MAX_BOARD; i++) {
+		dev_array[i] = NULL;
+		fb_info[i].dev = NULL;
+	}
+
+	dev =
+	    pci_find_device(PCI_VENDOR_ID_3DLABS,
+			    PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev);
+
+	for (i = 0; ((i < PM3_MAX_BOARD) && dev); i++) {
+		dev_array[i] = dev;
+		dev =
+		    pci_find_device(PCI_VENDOR_ID_3DLABS,
+				    PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev);
+	}
+
+	if (dev) {		/* more than PM3_MAX_BOARD */
+		printk(KERN_WARNING "pm3fb: Warning: more than %d boards found\n",
+		       PM3_MAX_BOARD);
+	}
+
+	if (!dev_array[0]) {	/* not a single board, abort */
+		return;
+	}
+
+	/* allocate user-defined boards */
+	for (i = 0; i < PM3_MAX_BOARD; i++) {
+		if ((bus[i] >= 0) && (slot[i] >= 0) && (func[i] >= 0)) {
+			for (j = 0; j < PM3_MAX_BOARD; j++) {
+				if ((dev_array[j] != NULL) &&
+				    (dev_array[j]->bus->number == bus[i])
+				    && (PCI_SLOT(dev_array[j]->devfn) ==
+					slot[i])
+				    && (PCI_FUNC(dev_array[j]->devfn) ==
+					func[i])) {
+					fb_info[i].dev = dev_array[j];
+					dev_array[j] = NULL;
+				}
+			}
+		}
+	}
+	/* allocate remaining boards */
+	for (i = 0; i < PM3_MAX_BOARD; i++) {
+		if (fb_info[i].dev == NULL) {
+			done = 0;
+			for (j = 0; ((j < PM3_MAX_BOARD) && (!done)); j++) {
+				if (dev_array[j] != NULL) {
+					fb_info[i].dev = dev_array[j];
+					dev_array[j] = NULL;
+					done = 1;
+				}
+			}
+		}
+	}
+
+	/* at that point, all PCI Permedia3 are detected and allocated */
+	/* now, initialize... or not */
+	for (i = 0; i < PM3_MAX_BOARD; i++) {
+		l_fb_info = &(fb_info[i]);
+		if ((l_fb_info->dev) && (!disable[i])) {	/* PCI device was found and not disabled by user */
+#ifdef SUPPORT_FB_OF
+			struct device_node *dp =
+			    find_pci_device_OFnode(l_fb_info->dev->bus->
+						   number,
+						   l_fb_info->dev->devfn);
+
+			if ((dp) && (!strncmp(dp->name, "formacGA12", 10))) {
+				/* do nothing, init of board is done in pm3fb_of_init */
+			} else {
+#endif
+				DPRINTK(2,
+					"found @%lx Vendor %lx Device %lx ; base @ : %lx - %lx - %lx - %lx - %lx - %lx, irq %ld\n",
+					(unsigned long) l_fb_info->dev,
+					(unsigned long) l_fb_info->dev->
+					vendor,
+					(unsigned long) l_fb_info->dev->
+					device,
+					(unsigned long)
+					pci_resource_start(l_fb_info->dev,
+							   0),
+					(unsigned long)
+					pci_resource_start(l_fb_info->dev,
+							   1),
+					(unsigned long)
+					pci_resource_start(l_fb_info->dev,
+							   2),
+					(unsigned long)
+					pci_resource_start(l_fb_info->dev,
+							   3),
+					(unsigned long)
+					pci_resource_start(l_fb_info->dev,
+							   4),
+					(unsigned long)
+					pci_resource_start(l_fb_info->dev,
+							   5),
+					(unsigned long) l_fb_info->dev->
+					irq);
+
+				l_fb_info->pIOBase =
+				    (unsigned char *)
+				    pci_resource_start(l_fb_info->dev, 0);
+#ifdef __BIG_ENDIAN
+				l_fb_info->pIOBase += PM3_REGS_SIZE;
+#endif
+				l_fb_info->vIOBase = (unsigned char *) -1;
+				l_fb_info->p_fb =
+				    (unsigned char *)
+				    pci_resource_start(l_fb_info->dev, 1);
+				l_fb_info->v_fb = (unsigned char *) -1;
+
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5) 	/* full resource management, new in linux-2.4.x */
+				if (!request_mem_region
+				    ((unsigned long)l_fb_info->p_fb, 64 * 1024 * 1024, /* request full aperture size */
+				     "pm3fb")) {
+					printk
+					    (KERN_ERR "pm3fb: Error: couldn't request framebuffer memory, board #%ld\n",
+					     l_fb_info->board_num);
+					continue;
+				}
+				if (!request_mem_region
+				    ((unsigned long)l_fb_info->pIOBase, PM3_REGS_SIZE,
+				     "pm3fb I/O regs")) {
+					printk
+					    (KERN_ERR "pm3fb: Error: couldn't request IObase memory, board #%ld\n",
+					     l_fb_info->board_num);
+					continue;
+				}
+#endif /* KERNEL_2_4 or KERNEL_2_5 */
+				if (forcesize[l_fb_info->board_num])
+					l_fb_info->fb_size = forcesize[l_fb_info->board_num];
+				
+				l_fb_info->fb_size =
+				    pm3fb_size_memory(l_fb_info);
+
+				if (l_fb_info->fb_size) {
+					(void) pci_enable_device(l_fb_info->dev);
+					pm3fb_common_init(l_fb_info);
+				} else
+					printk(KERN_ERR "pm3fb: memory problem, not enabling board #%ld\n", l_fb_info->board_num);
+				
+#ifdef SUPPORT_FB_OF
+			}
+#endif /* SUPPORT_FB_OF */
+		}
+	}
+}
+
+static int pm3fb_pan_display(const struct fb_var_screeninfo *var,
+			     struct fb_info_gen *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+
+	DTRACE;
+
+	if (!current_par_valid[l_fb_info->board_num])
+		return -EINVAL;
+
+	l_fb_info->current_par->base =	/* in 128 bits chunk - i.e. AFTER Shiftbpp */
+	    pm3fb_Shiftbpp(l_fb_info,
+			   l_fb_info->current_par->depth,
+			   (var->yoffset * l_fb_info->current_par->width) +
+			   var->xoffset);
+	PM3_SLOW_WRITE_REG(PM3ScreenBase, l_fb_info->current_par->base);
+	return 0;
+}
+
+static int pm3fb_ioctl(struct inode *inode, struct file *file,
+                       u_int cmd, u_long arg, int con,
+		       struct fb_info *info)
+{
+	struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
+	u32 cm, i;
+#ifdef PM3FB_MASTER_DEBUG
+	char cc[3];
+#endif /* PM3FB_MASTER_DEBUG */
+
+	switch(cmd)
+	{
+#ifdef PM3FB_MASTER_DEBUG
+	case PM3FBIO_CLEARMEMORY:
+		if (copy_from_user(&cm, (void *)arg, sizeof(u32)))
+			return(-EFAULT);
+		pm3fb_clear_memory(l_fb_info, cm);
+		return(0);
+		break;
+
+	case PM3FBIO_CLEARCMAP:
+		if (copy_from_user(cc, (void*)arg, 3 * sizeof(char)))
+			return(-EFAULT);
+		pm3fb_clear_colormap(l_fb_info, cc[0], cc[1], cc[2]);
+		return(0);
+		break;
+#endif /* PM3FB_MASTER_DEBUG */
+
+	case PM3FBIO_RESETCHIP:
+		cm = 1;
+		PM3_SLOW_WRITE_REG(PM3ResetStatus, 1);
+		for (i = 0 ; (i < 10000) && cm ; i++)
+		{
+			PM3_DELAY(10);
+			cm = PM3_READ_REG(PM3ResetStatus);
+		}
+		if (cm)
+		{
+			printk(KERN_ERR "pm3fb: chip reset failed with status 0x%x\n", cm);
+			return(-EIO);
+		}
+		/* first thing first, reload memory timings */
+		pm3fb_write_memory_timings(l_fb_info);
+#ifdef PM3FB_USE_ACCEL
+		pm3fb_init_engine(l_fb_info);
+#endif /* PM3FB_USE_ACCEL */
+		pm3fb_write_mode(l_fb_info);
+		return(0);
+		break;
+
+	default:
+		DPRINTK(2, "unknown ioctl: %d (%x)\n", cmd, cmd);
+		return(-EINVAL);
+	}
+}
+
+/* ****************************************** */
+/* ***** standard FB API init functions ***** */
+/* ****************************************** */
+
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+int __init pm3fb_setup(char *options)
+#endif
+#ifdef KERNEL_2_2
+__initfunc(void pm3fb_setup(char *options, int *ints))
+#endif
+{
+	long opsi = strlen(options);
+
+	DTRACE;
+
+	memcpy(g_options, options,
+	       ((opsi + 1) >
+		PM3_OPTIONS_SIZE) ? PM3_OPTIONS_SIZE : (opsi + 1));
+	g_options[PM3_OPTIONS_SIZE - 1] = 0;
+
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+	return (0);
+#endif
+}
+
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+int __init pm3fb_init(void)
+#endif
+#ifdef KERNEL_2_2
+__initfunc(void pm3fb_init(void))
+#endif
+{
+	DTRACE;
+
+	DPRINTK(2, "This is pm3fb.c, CVS version: $Header: /cvsroot/linux/drivers/video/pm3fb.c,v 1.1 2002/02/25 19:11:06 marcelo Exp $");
+
+	pm3fb_real_setup(g_options);
+
+	pm3fb_detect();
+
+	if (!fb_info[0].dev) {	/* not even one board ??? */
+		DPRINTK(1, "No PCI Permedia3 board detected\n");
+	}
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+	return (0);
+#endif
+}
+
+#ifdef SUPPORT_FB_OF		/* linux-2.2.x only */
+__initfunc(void pm3fb_of_init(struct device_node *dp))
+{
+	struct pm3fb_info *l_fb_info = NULL;
+	unsigned long i;
+	long bn = -1;
+	struct device_node *dn;
+
+	DTRACE;
+
+	DPRINTK(2, "OpenFirmware board : %s\n", dp->full_name);
+
+	for (i = 0; i < dp->n_addrs; i++) {
+		DPRINTK(2, "MemRange : 0x%08x - 0x%x\n",
+			dp->addrs[i].address, dp->addrs[i].size);
+	}
+
+	for (i = 0; i < PM3_MAX_BOARD; i++) {	/* find which PCI board is the OF device */
+		if (fb_info[i].dev) {
+			dn = find_pci_device_OFnode(fb_info[i].dev->bus->
+						    number,
+						    fb_info[i].dev->devfn);
+			if (dn == dp) {
+				if (bn == -1)
+					bn = i;
+				else {
+					DPRINTK(1,
+						"Error: Multiple PCI device for a single OpenFirmware node\n");
+				}
+			}
+		}
+	}
+
+	if (bn == -1) {
+		DPRINTK(1, "Warning: non-PCI Permedia3 found\n");
+		i = 0;
+		while (fb_info[i].dev && (i < PM3_MAX_BOARD))
+			i++;
+		if (i < PM3_MAX_BOARD)
+			bn = i;
+		else {
+			printk
+			    (KERN_ERR "pm3fb: Error: Couldn't find room for OpenFirmware device");
+			return;
+		}
+	}
+
+	l_fb_info = &(fb_info[bn]);
+
+	l_fb_info->dn = dp;
+
+	l_fb_info->pIOBase = (unsigned char *) dp->addrs[3].address;
+#ifdef __BIG_ENDIAN
+	l_fb_info->pIOBase += PM3_REGS_SIZE;
+#endif
+	l_fb_info->vIOBase = (unsigned char *) -1;
+	l_fb_info->p_fb = (unsigned char *) dp->addrs[1].address;
+	l_fb_info->v_fb = (unsigned char *) -1;
+
+	l_fb_info->fb_size = pm3fb_size_memory(l_fb_info);	/* (unsigned long)dp->addrs[1].size; *//* OF is a liar ! it claims 256 Mb */
+
+	DPRINTK(2,
+		"OpenFirmware board (#%ld) : IOBase 0x%08lx, p_fb 0x%08lx, fb_size %d KB\n",
+		bn, (unsigned long) l_fb_info->pIOBase,
+		(unsigned long) l_fb_info->p_fb, l_fb_info->fb_size >> 10);
+
+	l_fb_info->use_current = 1;	/* will use current mode by default */
+
+	pm3fb_common_init(l_fb_info);
+}
+#endif /* SUPPORT_FB_OF */
+
+/* ************************* */
+/* **** Module support ***** */
+/* ************************* */
+
+#ifdef MODULE
+MODULE_AUTHOR("Romain Dolbeau");
+MODULE_DESCRIPTION("Permedia3 framebuffer device driver");
+static char *mode[PM3_MAX_BOARD];
+MODULE_PARM(mode,PM3_MAX_BOARD_MODULE_ARRAY_STRING);
+MODULE_PARM_DESC(mode,"video mode");
+MODULE_PARM(disable,PM3_MAX_BOARD_MODULE_ARRAY_SHORT);
+MODULE_PARM_DESC(disable,"disable board");
+static short off[PM3_MAX_BOARD];
+MODULE_PARM(off,PM3_MAX_BOARD_MODULE_ARRAY_SHORT);
+MODULE_PARM_DESC(off,"disable board");
+static char *pciid[PM3_MAX_BOARD];
+MODULE_PARM(pciid,PM3_MAX_BOARD_MODULE_ARRAY_STRING);
+MODULE_PARM_DESC(pciid,"board PCI Id");
+MODULE_PARM(noaccel,PM3_MAX_BOARD_MODULE_ARRAY_SHORT);
+MODULE_PARM_DESC(noaccel,"disable accel");
+static char *font[PM3_MAX_BOARD];
+MODULE_PARM(font,PM3_MAX_BOARD_MODULE_ARRAY_STRING);
+MODULE_PARM_DESC(font,"choose font");
+MODULE_PARM(depth,PM3_MAX_BOARD_MODULE_ARRAY_SHORT);
+MODULE_PARM_DESC(depth,"boot-time depth");
+MODULE_PARM(printtimings, "h");
+MODULE_PARM_DESC(printtimings, "print the memory timings of the card(s)");
+MODULE_PARM(forcesize, PM3_MAX_BOARD_MODULE_ARRAY_SHORT);
+MODULE_PARM_DESC(forcesize, "force specified memory size");
+/*
+MODULE_SUPPORTED_DEVICE("Permedia3 PCI boards")
+MODULE_GENERIC_TABLE(gtype,name)
+MODULE_DEVICE_TABLE(type,name)
+*/
+
+void pm3fb_build_options(void)
+{
+	int i;
+	char ts[128];
+
+	strcpy(g_options, "pm3fb");
+	for (i = 0; i < PM3_MAX_BOARD ; i++)
+	{
+		if (mode[i])
+		{
+			sprintf(ts, ",mode:%d:%s", i, mode[i]);
+			strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
+		}
+		if (disable[i] || off[i])
+		{
+			sprintf(ts, ",disable:%d:", i);
+			strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
+		}
+		if (pciid[i])
+		{
+			sprintf(ts, ",pciid:%d:%s", i, pciid[i]);
+			strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
+		}
+		if (noaccel[i])
+		{
+			sprintf(ts, ",noaccel:%d:", i);
+			strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
+		}
+		if (font[i])
+		{
+			sprintf(ts, ",font:%d:%s", i, font[i]);
+			strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
+		}
+		if (depth[i])
+		{
+			sprintf(ts, ",depth:%d:%d", i, depth[i]);
+			strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
+		}
+	}
+	g_options[PM3_OPTIONS_SIZE - 1] = '\0';
+	DPRINTK(1, "pm3fb use options: %s\n", g_options);
+}
+
+int init_module(void)
+{
+	DTRACE;
+
+	pm3fb_build_options();
+
+	pm3fb_init();
+
+	return (0);
+}
+
+void cleanup_module(void)
+{
+	DTRACE;
+	{
+		unsigned long i;
+		struct pm3fb_info *l_fb_info;
+		for (i = 0; i < PM3_MAX_BOARD; i++) {
+			l_fb_info = &(fb_info[i]);
+			if ((l_fb_info->dev != NULL)
+			    && (!(disable[l_fb_info->board_num]))) {
+				if (l_fb_info->vIOBase !=
+				    (unsigned char *) -1) {
+					pm3fb_unmapIO(l_fb_info);
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5)
+					release_mem_region(l_fb_info->p_fb,
+							   l_fb_info->
+							   fb_size);
+					release_mem_region(l_fb_info->
+							   pIOBase,
+							   PM3_REGS_SIZE);
+#endif /* KERNEL_2_4 or KERNEL_2_5 */
+				}
+				unregister_framebuffer(&l_fb_info->gen.
+						       info);
+			}
+		}
+	}
+	return;
+}
+#endif /* MODULE */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/pm3fb.h linux/drivers/video/pm3fb.h
--- tmp/linux/drivers/video/pm3fb.h	Thu Jan  1 00:00:00 1970
+++ linux/drivers/video/pm3fb.h	Mon Feb 25 19:11:06 2002
@@ -0,0 +1,1286 @@
+/*
+ *  linux/drivers/video/pm3fb.h -- 3DLabs Permedia3 frame buffer device
+ *  
+ *  Copyright (C) 2001 Romain Dolbeau <dolbeau@irisa.fr>
+ *  Copyright (C) 2001 Sven Luther, <luther@dpt-info.u-strasbg.fr>
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License. See the file COPYING in the main directory of this archive for
+ *  more details.
+ *
+ *  $Header: /cvsroot/linux/drivers/video/pm3fb.h,v 1.1 2002/02/25 19:11:06 marcelo Exp $
+ *
+ */
+
+#ifndef PM3FB_H
+#define PM3FB_H
+
+/**********************************************
+*  GLINT Permedia3 Control Status registers   *
+***********************************************/
+/* Control Status Registers */
+#define PM3ResetStatus						0x0000
+#define PM3IntEnable						0x0008
+#define PM3IntFlags						0x0010
+#define PM3InFIFOSpace						0x0018
+#define PM3OutFIFOWords						0x0020
+#define PM3DMAAddress						0x0028
+#define PM3DMACount						0x0030
+#define PM3ErrorFlags						0x0038
+#define PM3VClkCtl						0x0040
+#define PM3TestRegister						0x0048
+#define PM3Aperture0						0x0050
+#define PM3Aperture1						0x0058
+#define PM3DMAControl						0x0060
+#define PM3FIFODis						0x0068
+#define PM3ChipConfig						0x0070
+#define PM3AGPControl						0x0078
+
+#define PM3GPOutDMAAddress					0x0080
+#define PM3PCIFeedbackCount					0x0088
+#define PM3PCIAbortStatus					0x0090
+#define PM3PCIAbortAddress					0x0098
+
+#define PM3PCIPLLStatus						0x00f0
+
+#define PM3HostTextureAddress					0x0100
+#define PM3TextureDownloadControl				0x0108
+#define PM3TextureOperation					0x0110
+#define PM3LogicalTexturePage					0x0118
+#define PM3TexDMAAddress					0x0120
+#define PM3TexFIFOSpace						0x0128
+
+/**********************************************
+*  GLINT Permedia3 Region 0 Bypass Controls   *
+***********************************************/
+#define PM3ByAperture1Mode					0x0300
+	#define PM3ByApertureMode_BYTESWAP_ABCD			(0<<0)
+	#define PM3ByApertureMode_BYTESWAP_BADC			(1<<0)
+	#define PM3ByApertureMode_BYTESWAP_CDAB			(2<<0)
+	#define PM3ByApertureMode_BYTESWAP_DCBA			(3<<0)
+	#define PM3ByApertureMode_PATCH_DISABLE			(0<<2)
+	#define PM3ByApertureMode_PATCH_ENABLE			(1<<2)
+	#define PM3ByApertureMode_FORMAT_RAW			(0<<3)
+	#define PM3ByApertureMode_FORMAT_YUYV			(1<<3)
+	#define PM3ByApertureMode_FORMAT_UYVY			(2<<3)
+	#define PM3ByApertureMode_PIXELSIZE_8BIT		(0<<5)
+	#define PM3ByApertureMode_PIXELSIZE_16BIT		(1<<5)
+	#define PM3ByApertureMode_PIXELSIZE_32BIT		(2<<5)
+                #define PM3ByApertureMode_PIXELSIZE_MASK        (3<<5)
+	#define PM3ByApertureMode_EFFECTIVE_STRIDE_1024		(0<<7)
+	#define PM3ByApertureMode_EFFECTIVE_STRIDE_2048		(1<<7)
+	#define PM3ByApertureMode_EFFECTIVE_STRIDE_4096		(2<<7)
+	#define PM3ByApertureMode_EFFECTIVE_STRIDE_8192		(3<<7)
+	#define PM3ByApertureMode_PATCH_OFFSET_X(off)	(((off)&7f)<<9)
+	#define PM3ByApertureMode_PATCH_OFFSET_Y(off)	(((off)&7f)<<16)
+	#define PM3ByApertureMode_FRAMEBUFFER			(0<<21)
+	#define PM3ByApertureMode_LOCALBUFFER			(1<<21)
+	#define PM3ByApertureMode_DOUBLE_WRITE_OFF		(0<<22)
+	#define PM3ByApertureMode_DOUBLE_WRITE_1MB		(1<<22)
+	#define PM3ByApertureMode_DOUBLE_WRITE_2MB		(2<<22)
+	#define PM3ByApertureMode_DOUBLE_WRITE_4MB		(3<<22)
+	#define PM3ByApertureMode_DOUBLE_WRITE_8MB		(4<<22)
+	#define PM3ByApertureMode_DOUBLE_WRITE_16MB		(5<<22)
+	#define PM3ByApertureMode_DOUBLE_WRITE_32MB		(6<<22)
+
+#define PM3ByAperture2Mode					0x0328
+	
+/**********************************************
+*  GLINT Permedia3 Memory Control (0x1000)    *
+***********************************************/
+#define PM3MemCounter						0x1000
+#define PM3MemBypassWriteMask					0x1008
+#define PM3MemScratch						0x1010
+#define PM3LocalMemCaps						0x1018
+        #define PM3LocalMemCaps_NoWriteMask                     (1 << 28)
+#define PM3LocalMemTimings					0x1020
+#define PM3LocalMemControl					0x1028
+#define PM3LocalMemRefresh					0x1030
+#define PM3LocalMemPowerDown					0x1038
+#define PM3RemoteMemControl					0x1100
+
+/**********************************************
+*  GLINT Permedia3 Video Control (0x3000)     *
+***********************************************/
+
+#define PM3ScreenBase						0x3000
+#define PM3ScreenStride						0x3008
+#define PM3HTotal						0x3010
+#define PM3HgEnd						0x3018
+#define PM3HbEnd						0x3020
+#define PM3HsStart						0x3028
+#define PM3HsEnd						0x3030
+#define PM3VTotal						0x3038
+#define PM3VbEnd						0x3040
+#define PM3VsStart						0x3048
+#define PM3VsEnd						0x3050
+#define PM3VideoControl						0x3058
+	#define PM3VideoControl_DISABLE				(0<<0)
+	#define PM3VideoControl_ENABLE				(1<<0)
+	#define PM3VideoControl_BLANK_ACTIVE_HIGH		(0<<1)
+	#define PM3VideoControl_BLANK_ACTIVE_LOW		(1<<1)
+	#define PM3VideoControl_LINE_DOUBLE_OFF			(0<<2)
+	#define PM3VideoControl_LINE_DOUBLE_ON			(1<<2)
+	#define PM3VideoControl_HSYNC_FORCE_HIGH		(0<<3)
+	#define PM3VideoControl_HSYNC_ACTIVE_HIGH		(1<<3)
+	#define PM3VideoControl_HSYNC_FORCE_LOW			(2<<3)
+	#define PM3VideoControl_HSYNC_ACTIVE_LOW		(3<<3)
+        #define PM3VideoControl_HSYNC_MASK          (3<<3)
+	#define PM3VideoControl_VSYNC_FORCE_HIGH		(0<<5)
+	#define PM3VideoControl_VSYNC_ACTIVE_HIGH		(1<<5)
+	#define PM3VideoControl_VSYNC_FORCE_LOW			(2<<5)
+	#define PM3VideoControl_VSYNC_ACTIVE_LOW		(3<<5)
+        #define PM3VideoControl_VSYNC_MASK          (3<<5)
+	#define PM3VideoControl_BYTE_DOUBLE_OFF			(0<<7)
+	#define PM3VideoControl_BYTE_DOUBLE_ON			(1<<7)
+	#define PM3VideoControl_BUFFER_SWAP_SYNCON_FRAMEBLANK	(0<<9)
+	#define PM3VideoControl_BUFFER_SWAP_FREE_RUNNING	(1<<9)
+	#define PM3VideoControl_BUFFER_SWAP_LIMITETO_FRAMERATE	(2<<9)
+	#define PM3VideoControl_STEREO_DISABLE			(0<<11)
+	#define PM3VideoControl_STEREO_ENABLE			(1<<11)
+	#define PM3VideoControl_RIGHT_EYE_ACTIVE_HIGH		(0<<12)
+	#define PM3VideoControl_RIGHT_EYE_ACTIVE_LOW		(1<<12)
+	#define PM3VideoControl_VIDEO_EXT_LOW			(0<<14)
+	#define PM3VideoControl_VIDEO_EXT_HIGH			(1<<14)
+	#define PM3VideoControl_SYNC_MODE_INDEPENDENT		(0<<16)
+	#define PM3VideoControl_SYNC_MODE_SYNCTO_VSA		(1<<16)
+	#define PM3VideoControl_SYNC_MODE_SYNCTO_VSB		(2<<16)
+	#define PM3VideoControl_PATCH_DISABLE			(0<<18)
+	#define PM3VideoControl_PATCH_ENABLE			(1<<18)
+	#define PM3VideoControl_PIXELSIZE_8BIT			(0<<19)
+	#define PM3VideoControl_PIXELSIZE_16BIT			(1<<19)
+	#define PM3VideoControl_PIXELSIZE_32BIT			(2<<19)
+	#define PM3VideoControl_DISPLAY_DISABLE			(0<<21)
+	#define PM3VideoControl_DISPLAY_ENABLE			(1<<21)
+	#define PM3VideoControl_PATCH_OFFSET_X(off)	(((off)&0x3f)<<22)
+	#define PM3VideoControl_PATCH_OFFSET_Y(off)	(((off)&0x3f)<<28)
+#define PM3InterruptLine					0x3060
+#define PM3DisplayData						0x3068
+#define PM3VerticalLineCount					0x3070
+#define PM3FifoControl						0x3078
+#define PM3ScreenBaseRight					0x3080
+#define PM3MiscControl						0x3088
+
+#define PM3VideoOverlayUpdate					0x3100
+        #define PM3VideoOverlayUpdate_DISABLE                   (0<<0)
+        #define PM3VideoOverlayUpdate_ENABLE                    (1<<0)
+#define PM3VideoOverlayMode					0x3108
+	#define PM3VideoOverlayMode_DISABLE			(0<<0)
+	#define PM3VideoOverlayMode_ENABLE			(1<<0)
+        #define PM3VideoOverlayMode_BUFFERSYNC_MANUAL           (0<<1)
+        #define PM3VideoOverlayMode_BUFFERSYNC_VIDEOSTREAMA     (1<<1)
+        #define PM3VideoOverlayMode_BUFFERSYNC_VIDEOSTREAMB     (2<<1)
+        #define PM3VideoOverlayMode_FIELDPOLARITY_NORMAL        (0<<4)
+        #define PM3VideoOverlayMode_FIELDPOLARITY_INVERT        (1<<4)
+        #define PM3VideoOverlayMode_PIXELSIZE_8BIT              (0<<5)
+        #define PM3VideoOverlayMode_PIXELSIZE_16BIT             (1<<5)
+        #define PM3VideoOverlayMode_PIXELSIZE_32BIT             (2<<5)
+        #define PM3VideoOverlayMode_COLORFORMAT_RGB8888 ((0<<7)|(1<<12)|(2<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_RGB4444 ((1<<7)|(1<<12)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_RGB5551 ((2<<7)|(1<<12)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_RGB565  ((3<<7)|(1<<12)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_RGB332  ((4<<7)|(1<<12)|(0<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_BGR8888 ((0<<7)|(2<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_BGR4444 ((1<<7)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_BGR5551 ((2<<7)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_BGR565  ((3<<7)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_BGR332  ((4<<7)|(0<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_CI8     ((5<<7)|(1<<12)|(0<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_VUY444  ((2<<10)|(1<<12)|(2<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_YUV444  ((2<<10)|(2<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_VUY422  ((1<<10)|(1<<12)|(1<<5))
+        #define PM3VideoOverlayMode_COLORFORMAT_YUV422  ((1<<10)|(1<<5))
+        #define PM3VideoOverlayMode_COLORORDER_BGR              (0<<12)
+        #define PM3VideoOverlayMode_COLORORDER_RGB              (1<<12)
+        #define PM3VideoOverlayMode_LINEARCOLOREXT_OFF          (0<<13)
+        #define PM3VideoOverlayMode_LINEARCOLOREXT_ON           (1<<13)
+        #define PM3VideoOverlayMode_FILTER_MASK                 (3<<14)
+        #define PM3VideoOverlayMode_FILTER_OFF                  (0<<14)
+        #define PM3VideoOverlayMode_FILTER_FULL                 (1<<14)
+        #define PM3VideoOverlayMode_FILTER_PARTIAL              (2<<14)
+        #define PM3VideoOverlayMode_DEINTERLACE_OFF             (0<<16)
+        #define PM3VideoOverlayMode_DEINTERLACE_BOB             (1<<16)
+        #define PM3VideoOverlayMode_PATCHMODE_OFF               (0<<18)
+        #define PM3VideoOverlayMode_PATCHMODE_ON                (1<<18)
+        #define PM3VideoOverlayMode_FLIP_VIDEO                  (0<<20)
+        #define PM3VideoOverlayMode_FLIP_VIDEOSTREAMA           (1<<20)
+        #define PM3VideoOverlayMode_FLIP_VIDEOSTREAMB           (2<<20)
+        #define PM3VideoOverlayMode_MIRROR_MASK                 (3<<23)
+        #define PM3VideoOverlayMode_MIRRORX_OFF                 (0<<23)
+        #define PM3VideoOverlayMode_MIRRORX_ON                  (1<<23)
+        #define PM3VideoOverlayMode_MIRRORY_OFF                 (0<<24)
+        #define PM3VideoOverlayMode_MIRRORY_ON                  (1<<24)
+#define PM3VideoOverlayFifoControl				0x3110
+#define PM3VideoOverlayIndex					0x3118
+#define PM3VideoOverlayBase0					0x3120
+#define PM3VideoOverlayBase1					0x3128
+#define PM3VideoOverlayBase2					0x3130
+#define PM3VideoOverlayStride					0x3138
+        #define PM3VideoOverlayStride_STRIDE(s)         (((s)&0xfff)<<0)
+#define PM3VideoOverlayWidth                                    0x3140
+        #define PM3VideoOverlayWidth_WIDTH(w)           (((w)&0xfff)<<0)
+#define PM3VideoOverlayHeight                                   0x3148
+        #define PM3VideoOverlayHeight_HEIGHT(h)         (((h)&0xfff)<<0)
+#define PM3VideoOverlayOrigin                                   0x3150
+        #define PM3VideoOverlayOrigin_XORIGIN(x)        (((x)&0xfff)<<0)
+        #define PM3VideoOverlayOrigin_YORIGIN(y)        (((y)&0xfff)<<16)
+#define PM3VideoOverlayShrinkXDelta                             0x3158
+        #define PM3VideoOverlayShrinkXDelta_NONE                (1<<16)
+        #define PM3VideoOverlayShrinkXDelta_DELTA(s,d)          \
+                ((((s)<<16)/(d))&0x0ffffff0)
+#define PM3VideoOverlayZoomXDelta                               0x3160
+        #define PM3VideoOverlayZoomXDelta_NONE                  (1<<16)
+        #define PM3VideoOverlayZoomXDelta_DELTA(s,d)            \
+                ((((s)<<16)/(d))&0x0001fff0)
+#define PM3VideoOverlayYDelta                                   0x3168
+        #define PM3VideoOverlayYDelta_NONE                      (1<<16)
+        #define PM3VideoOverlayYDelta_DELTA(s,d)                        \
+                ((((s)<<16)/(d))&0x0ffffff0)
+#define PM3VideoOverlayFieldOffset				0x3170
+#define PM3VideoOverlayStatus					0x3178
+
+/**********************************************
+*  GLINT Permedia3 RAMDAC Registers (0x4000)  *
+***********************************************/
+/* Direct Registers */
+#define PM3RD_PaletteWriteAddress				0x4000
+#define PM3RD_PaletteData					0x4008
+#define PM3RD_PixelMask						0x4010
+#define PM3RD_PaletteReadAddress				0x4018
+
+#define PM3RD_IndexLow						0x4020
+#define PM3RD_IndexHigh						0x4028
+#define PM3RD_IndexedData					0x4030
+#define PM3RD_IndexControl					0x4038
+	#define PM3RD_IndexControl_AUTOINCREMENT_ENABLE		(1<<0)
+	#define PM3RD_IndexControl_AUTOINCREMENT_DISABLE	(0<<0)
+
+/* Indirect Registers */
+#define PM3RD_MiscControl					0x000
+	#define PM3RD_MiscControl_HIGHCOLOR_RES_DISABLE		(0<<0)
+	#define PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE		(1<<0)
+	#define PM3RD_MiscControl_PIXELDOUBLE_DISABLE		(0<<1)
+	#define PM3RD_MiscControl_PIXELDOUBLE_ENABLE		(1<<1)
+	#define PM3RD_MiscControl_LASTREAD_ADDR_DISABLE		(0<<2)
+	#define PM3RD_MiscControl_LASTREAD_ADDR_ENABLE		(1<<2)
+	#define PM3RD_MiscControl_DIRECTCOLOR_DISABLE		(0<<3)
+	#define PM3RD_MiscControl_DIRECTCOLOR_ENABLE		(1<<3)
+	#define PM3RD_MiscControl_OVERLAY_DISABLE		(0<<4)
+	#define PM3RD_MiscControl_OVERLAY_ENABLE		(1<<4)
+	#define PM3RD_MiscControl_PIXELDOUBLE_BUFFER_DISABLE	(0<<5)
+	#define PM3RD_MiscControl_PIXELDOUBLE_BUFFER_ENABLE	(1<<5)
+	#define PM3RD_MiscControl_VSB_OUTPUT_DISABLE		(0<<6)
+	#define PM3RD_MiscControl_VSB_OUTPUT_ENABLE		(1<<6)
+	#define PM3RD_MiscControl_STEREODOUBLE_BUFFER_DISABLE	(0<<7)
+	#define PM3RD_MiscControl_STEREODOUBLE_BUFFER_ENABLE	(1<<7)
+#define PM3RD_SyncControl					0x001
+	#define PM3RD_SyncControl_HSYNC_ACTIVE_LOW		(0<<0)
+	#define PM3RD_SyncControl_HSYNC_ACTIVE_HIGH		(1<<0)
+	#define PM3RD_SyncControl_HSYNC_FORCE_ACTIVE		(3<<0)
+	#define PM3RD_SyncControl_HSYNC_FORCE_INACTIVE		(4<<0)
+	#define PM3RD_SyncControl_HSYNC_TRI_STATE		(2<<0)
+	#define PM3RD_SyncControl_VSYNC_ACTIVE_LOW		(0<<3)
+	#define PM3RD_SyncControl_VSYNC_ACTIVE_HIGH		(1<<3)
+	#define PM3RD_SyncControl_VSYNC_TRI_STATE		(2<<3)
+	#define PM3RD_SyncControl_VSYNC_FORCE_ACTIVE		(3<<3)
+	#define PM3RD_SyncControl_VSYNC_FORCE_INACTIVE		(4<<3)
+	#define PM3RD_SyncControl_HSYNC_OVERRIDE_SETBY_HSYNC	(0<<6)
+	#define PM3RD_SyncControl_HSYNC_OVERRIDE_FORCE_HIGH	(1<<6)
+	#define PM3RD_SyncControl_VSYNC_OVERRIDE_SETBY_VSYNC	(0<<7)
+	#define PM3RD_SyncControl_VSYNC_OVERRIDE_FORCE_HIGH	(1<<7)
+#define PM3RD_DACControl					0x002
+	#define PM3RD_DACControl_DAC_POWER_ON			(0<<0)
+	#define PM3RD_DACControl_DAC_POWER_OFF			(1<<0)
+	#define PM3RD_DACControl_SYNC_ON_GREEN_DISABLE		(0<<3)
+	#define PM3RD_DACControl_SYNC_ON_GREEN_ENABLE		(1<<3)
+	#define PM3RD_DACControl_BLANK_RED_DAC_DISABLE		(0<<4)
+	#define PM3RD_DACControl_BLANK_RED_DAC_ENABLE		(1<<4)
+	#define PM3RD_DACControl_BLANK_GREEN_DAC_DISABLE	(0<<5)
+	#define PM3RD_DACControl_BLANK_GREEN_DAC_ENABLE		(1<<5)
+	#define PM3RD_DACControl_BLANK_BLUE_DAC_DISABLE		(0<<6)
+	#define PM3RD_DACControl_BLANK_BLUE_DAC_ENABLE		(1<<6)
+	#define PM3RD_DACControl_BLANK_PEDESTAL_DISABLE		(0<<7)
+	#define PM3RD_DACControl_BLANK_PEDESTAL_ENABLE		(1<<7)
+#define PM3RD_PixelSize						0x003
+	#define PM3RD_PixelSize_24_BIT_PIXELS			(4<<0)
+	#define PM3RD_PixelSize_32_BIT_PIXELS			(2<<0)
+	#define PM3RD_PixelSize_16_BIT_PIXELS			(1<<0)
+	#define PM3RD_PixelSize_8_BIT_PIXELS			(0<<0)
+#define PM3RD_ColorFormat					0x004
+	#define PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE	(1<<6)
+	#define PM3RD_ColorFormat_LINEAR_COLOR_EXT_DISABLE	(0<<6)
+	#define PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW		(1<<5)
+	#define PM3RD_ColorFormat_COLOR_ORDER_RED_LOW		(0<<5)
+	#define PM3RD_ColorFormat_COLOR_FORMAT_MASK		(0x1f<<0)
+	#define PM3RD_ColorFormat_8888_COLOR			(0<<0)
+	#define PM3RD_ColorFormat_5551_FRONT_COLOR		(1<<0)
+	#define PM3RD_ColorFormat_4444_COLOR			(2<<0)
+	#define PM3RD_ColorFormat_332_FRONT_COLOR		(5<<0)
+	#define PM3RD_ColorFormat_332_BACK_COLOR		(6<<0)
+	#define PM3RD_ColorFormat_2321_FRONT_COLOR		(9<<0)
+	#define PM3RD_ColorFormat_2321_BACK_COLOR		(10<<0)
+	#define PM3RD_ColorFormat_232_FRONTOFF_COLOR		(11<<0)
+	#define PM3RD_ColorFormat_232_BACKOFF_COLOR		(12<<0)
+	#define PM3RD_ColorFormat_5551_BACK_COLOR		(13<<0)
+	#define PM3RD_ColorFormat_CI8_COLOR			(14<<0)
+	#define PM3RD_ColorFormat_565_FRONT_COLOR		(16<<0)
+	#define PM3RD_ColorFormat_565_BACK_COLOR		(17<<0)
+#define PM3RD_CursorMode					0x005
+	#define PM3RD_CursorMode_CURSOR_DISABLE			(0<<0)
+	#define PM3RD_CursorMode_CURSOR_ENABLE			(1<<0)
+	#define PM3RD_CursorMode_FORMAT_64x64_2BPE_P0123	(0<<2)
+	#define PM3RD_CursorMode_FORMAT_32x32_2BPE_P0		(1<<2)
+	#define PM3RD_CursorMode_FORMAT_32x32_2BPE_P1		(2<<2)
+	#define PM3RD_CursorMode_FORMAT_32x32_2BPE_P2		(3<<2)
+	#define PM3RD_CursorMode_FORMAT_32x32_2BPE_P3		(4<<2)
+	#define PM3RD_CursorMode_FORMAT_32x32_4BPE_P01		(5<<2)
+	#define PM3RD_CursorMode_FORMAT_32x32_4BPE_P23		(6<<2)
+	#define PM3RD_CursorMode_TYPE_MS			(0<<4)
+	#define PM3RD_CursorMode_TYPE_X				(1<<4)
+	#define PM3RD_CursorMode_REVERSE_PIXEL_ORDER_DISABLE	(0<<6)
+	#define PM3RD_CursorMode_REVERSE_PIXEL_ORDER_ENABLE	(1<<6)
+	#define PM3RD_CursorMode_REVERSE_PIXEL_ORDER_3_COLOR	(2<<6)
+	#define PM3RD_CursorMode_REVERSE_PIXEL_ORDER_15_COLOR	(3<<6)
+#define PM3RD_CursorControl					0x006
+	#define PM3RD_CursorControl_DOUBLE_X_DISABLED		(0<<0)
+	#define PM3RD_CursorControl_DOUBLE_X_ENABLED		(1<<0)
+	#define PM3RD_CursorControl_DOUBLE_Y_DISABLED		(0<<1)
+	#define PM3RD_CursorControl_DOUBLE_Y_ENABLED		(1<<1)
+	#define PM3RD_CursorControl_READBACK_POS_DISABLED	(0<<2)
+	#define PM3RD_CursorControl_READBACK_POS_ENABLED	(1<<2)
+
+#define PM3RD_CursorXLow					0x007
+#define PM3RD_CursorXHigh					0x008
+#define PM3RD_CursorYLow					0x009
+#define PM3RD_CursorYHigh					0x00a
+#define PM3RD_CursorHotSpotX					0x00b
+#define PM3RD_CursorHotSpotY					0x00c
+#define PM3RD_OverlayKey					0x00d
+#define PM3RD_Pan						0x00e
+	#define PM3RD_Pan_DISABLE				(0<<0)
+	#define PM3RD_Pan_ENABLE				(1<<0)
+	#define PM3RD_Pan_GATE_DISABLE				(0<<1)
+	#define PM3RD_Pan_GATE_ENABLE				(1<<1)
+#define PM3RD_Sense						0x00f
+
+#define PM3RD_CheckControl					0x018
+	#define PM3RD_CheckControl_PIXEL_DISABLED		(0<<0)
+	#define PM3RD_CheckControl_PIXEL_ENABLED		(1<<0)
+	#define PM3RD_CheckControl_LUT_DISABLED			(0<<1)
+	#define PM3RD_CheckControl_LUT_ENABLED			(1<<1)
+#define PM3RD_CheckPixelRed					0x019
+#define PM3RD_CheckPixelGreen					0x01a
+#define PM3RD_CheckPixelBlue					0x01b
+#define PM3RD_CheckLUTRed					0x01c
+#define PM3RD_CheckLUTGreen					0x01d
+#define PM3RD_CheckLUTBlue					0x01e
+#define PM3RD_Scratch						0x01f
+
+#define PM3RD_VideoOverlayControl				0x020
+        #define PM3RD_VideoOverlayControl_DISABLE               (0<<0)
+        #define PM3RD_VideoOverlayControl_ENABLE                (1<<0)
+        #define PM3RD_VideoOverlayControl_MODE_MASK             (3<<1)
+        #define PM3RD_VideoOverlayControl_MODE_MAINKEY          (0<<1)
+        #define PM3RD_VideoOverlayControl_MODE_OVERLAYKEY       (1<<1)
+        #define PM3RD_VideoOverlayControl_MODE_ALWAYS           (2<<1)
+        #define PM3RD_VideoOverlayControl_MODE_BLEND            (3<<1)
+        #define PM3RD_VideoOverlayControl_DIRECTCOLOR_DISABLED  (0<<3)
+        #define PM3RD_VideoOverlayControl_DIRECTCOLOR_ENABLED   (1<<3)
+        #define PM3RD_VideoOverlayControl_BLENDSRC_MAIN         (0<<4)
+        #define PM3RD_VideoOverlayControl_BLENDSRC_REGISTER     (1<<4)
+        #define PM3RD_VideoOverlayControl_KEY_COLOR             (0<<5)
+        #define PM3RD_VideoOverlayControl_KEY_ALPHA             (1<<5)
+#define PM3RD_VideoOverlayXStartLow				0x021
+#define PM3RD_VideoOverlayXStartHigh				0x022
+#define PM3RD_VideoOverlayYStartLow				0x023
+#define PM3RD_VideoOverlayYStartHigh				0x024
+#define PM3RD_VideoOverlayXEndLow				0x025
+#define PM3RD_VideoOverlayXEndHigh				0x026
+#define PM3RD_VideoOverlayYEndLow				0x027
+#define PM3RD_VideoOverlayYEndHigh				0x028
+#define PM3RD_VideoOverlayKeyR					0x029
+#define PM3RD_VideoOverlayKeyG					0x02a
+#define PM3RD_VideoOverlayKeyB					0x02b
+#define PM3RD_VideoOverlayBlend					0x02c
+        #define PM3RD_VideoOverlayBlend_FACTOR_0_PERCENT        (0<<6)
+        #define PM3RD_VideoOverlayBlend_FACTOR_25_PERCENT       (1<<6)
+        #define PM3RD_VideoOverlayBlend_FACTOR_75_PERCENT       (2<<6)
+        #define PM3RD_VideoOverlayBlend_FACTOR_100_PERCENT      (3<<6)
+
+#define PM3RD_DClkSetup1					0x1f0
+#define PM3RD_DClkSetup2					0x1f1
+#define PM3RD_KClkSetup1					0x1f2
+#define PM3RD_KClkSetup2					0x1f3
+
+#define PM3RD_DClkControl					0x200
+	#define PM3RD_DClkControl_SOURCE_PLL			(0<<4)
+	#define PM3RD_DClkControl_SOURCE_VSA			(1<<4)
+	#define PM3RD_DClkControl_SOURCE_VSB			(2<<4)
+	#define PM3RD_DClkControl_SOURCE_EXT			(3<<4)
+	#define PM3RD_DClkControl_STATE_RUN			(2<<2)
+	#define PM3RD_DClkControl_STATE_HIGH			(1<<2)
+	#define PM3RD_DClkControl_STATE_LOW			(0<<2)
+	#define PM3RD_DClkControl_LOCKED			(1<<1)
+	#define PM3RD_DClkControl_NOT_LOCKED			(0<<1)
+	#define PM3RD_DClkControl_ENABLE			(1<<0)
+	#define PM3RD_DClkControl_DISABLE			(0<<0)
+#define PM3RD_DClk0PreScale					0x201
+#define PM3RD_DClk0FeedbackScale				0x202
+#define PM3RD_DClk0PostScale					0x203
+        #define PM3_REF_CLOCK                                   14318
+#define PM3RD_DClk1PreScale					0x204
+#define PM3RD_DClk1FeedbackScale				0x205
+#define PM3RD_DClk1PostScale					0x206
+#define PM3RD_DClk2PreScale					0x207
+#define PM3RD_DClk2FeedbackScale				0x208
+#define PM3RD_DClk2PostScale					0x209
+#define PM3RD_DClk3PreScale					0x20a
+#define PM3RD_DClk3FeedbackScale				0x20b
+#define PM3RD_DClk3PostScale					0x20c
+#define PM3RD_KClkControl					0x20d
+	#define PM3RD_KClkControl_DISABLE			(0<<0)
+	#define PM3RD_KClkControl_ENABLE			(1<<0)
+	#define PM3RD_KClkControl_NOT_LOCKED			(0<<1)
+	#define PM3RD_KClkControl_LOCKED			(1<<1)
+	#define PM3RD_KClkControl_STATE_LOW			(0<<2)
+	#define PM3RD_KClkControl_STATE_HIGH			(1<<2)
+	#define PM3RD_KClkControl_STATE_RUN			(2<<2)
+	#define PM3RD_KClkControl_STATE_LOW_POWER		(3<<2)
+	#define PM3RD_KClkControl_SOURCE_PCLK			(0<<4)
+	#define PM3RD_KClkControl_SOURCE_HALF_PCLK		(1<<4)
+	#define PM3RD_KClkControl_SOURCE_PLL			(2<<4)
+#define PM3RD_KClkPreScale					0x20e
+#define PM3RD_KClkFeedbackScale					0x20f
+#define PM3RD_KClkPostScale					0x210
+#define PM3RD_MClkControl					0x211
+	#define PM3RD_MClkControl_DISABLE			(0<<0)
+	#define PM3RD_MClkControl_ENABLE			(1<<0)
+	#define PM3RD_MClkControl_NOT_LOCKED			(0<<1)
+	#define PM3RD_MClkControl_LOCKED			(1<<1)
+	#define PM3RD_MClkControl_STATE_LOW			(0<<2)
+	#define PM3RD_MClkControl_STATE_HIGH			(1<<2)
+	#define PM3RD_MClkControl_STATE_RUN			(2<<2)
+	#define PM3RD_MClkControl_STATE_LOW_POWER		(3<<2)
+	#define PM3RD_MClkControl_SOURCE_PCLK			(0<<4)
+	#define PM3RD_MClkControl_SOURCE_HALF_PCLK		(1<<4)
+	#define PM3RD_MClkControl_SOURCE_HALF_EXT		(3<<4)
+	#define PM3RD_MClkControl_SOURCE_EXT			(4<<4)
+	#define PM3RD_MClkControl_SOURCE_HALF_KCLK		(5<<4)
+	#define PM3RD_MClkControl_SOURCE_KCLK			(6<<4)
+#define PM3RD_MClkPreScale					0x212
+#define PM3RD_MClkFeedbackScale					0x213
+#define PM3RD_MClkPostScale					0x214
+#define PM3RD_SClkControl					0x215
+	#define PM3RD_SClkControl_DISABLE			(0<<0)
+	#define PM3RD_SClkControl_ENABLE			(1<<0)
+	#define PM3RD_SClkControl_NOT_LOCKED			(0<<1)
+	#define PM3RD_SClkControl_LOCKED			(1<<1)
+	#define PM3RD_SClkControl_STATE_LOW			(0<<2)
+	#define PM3RD_SClkControl_STATE_HIGH			(1<<2)
+	#define PM3RD_SClkControl_STATE_RUN			(2<<2)
+	#define PM3RD_SClkControl_STATE_LOW_POWER		(3<<2)
+	#define PM3RD_SClkControl_SOURCE_PCLK			(0<<4)
+	#define PM3RD_SClkControl_SOURCE_HALF_PCLK		(1<<4)
+	#define PM3RD_SClkControl_SOURCE_HALF_EXT		(3<<4)
+	#define PM3RD_SClkControl_SOURCE_EXT			(4<<4)
+	#define PM3RD_SClkControl_SOURCE_HALF_KCLK		(5<<4)
+	#define PM3RD_SClkControl_SOURCE_KCLK			(6<<4)
+#define PM3RD_SClkPreScale					0x216
+#define PM3RD_SClkFeedbackScale					0x217
+#define PM3RD_SClkPostScale					0x218
+
+#define PM3RD_CursorPalette(p)					(0x303+(p))
+#define PM3RD_CursorPattern(p)					(0x400+(p))
+/******************************************************
+*  GLINT Permedia3 Video Streaming Registers (0x5000) *
+*******************************************************/
+
+#define PM3VSConfiguration					0x5800
+
+/**********************************************
+*  GLINT Permedia3 Core Registers (0x8000+)   *
+***********************************************/
+#define PM3AALineWidth						0x94c0
+#define PM3AAPointsize						0x94a0
+#define PM3AlphaBlendAlphaMode					0xafa8
+#define PM3AlphaBlendAlphaModeAnd				0xad30
+#define PM3AlphaBlendAlphaModeOr				0xad38
+#define PM3AlphaBlendColorMode					0xafa0
+#define PM3AlphaBlendColorModeAnd				0xacb0
+#define PM3AlphaBlendColorModeOr				0xacb8
+#define PM3AlphaDestColor					0xaf88
+#define PM3AlphaSourceColor					0xaf80
+#define PM3AlphaTestMode					0x8800
+#define PM3AlphaTestModeAnd					0xabf0
+#define PM3AlphaTestModeOr					0xabf8
+#define PM3AntialiasMode					0x8808
+#define PM3AntialiasModeAnd					0xac00
+#define PM3AntialiasModeOr					0xac08
+/* ... */
+#define PM3BackgroundColor					0xb0c8
+/* ... */
+#define PM3ColorDDAMode						0x87e0
+#define PM3ColorDDAModeAnd					0xabe0
+#define PM3ColorDDAModeOr					0xabe8
+#define PM3CommandInterrupt					0xa990
+#define PM3ConstantColorDDA					0xafb0
+	#define PM3ConstantColorDDA_R(r)		((r)&0xff)
+	#define PM3ConstantColorDDA_G(g)		(((g)&0xff)<<8)
+	#define PM3ConstantColorDDA_B(b)		(((b)&0xff)<<16)
+	#define PM3ConstantColorDDA_A(a)		(((a)&0xff)<<24)
+#define PM3ContextData						0x8dd0
+#define PM3ContextDump						0x8dc0
+#define PM3ContextRestore					0x8dc8
+#define PM3Continue						0x8058
+#define PM3ContinueNewDom					0x8048
+#define PM3ContinueNewLine					0x8040
+#define PM3ContinueNewSub					0x8050
+#define PM3Count						0x8030
+/* ... */
+#define PM3DeltaControl						0x9350
+#define PM3DeltaControlAnd					0xab20
+#define PM3DeltaControlOr					0xab28
+#define PM3DeltaMode						0x9300
+#define PM3DeltaModeAnd						0xaad0
+#define PM3DeltaModeOr						0xaad8
+/* ... */
+#define PM3DitherMode						0x8818
+#define PM3DitherModeAnd					0xacd0
+#define PM3DitherModeOr						0xacd8
+/* ... */
+#define PM3dXDom						0x8008
+#define PM3dXSub						0x8018
+#define PM3dY							0x8028
+/* ... */
+#define PM3FBBlockColor						0x8ac8
+#define PM3FBBlockColor0					0xb060
+#define PM3FBBlockColor1					0xb068
+#define PM3FBBlockColor2					0xb070
+#define PM3FBBlockColor3					0xb078
+#define PM3FBBlockColorBack					0xb0a0
+#define PM3FBBlockColorBack0					0xb080
+#define PM3FBBlockColorBack1					0xb088
+#define PM3FBBlockColorBack2					0xb090
+#define PM3FBBlockColorBack3					0xb098
+#define PM3FBColor						0x8a98
+#define PM3FBDestReadBufferAddr0				0xae80
+#define PM3FBDestReadBufferAddr1				0xae88
+#define PM3FBDestReadBufferAddr2				0xae90
+#define PM3FBDestReadBufferAddr3				0xae98
+#define PM3FBDestReadBufferOffset0				0xaea0
+#define PM3FBDestReadBufferOffset1				0xaea8
+#define PM3FBDestReadBufferOffset2				0xaeb0
+#define PM3FBDestReadBufferOffset3				0xaeb8
+	#define PM3FBDestReadBufferOffset_XOffset(x)	((x)&0xffff)
+	#define PM3FBDestReadBufferOffset_YOffset(y)	(((y)&0xffff)<<16)
+#define PM3FBDestReadBufferWidth0				0xaec0
+#define PM3FBDestReadBufferWidth1				0xaec8
+#define PM3FBDestReadBufferWidth2				0xaed0
+#define PM3FBDestReadBufferWidth3				0xaed8
+	#define PM3FBDestReadBufferWidth_Width(w)	((w)&0x0fff)
+
+#define PM3FBDestReadEnables					0xaee8
+#define PM3FBDestReadEnablesAnd					0xad20
+#define PM3FBDestReadEnablesOr					0xad28
+	#define PM3FBDestReadEnables_E(e)		((e)&0xff)
+	#define PM3FBDestReadEnables_E0				1<<0
+	#define PM3FBDestReadEnables_E1				1<<1
+	#define PM3FBDestReadEnables_E2				1<<2
+	#define PM3FBDestReadEnables_E3				1<<3
+	#define PM3FBDestReadEnables_E4				1<<4
+	#define PM3FBDestReadEnables_E5				1<<5
+	#define PM3FBDestReadEnables_E6				1<<6
+	#define PM3FBDestReadEnables_E7				1<<7
+	#define PM3FBDestReadEnables_R(r)		(((r)&0xff)<<8)
+	#define PM3FBDestReadEnables_R0				1<<8
+	#define PM3FBDestReadEnables_R1				1<<9
+	#define PM3FBDestReadEnables_R2				1<<10
+	#define PM3FBDestReadEnables_R3				1<<11
+	#define PM3FBDestReadEnables_R4				1<<12
+	#define PM3FBDestReadEnables_R5				1<<13
+	#define PM3FBDestReadEnables_R6				1<<14
+	#define PM3FBDestReadEnables_R7				1<<15
+	#define PM3FBDestReadEnables_ReferenceAlpha(a)	(((a)&0xff)<<24)
+
+#define PM3FBDestReadMode					0xaee0
+#define PM3FBDestReadModeAnd					0xac90
+#define PM3FBDestReadModeOr					0xac98
+	#define PM3FBDestReadMode_ReadDisable			0<<0
+	#define PM3FBDestReadMode_ReadEnable			1<<0
+	#define PM3FBDestReadMode_StripePitch(sp)	(((sp)&0x7)<<2
+	#define PM3FBDestReadMode_StripeHeight(sh)	(((sh)&0x7)<<7
+	#define PM3FBDestReadMode_Enable0			1<<8
+	#define PM3FBDestReadMode_Enable1			1<<9
+	#define PM3FBDestReadMode_Enable2			1<<10
+	#define PM3FBDestReadMode_Enable3			1<<11
+	#define PM3FBDestReadMode_Layout0(l)		(((l)&0x3)<<12
+	#define PM3FBDestReadMode_Layout1(l)		(((l)&0x3)<<14
+	#define PM3FBDestReadMode_Layout2(l)		(((l)&0x3)<<16
+	#define PM3FBDestReadMode_Layout3(l)		(((l)&0x3)<<18
+	#define PM3FBDestReadMode_Origin0			1<<20
+	#define PM3FBDestReadMode_Origin1			1<<21
+	#define PM3FBDestReadMode_Origin2			1<<22
+	#define PM3FBDestReadMode_Origin3			1<<23
+	#define PM3FBDestReadMode_Blocking			1<<24
+	#define PM3FBDestReadMode_UseReadEnabled		1<<26
+	#define PM3FBDestReadMode_AlphaFiltering		1<<27
+
+#define PM3FBHardwareWriteMask					0x8ac0
+#define PM3FBSoftwareWriteMask					0x8820
+#define PM3FBData						0x8aa0
+#define PM3FBSourceData						0x8aa8
+#define PM3FBSourceReadBufferAddr				0xaf08
+#define PM3FBSourceReadBufferOffset				0xaf10
+	#define PM3FBSourceReadBufferOffset_XOffset(x)	((x)&0xffff)
+	#define PM3FBSourceReadBufferOffset_YOffset(y)	(((y)&0xffff)<<16)
+#define PM3FBSourceReadBufferWidth				0xaf18
+	#define PM3FBSourceReadBufferWidth_Width(w)	((w)&0x0fff)
+#define PM3FBSourceReadMode					0xaf00
+#define PM3FBSourceReadModeAnd					0xaca0
+#define PM3FBSourceReadModeOr					0xaca8
+	#define PM3FBSourceReadMode_ReadDisable			(0<<0)
+	#define PM3FBSourceReadMode_ReadEnable			(1<<0)
+	#define PM3FBSourceReadMode_StripePitch(sp)	(((sp)&0x7)<<2
+	#define PM3FBSourceReadMode_StripeHeight(sh)	(((sh)&0x7)<<7
+	#define PM3FBSourceReadMode_Layout(l)		(((l)&0x3)<<8
+	#define PM3FBSourceReadMode_Origin			1<<10
+	#define PM3FBSourceReadMode_Blocking			1<<11
+	#define PM3FBSourceReadMode_UserTexelCoord		1<<13
+	#define PM3FBSourceReadMode_WrapXEnable			1<<14
+	#define PM3FBSourceReadMode_WrapYEnable			1<<15
+	#define PM3FBSourceReadMode_WrapX(w)		(((w)&0xf)<<16
+	#define PM3FBSourceReadMode_WrapY(w)		(((w)&0xf)<<20
+	#define PM3FBSourceReadMode_ExternalSourceData		1<<24
+#define PM3FBWriteBufferAddr0                                   0xb000
+#define PM3FBWriteBufferAddr1                                   0xb008
+#define PM3FBWriteBufferAddr2                                   0xb010
+#define PM3FBWriteBufferAddr3                                   0xb018
+
+#define PM3FBWriteBufferOffset0                                 0xb020
+#define PM3FBWriteBufferOffset1                                 0xb028
+#define PM3FBWriteBufferOffset2                                 0xb030
+#define PM3FBWriteBufferOffset3                                 0xb038
+	#define PM3FBWriteBufferOffset_XOffset(x)		((x)&0xffff)
+	#define PM3FBWriteBufferOffset_YOffset(y)		(((y)&0xffff)<<16)
+
+#define PM3FBWriteBufferWidth0                                  0xb040
+#define PM3FBWriteBufferWidth1                                  0xb048
+#define PM3FBWriteBufferWidth2                                  0xb050
+#define PM3FBWriteBufferWidth3                                  0xb058
+	#define PM3FBWriteBufferWidth_Width(w)			((w)&0x0fff)
+
+#define PM3FBWriteMode                                          0x8ab8
+#define PM3FBWriteModeAnd                                       0xacf0
+#define PM3FBWriteModeOr                                        0xacf8
+	#define PM3FBWriteMode_WriteDisable                     0<<0
+	#define PM3FBWriteMode_WriteEnable                      1<<0
+	#define PM3FBWriteMode_Replicate                        1<<4
+	#define PM3FBWriteMode_OpaqueSpan                       1<<5
+	#define PM3FBWriteMode_StripePitch(p)            (((p)&0x7)<<6)
+	#define PM3FBWriteMode_StripeHeight(h)           (((h)&0x7)<<9)
+	#define PM3FBWriteMode_Enable0                          1<<12
+	#define PM3FBWriteMode_Enable1                          1<<13
+	#define PM3FBWriteMode_Enable2                          1<<14
+	#define PM3FBWriteMode_Enable3                          1<<15
+	#define PM3FBWriteMode_Layout0(l)               (((l)&0x3)<<16)
+	#define PM3FBWriteMode_Layout1(l)               (((l)&0x3)<<18)
+	#define PM3FBWriteMode_Layout2(l)               (((l)&0x3)<<20)
+	#define PM3FBWriteMode_Layout3(l)               (((l)&0x3)<<22)
+	#define PM3FBWriteMode_Origin0                          1<<24
+	#define PM3FBWriteMode_Origin1                          1<<25
+	#define PM3FBWriteMode_Origin2                          1<<26
+	#define PM3FBWriteMode_Origin3                          1<<27
+#define PM3ForegroundColor					0xb0c0
+/* ... */
+#define PM3GIDMode						0xb538
+#define PM3GIDModeAnd						0xb5b0
+#define PM3GIDModeOr						0xb5b8
+/* ... */
+#define PM3LBDestReadBufferAddr					0xb510
+#define PM3LBDestReadBufferOffset				0xb518
+#define PM3LBDestReadEnables					0xb508
+#define PM3LBDestReadEnablesAnd					0xb590
+#define PM3LBDestReadEnablesOr					0xb598
+#define PM3LBDestReadMode					0xb500
+#define PM3LBDestReadModeAnd					0xb580
+#define PM3LBDestReadModeOr					0xb588
+	#define PM3LBDestReadMode_Disable			0<<0
+	#define PM3LBDestReadMode_Enable			1<<0
+	#define PM3LBDestReadMode_StripePitch(p)		(((p)&0x7)<<2)
+	#define PM3LBDestReadMode_StripeHeight(h)		(((h)&0x7)<<5)
+	#define PM3LBDestReadMode_Layout			1<<8
+	#define PM3LBDestReadMode_Origin			1<<9
+	#define PM3LBDestReadMode_UserReadEnables		1<<10
+	#define PM3LBDestReadMode_Packed16			1<<11
+	#define PM3LBDestReadMode_Width(w)			(((w)&0xfff)<<12)
+#define PM3LBReadFormat						0x8888
+	#define PM3LBReadFormat_DepthWidth(w)			(((w)&0x3)<<0)
+	#define PM3LBReadFormat_StencilWidth(w)			(((w)&0xf)<<2)
+	#define PM3LBReadFormat_StencilPosition(p)		(((p)&0x1f)<<6)
+	#define PM3LBReadFormat_FCPWidth(w)			(((w)&0xf)<<11)
+	#define PM3LBReadFormat_FCPPosition(p)			(((p)&0x1f)<<15)
+	#define PM3LBReadFormat_GIDWidth(w)			(((w)&0x7)<<20)
+	#define PM3LBReadFormat_GIDPosition(p)			(((p)&0x1f)<<23)
+#define PM3LBSourceReadBufferAddr				0xb528
+#define PM3LBSourceReadBufferOffset				0xb530
+#define PM3LBSourceReadMode					0xb520
+#define PM3LBSourceReadModeAnd					0xb5a0
+#define PM3LBSourceReadModeOr					0xb5a8
+	#define PM3LBSourceReadMode_Enable			1<<0
+	#define PM3LBSourceReadMode_StripePitch(p)		(((p)&0x7)<<2)
+	#define PM3LBSourceReadMode_StripeHeight(h)		(((h)&0x7)<<5)
+	#define PM3LBSourceReadMode_Layout			1<<8
+	#define PM3LBSourceReadMode_Origin			1<<9
+	#define PM3LBSourceReadMode_Packed16			1<<10
+	#define PM3LBSourceReadMode_Width(w)			(((w)&0xfff)<<11)
+#define PM3LBStencil						0x88a8
+#define PM3LBWriteBufferAddr					0xb540
+#define PM3LBWriteBufferOffset					0xb548
+#define PM3LBWriteFormat					0x88c8
+	#define PM3LBWriteFormat_DepthWidth(w)			(((w)&0x3)<<0)
+	#define PM3LBWriteFormat_StencilWidth(w)		(((w)&0xf)<<2)
+	#define PM3LBWriteFormat_StencilPosition(p)		(((p)&0x1f)<<6)
+	#define PM3LBWriteFormat_GIDWidth(w)			(((w)&0x7)<<20)
+	#define PM3LBWriteFormat_GIDPosition(p)			(((p)&0x1f)<<23)
+#define PM3LBWriteMode						0x88c0
+#define PM3LBWriteModeAnd					0xac80
+#define PM3LBWriteModeOr					0xac88
+	#define PM3LBWriteMode_WriteDisable			0<<0
+	#define PM3LBWriteMode_WriteEnable			1<<0
+	#define PM3LBWriteMode_StripePitch(p)			(((p)&0x7)<<3)
+	#define PM3LBWriteMode_StripeHeight(h)			(((h)&0x7)<<6)
+	#define PM3LBWriteMode_Layout				1<<9
+	#define PM3LBWriteMode_Origin				1<<10
+	#define PM3LBWriteMode_Packed16				1<<11
+	#define PM3LBWriteMode_Width(w)				(((w)&0xfff)<<12)
+/* ... */
+#define PM3LineStippleMode					0x81a8
+#define PM3LineStippleModeAnd					0xabc0
+#define PM3LineStippleModeOr					0xabc8
+#define PM3LoadLineStippleCounters				0x81b0
+/* ... */
+#define PM3LogicalOpMode					0x8828
+#define PM3LogicalOpModeAnd					0xace0
+#define PM3LogicalOpModeOr					0xace8
+	#define PM3LogicalOpMode_Disable			(0<<0)
+	#define PM3LogicalOpMode_Enable				(1<<0)
+	#define PM3LogicalOpMode_LogicOp(op)			(((op)&0xf)<<1)
+	#define PM3LogicalOpMode_UseConstantWriteData_Disable	(0<<5)
+	#define PM3LogicalOpMode_UseConstantWriteData_Enable	(1<<5)
+	#define PM3LogicalOpMode_Background_Disable		(0<<6)
+	#define PM3LogicalOpMode_Background_Enable		(1<<6)
+	#define PM3LogicalOpMode_Background_LogicOp(op)		(((op)&0xf)<<7)
+	#define PM3LogicalOpMode_UseConstantSource_Disable	(0<<11)
+	#define PM3LogicalOpMode_UseConstantSource_Enable	(1<<11)
+
+/* ... */
+#define PM3LUT							0x8e80
+/* ... */
+#define PM3LUT							0x8e80
+#define PM3LUTAddress						0x84d0
+#define PM3LUTData						0x84c8
+#define PM3LUTIndex						0x84c0
+#define PM3LUTMode						0xb378
+#define PM3LUTModeAnd						0xad70
+#define PM3LUTModeOr						0xad78
+#define PM3LUTTransfer						0x84d8
+/* ... */
+#define PM3PixelSize						0x80c0
+	#define PM3PixelSize_GLOBAL_32BIT			(0<<0)
+	#define PM3PixelSize_GLOBAL_16BIT			(1<<0)
+	#define PM3PixelSize_GLOBAL_8BIT			(2<<0)
+	#define PM3PixelSize_RASTERIZER_32BIT			(0<<2)
+	#define PM3PixelSize_RASTERIZER_16BIT			(1<<2)
+	#define PM3PixelSize_RASTERIZER_8BIT			(2<<2)
+	#define PM3PixelSize_SCISSOR_AND_STIPPLE_32BIT		(0<<4)
+	#define PM3PixelSize_SCISSOR_AND_STIPPLE_16BIT		(1<<4)
+	#define PM3PixelSize_SCISSOR_AND_STIPPLE_8BIT		(2<<4)
+	#define PM3PixelSize_TEXTURE_32BIT			(0<<6)
+	#define PM3PixelSize_TEXTURE_16BIT			(1<<6)
+	#define PM3PixelSize_TEXTURE_8BIT			(2<<6)
+	#define PM3PixelSize_LUT_32BIT				(0<<8)
+	#define PM3PixelSize_LUT_16BIT				(1<<8)
+	#define PM3PixelSize_LUT_8BIT				(2<<8)
+	#define PM3PixelSize_FRAMEBUFFER_32BIT			(0<<10)
+	#define PM3PixelSize_FRAMEBUFFER_16BIT			(1<<10)
+	#define PM3PixelSize_FRAMEBUFFER_8BIT			(2<<10)
+	#define PM3PixelSize_LOGICAL_OP_32BIT			(0<<12)
+	#define PM3PixelSize_LOGICAL_OP_16BIT			(1<<12)
+	#define PM3PixelSize_LOGICAL_OP_8BIT			(2<<12)
+	#define PM3PixelSize_LOCALBUFFER_32BIT			(0<<14)
+	#define PM3PixelSize_LOCALBUFFER_16BIT			(1<<14)
+	#define PM3PixelSize_LOCALBUFFER_8BIT			(2<<14)
+	#define PM3PixelSize_SETUP_32BIT			(0<<16)
+	#define PM3PixelSize_SETUP_16BIT			(1<<16)
+	#define PM3PixelSize_SETUP_8BIT				(2<<16)
+	#define PM3PixelSize_GLOBAL				(0<<31)
+	#define PM3PixelSize_INDIVIDUAL				(1<<31)
+/* ... */
+#define PM3Render						0x8038
+	#define PM3Render_AreaStipple_Disable			(0<<0)
+	#define PM3Render_AreaStipple_Enable			(1<<0)
+	#define PM3Render_LineStipple_Disable			(0<<1)
+	#define PM3Render_LineStipple_Enable			(1<<1)
+	#define PM3Render_ResetLine_Disable			(0<<2)
+	#define PM3Render_ResetLine_Enable			(1<<2)
+	#define PM3Render_FastFill_Disable			(0<<3)
+	#define PM3Render_FastFill_Enable			(1<<3)
+	#define PM3Render_Primitive_Line			(0<<6)
+	#define PM3Render_Primitive_Trapezoid			(1<<6)
+	#define PM3Render_Primitive_Point			(2<<6)
+	#define PM3Render_Antialias_Disable			(0<<8)
+	#define PM3Render_Antialias_Enable			(1<<8)
+	#define PM3Render_Antialias_SubPixelRes_4x4		(0<<9)
+	#define PM3Render_Antialias_SubPixelRes_8x8		(1<<9)
+	#define PM3Render_UsePointTable_Disable			(0<<10)
+	#define PM3Render_UsePointTable_Enable			(1<<10)
+	#define PM3Render_SyncOnbitMask_Disable			(0<<11)
+	#define PM3Render_SyncOnBitMask_Enable			(1<<11)
+	#define PM3Render_SyncOnHostData_Disable		(0<<12)
+	#define PM3Render_SyncOnHostData_Enable			(1<<12)
+	#define PM3Render_Texture_Disable			(0<<13)
+	#define PM3Render_Texture_Enable			(1<<13)
+	#define PM3Render_Fog_Disable				(0<<14)
+	#define PM3Render_Fog_Enable				(1<<14)
+	#define PM3Render_Coverage_Disable			(0<<15)
+	#define PM3Render_Coverage_Enable			(1<<15)
+	#define PM3Render_SubPixelCorrection_Disable		(0<<16)
+	#define PM3Render_SubPixelCorrection_Enable		(1<<16)
+	#define PM3Render_SpanOperation_Disable			(0<<18)
+	#define PM3Render_SpanOperation_Enable			(1<<18)
+	#define PM3Render_FBSourceRead_Disable			(0<<27)
+	#define PM3Render_FBSourceRead_Enable			(1<<27)
+#define PM3RasterizerMode					0x80a0
+#define PM3RasterizerModeAnd					0xaba0
+#define PM3RasterizerModeOr					0xabb8
+#define PM3RectangleHeight					0x94e0
+#define PM3Render						0x8038
+#define PM3RepeatLine						0x9328
+#define PM3ResetPickResult					0x8c20
+#define PM3RLEMask						0x8c48
+#define PM3RouterMode						0x8840
+#define PM3RStart						0x8780
+#define PM3S1Start						0x8400
+#define PM3aveLineStippleCounters				0x81c0
+#define PM3ScissorMaxXY						0x8190
+#define PM3ScissorMinXY						0x8188
+#define PM3ScissorMode						0x8180
+#define PM3ScissorModeAnd					0xabb0
+#define PM3ScissorModeOr					0xabb8
+#define PM3ScreenSize						0x8198
+#define PM3Security						0x8908
+#define PM3SetLogicalTexturePage				0xb360
+#define PM3SizeOfFramebuffer					0xb0a8
+#define PM3SStart						0x8388
+#define PM3StartXDom						0x8000
+#define PM3StartXSub						0x8010
+#define PM3StartY						0x8020
+/* ... */
+#define PM3SpanColorMask					0x8168
+/* ... */
+#define PM3TextureApplicationMode				0x8680
+#define PM3TextureApplicationModeAnd				0xac50
+#define PM3TextureApplicationModeOr				0xac58
+#define PM3TextureBaseAddr					0x8500
+#define PM3TextureCacheControl					0x8490
+#define PM3TextureChromaLower0					0x84f0
+#define PM3TextureChromaLower1					0x8608
+#define PM3TextureChromaUpper0					0x84e8
+#define PM3TextureChromaUpper1					0x8600
+#define PM3TextureCompositeAlphaMode0				0xb310
+#define PM3TextureCompositeAlphaMode0And			0xb390
+#define PM3TextureCompositeAlphaMode0Or				0xb398
+#define PM3TextureCompositeAlphaMode1				0xb320
+#define PM3TextureCompositeAlphaMode1And			0xb3b0
+#define PM3TextureCompositeAlphaMode1Or				0xb3b8
+#define PM3TextureCompositeColorMode0				0xb308
+#define PM3TextureCompositeColorMode0And			0xb380
+#define PM3TextureCompositeColorMode0Or				0xb388
+#define PM3TextureCompositeColorMode1				0xb318
+#define PM3TextureCompositeColorMode1And			0xb3a0
+#define PM3TextureCompositeColorMode1Or				0xb3a8
+#define PM3TextureCompositeFactor0				0xb328
+#define PM3TextureCompositeFactor1				0xb330
+#define PM3TextureCompositeMode					0xb300
+#define PM3TextureCoordMode					0x8380
+#define PM3TextureCoordModeAnd					0xac20
+#define PM3TextureCoordModeOr					0xac28
+#define PM3TextureData						0x88e8
+/*
+#define PM3TextureDownloadControl				0x0108
+*/
+#define PM3TextureDownloadOffset				0x88f0
+#define PM3TextureEnvColor					0x8688
+#define PM3TextureFilterMode					0x84e0
+#define PM3TextureFilterModeAnd					0xad50
+#define PM3TextureFilterModeOr					0xad58
+#define PM3TextureIndexMode0					0xb338
+#define PM3TextureIndexMode0And					0xb3c0
+#define PM3TextureIndexMode0Or					0xb3c8
+#define PM3TextureIndexMode1					0xb340
+#define PM3TextureIndexMode1And					0xb3d0
+#define PM3TextureIndexMode1Or					0xb3d8
+/* ... */
+#define PM3TextureMapSize                                       0xb428
+#define PM3TextureMapWidth0                                     0x8580
+#define PM3TextureMapWidth1                                     0x8588
+        #define PM3TextureMapWidth_Width(w)             ((w&0xfff)<<0)
+        #define PM3TextureMapWidth_BorderLayout                 (1<<12)
+        #define PM3TextureMapWidth_Layout_Linear                (0<<13)
+        #define PM3TextureMapWidth_Layout_Patch64               (1<<13)
+        #define PM3TextureMapWidth_Layout_Patch32_2             (2<<13)
+        #define PM3TextureMapWidth_Layout_Patch2                (3<<13)
+        #define PM3TextureMapWidth_HostTexture                  (1<<15)
+#define PM3TextureReadMode0                                     0xb400
+#define PM3TextureReadMode0And                                  0xac30
+#define PM3TextureReadMode0Or                                   0xac38
+#define PM3TextureReadMode1                                     0xb408
+#define PM3TextureReadMode1And                                  0xad40
+#define PM3TextureReadMode1Or                                   0xad48
+/* ... */
+#define PM3WaitForCompletion					0x80b8
+#define PM3Window						0x8980
+	#define PM3Window_ForceLBUpdate				1<<3
+	#define PM3Window_LBUpdateSource			1<<4
+	#define PM3Window_FrameCount(c)				(((c)&0xff)<<9
+	#define PM3Window_StencilFCP				1<<17
+	#define PM3Window_DepthFCP				1<<18
+	#define PM3Window_OverrideWriteFiltering		1<<19
+#define PM3WindowAnd						0xab80
+#define PM3WindowOr						0xab88
+#define PM3WindowOrigin						0x81c8
+#define PM3XBias						0x9480
+#define PM3YBias						0x9488
+#define PM3YLimits						0x80a8
+#define PM3UVMode						0x8f00
+#define PM3ZFogBias						0x86b8
+#define PM3ZStart						0xadd8
+#define PM3ZStartL						0x89b8
+#define PM3ZStartU						0x89b0
+
+
+/**********************************************
+*  GLINT Permedia3 2D setup Unit              *
+***********************************************/
+#define PM3Config2D						0xb618
+	#define PM3Config2D_OpaqueSpan				1<<0
+	#define PM3Config2D_MultiRXBlit				1<<1
+	#define PM3Config2D_UserScissorEnable			1<<2
+	#define PM3Config2D_FBDestReadEnable			1<<3
+	#define PM3Config2D_AlphaBlendEnable			1<<4
+	#define PM3Config2D_DitherEnable			1<<5
+	#define PM3Config2D_ForegroundROPEnable			1<<6
+	#define PM3Config2D_ForegroundROP(rop)		(((rop)&0xf)<<7)
+	#define PM3Config2D_BackgroundROPEnable			1<<11
+	#define PM3Config2D_BackgroundROP(rop)		(((rop)&0xf)<<12)
+	#define PM3Config2D_UseConstantSource			1<<16
+	#define PM3Config2D_FBWriteEnable			1<<17
+	#define PM3Config2D_Blocking				1<<18
+	#define PM3Config2D_ExternalSourceData			1<<19
+	#define PM3Config2D_LUTModeEnable			1<<20
+#define PM3DownloadGlyphwidth					0xb658
+	#define PM3DownloadGlyphwidth_GlyphWidth(gw)	((gw)&0xffff)
+#define PM3DownloadTarget					0xb650
+	#define PM3DownloadTarget_TagName(tag)		((tag)&0x1fff)
+#define PM3GlyphData						0xb660
+#define PM3GlyphPosition					0xb608
+	#define PM3GlyphPosition_XOffset(x)		((x)&0xffff)
+	#define PM3GlyphPosition_YOffset(y)		(((y)&0xffff)<<16)
+#define PM3Packed4Pixels					0xb668
+#define PM3Packed8Pixels					0xb630
+#define PM3Packed16Pixels					0xb638
+#define PM3RectanglePosition					0xb600
+	#define PM3RectanglePosition_XOffset(x)		((x)&0xffff)
+	#define PM3RectanglePosition_YOffset(y)		(((y)&0xffff)<<16)
+#define PM3Render2D						0xb640
+	#define PM3Render2D_Width(w)			((w)&0x0fff)
+	#define PM3Render2D_Operation_Normal			0<<12
+	#define PM3Render2D_Operation_SyncOnHostData		1<<12
+	#define PM3Render2D_Operation_SyncOnBitMask		2<<12
+	#define PM3Render2D_Operation_PatchOrderRendering	3<<12
+	#define PM3Render2D_FBSourceReadEnable			1<<14
+	#define PM3Render2D_SpanOperation			1<<15
+	#define PM3Render2D_Height(h)			(((h)&0x0fff)<<16)
+	#define PM3Render2D_XPositive				1<<28
+	#define PM3Render2D_YPositive				1<<29
+	#define PM3Render2D_AreaStippleEnable			1<<30
+	#define PM3Render2D_TextureEnable			1<<31
+#define PM3Render2DGlyph					0xb648
+	#define PM3Render2DGlyph_Width(w)		((w)&0x7f)
+	#define PM3Render2DGlyph_Height(h)		(((h)&0x7f)<<7)
+	#define PM3Render2DGlyph_XOffset(x)		(((x)&0x1ff)<<14)
+	#define PM3Render2DGlyph_YOffset(y)		(((y)&0x1ff)<<23)
+#define PM3RenderPatchOffset					0xb610
+	#define PM3RenderPatchOffset_XOffset(x)		((x)&0xffff)
+	#define PM3RenderPatchOffset_YOffset(y)		(((y)&0xffff)<<16)
+#define PM3RLCount						0xb678
+	#define PM3RLCount_Count(c)			((c)&0x0fff)
+#define PM3RLData						0xb670
+
+/**********************************************
+*  GLINT Permedia3 Alias Register             *
+***********************************************/
+#define PM3FillBackgroundColor                                  0x8330
+#define PM3FillConfig2D0                                        0x8338
+#define PM3FillConfig2D1                                        0x8360
+	#define PM3FillConfig2D_OpaqueSpan                      1<<0
+	#define PM3FillConfig2D_MultiRXBlit                     1<<1
+	#define PM3FillConfig2D_UserScissorEnable               1<<2
+	#define PM3FillConfig2D_FBDestReadEnable                1<<3
+	#define PM3FillConfig2D_AlphaBlendEnable                1<<4
+	#define PM3FillConfig2D_DitherEnable                    1<<5
+	#define PM3FillConfig2D_ForegroundROPEnable             1<<6
+	#define PM3FillConfig2D_ForegroundROP(rop)              (((rop)&0xf)<<7)
+	#define PM3FillConfig2D_BackgroundROPEnable             1<<11
+	#define PM3FillConfig2D_BackgroundROP(rop)              (((rop)&0xf)<<12)
+	#define PM3FillConfig2D_UseConstantSource               1<<16
+	#define PM3FillConfig2D_FBWriteEnable                   1<<17
+	#define PM3FillConfig2D_Blocking                        1<<18
+	#define PM3FillConfig2D_ExternalSourceData              1<<19
+	#define PM3FillConfig2D_LUTModeEnable                   1<<20
+#define PM3FillFBDestReadBufferAddr                             0x8310
+#define PM3FillFBSourceReadBufferAddr                           0x8308
+#define PM3FillFBSourceReadBufferOffset                         0x8340
+	#define PM3FillFBSourceReadBufferOffset_XOffset(x)     ((x)&0xffff)
+	#define PM3FillFBSourceReadBufferOffset_YOffset(y)      (((y)&0xffff)<<16)
+#define PM3FillFBWriteBufferAddr                                0x8300
+#define PM3FillForegroundColor0                                 0x8328
+#define PM3FillForegroundColor1                                 0x8358
+#define PM3FillGlyphPosition                                    0x8368
+        #define PM3FillGlyphPosition_XOffset(x)                        ((x)&0xffff)
+	#define PM3FillGlyphPosition_YOffset(y)                        (((y)&0xffff)<<16)
+#define PM3FillRectanglePosition                                0x8348
+	#define PM3FillRectanglePosition_XOffset(x)            ((x)&0xffff)
+	#define PM3FillRectanglePosition_YOffset(y)            (((y)&0xffff)<<16)
+
+#define PM3_REGS_SIZE           0x10000
+#define PM3_MAX_PIXCLOCK        300000
+/* a few more useful registers & regs value... */
+#define PM3Sync 0x8c40
+        #define PM3Sync_Tag 0x188
+#define PM3FilterMode 0x8c00
+        #define PM3FilterModeSync 0x400
+#define PM3OutputFifo 0x2000
+#define PM3StatisticMode 0x8c08
+#define PM3AreaStippleMode 0x81a0
+        #define AreaStipplePattern0					(0x8200)
+        #define AreaStipplePattern1					(0x8208)
+        #define AreaStipplePattern2					(0x8210)
+        #define AreaStipplePattern3					(0x8218)
+        #define AreaStipplePattern4					(0x8220)
+        #define AreaStipplePattern5					(0x8228)
+        #define AreaStipplePattern6					(0x8230)
+        #define AreaStipplePattern7					(0x8238)
+        #define AreaStipplePattern8					(0x8240)
+        #define AreaStipplePattern9					(0x8248)
+        #define AreaStipplePattern10					(0x8250)
+        #define AreaStipplePattern11					(0x8258)
+        #define AreaStipplePattern12					(0x8260)
+        #define AreaStipplePattern13					(0x8268)
+        #define AreaStipplePattern14					(0x8270)
+        #define AreaStipplePattern15					(0x8278)
+        #define AreaStipplePattern16					(0x8280)
+        #define AreaStipplePattern17					(0x8288)
+        #define AreaStipplePattern18					(0x8290)
+        #define AreaStipplePattern19					(0x8298)
+        #define AreaStipplePattern20					(0x82a0)
+        #define AreaStipplePattern21					(0x82a8)
+        #define AreaStipplePattern22					(0x82b0)
+        #define AreaStipplePattern23					(0x82b8)
+        #define AreaStipplePattern24					(0x82c0)
+        #define AreaStipplePattern25					(0x82c8)
+        #define AreaStipplePattern26					(0x82d0)
+        #define AreaStipplePattern27					(0x82d8)
+        #define AreaStipplePattern28					(0x82eo)
+        #define AreaStipplePattern29					(0x82e8)
+        #define AreaStipplePattern30					(0x82f0)
+        #define AreaStipplePattern31					(0x82f8)
+        #define AreaStipplePattern_indexed(i)             (0x8200 + ((i) * 0x8))
+
+#define PM3DepthMode 0x89a0
+#define PM3StencilMode 0x8988
+#define PM3StencilData 0x8990
+#define PM3TextureReadMode 0x8670
+#define PM3FogMode 0x8690
+#define PM3ChromaTestMode 0x8f18
+#define PM3YUVMode 0x8f00
+#define PM3BitMaskPattern 0x8068
+
+/* ***************************** */
+/* ***** pm3fb IOCTL const ***** */
+/* ***************************** */
+/* debug-only IOCTL */
+#define PM3FBIO_CLEARMEMORY 0x504D3300 /* 'PM3\000' */
+#define PM3FBIO_CLEARCMAP   0x504D3301 /* 'PM3\001' */
+/* common use IOCTL */
+#define PM3FBIO_RESETCHIP   0x504D33FF /* 'PM3\377' */
+
+/* ***************************************** */
+/* ***** pm3fb useful define and macro ***** */
+/* ***************************************** */
+
+/* kernel -specific definitions */
+/* what kernel is this ? */
+#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)))
+#define KERNEL_2_5
+#endif
+
+#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)))
+#define KERNEL_2_4
+#endif
+
+#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))) 
+#define KERNEL_2_2
+/* pci_resource_start, available in 2.2.18 */
+#include <linux/kcomp.h>
+#ifdef CONFIG_FB_OF
+#define SUPPORT_FB_OF
+#endif
+#endif
+
+#if (!defined(KERNEL_2_2)) && (!defined(KERNEL_2_4)) && (!defined(KERNEL_2_5))
+#error "Only kernel 2.2.x, kernel 2.4.y and kernel 2.5.z might work"
+#endif
+
+/* not sure if/why it's needed. doesn't work without on my PowerMac... */
+#ifdef __BIG_ENDIAN
+#define MUST_BYTESWAP
+#endif
+
+/* for compatibility between 2.5, 2.4 and 2.2 */
+#ifndef B_FREE
+#define B_FREE   -1
+#endif
+
+/* permedia3 -specific definitions */
+#define PM3_SCALE_TO_CLOCK(pr, fe, po) ((2 * PM3_REF_CLOCK * fe) / (pr * (1 << (po))))
+#define PICOS2KHZ(a) (1000000000UL/(a))
+#define KHZ2PICOS(a) (1000000000UL/(a))
+
+/* in case it's not in linux/pci.h */
+#ifndef PCI_DEVICE_ID_3DLABS_PERMEDIA3
+#define PCI_DEVICE_ID_3DLABS_PERMEDIA3 0x000a
+#endif
+
+/* max number of simultaneous board */
+/* warning : make sure module array def's are coherent with PM3_MAX_BOARD */
+#define PM3_MAX_BOARD 4
+#define PM3_MAX_BOARD_MODULE_ARRAY_SHORT "1-4h"
+#define PM3_MAX_BOARD_MODULE_ARRAY_STRING "1-4s"
+
+/* max size of options */
+#define PM3_OPTIONS_SIZE 256
+
+/* max size of font name */
+#define PM3_FONTNAME_SIZE 40
+
+/* do we want accelerated console  */
+#define PM3FB_USE_ACCEL 1
+
+/* useful ? */
+#define CHAR_IS_NUM(a)  ((((a) >= '0') && ((a) <= '9')) ? 1 : 0)
+
+/* for driver debugging ONLY */
+/* 0 = assert only, 1 = error, 2 = info, 3+ = verbose */
+/* define PM3FB_MASTER_DEBUG 1 */
+#if defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 3)
+#define PM3FB_TRACE
+#endif /* defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 3) */
+
+#ifdef PM3FB_MASTER_DEBUG
+#define DPRINTK(l,a,b...) do { if ((l) <= PM3FB_MASTER_DEBUG) printk("pm3fb: %s: " a, __FUNCTION__ , ## b); } while (0)
+#define DASSERT(t,a,b...) do { if (!(t)) printk("pm3fb: _assert failed: %s: " a, __FUNCTION__ , ## b); } while (0)
+#ifdef PM3FB_TRACE
+#define DTRACE printk("pm3fb: _enter %s\n", __FUNCTION__)
+#else /* PM3FB_TRACE */
+#define DTRACE
+#endif /* PM3FB_TRACE */
+#else /* PM3FB_MASTER_DEBUG */
+#define DPRINTK(l,a,b...)
+#define DASSERT(t,a,b...)
+#define DTRACE
+#endif /* PM3FB_MASTER_DEBUG */
+
+#if defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2)
+#define PM3_SHOW_CUR_MODE pm3fb_show_cur_mode(l_fb_info)
+#else
+#define PM3_SHOW_CUR_MODE /* pm3fb_show_cur_mode() */
+#endif
+
+/* ******************************************** */
+/* ***** A bunch of register-access macro ***** */
+/* ******************************************** */
+#ifdef KERNEL_2_2
+#ifdef MUST_BYTESWAP /* we are writing big_endian to big_endian through a little_endian macro */
+#define PM3_READ_REG(r) __swab32(readl((l_fb_info->vIOBase + r)))
+#define PM3_WRITE_REG(r, v) writel(__swab32(v), (l_fb_info->vIOBase + r))
+#else /* MUST_BYTESWAP */
+#define PM3_WRITE_REG(r, v) writel(v, (l_fb_info->vIOBase + r))
+#define PM3_READ_REG(r) readl((l_fb_info->vIOBase + r))
+#endif /* MUST_BYTESWAP */
+#endif /* KERNEL_2_2 */
+#if (defined KERNEL_2_4) || (defined KERNEL_2_5) /* native-endian access */
+#define PM3_WRITE_REG(r, v) fb_writel(v, (l_fb_info->vIOBase + r))
+#define PM3_READ_REG(r) fb_readl((l_fb_info->vIOBase + r))
+#endif /* KERNEL_2_4 or KERNEL_2_5 */
+
+
+#define depth2bpp(d) ((d + 7L) & ~7L)
+#define depth2ByPP(d) (depth2bpp(d) / 8)
+
+#define depth_supported(d) ((d == 8) || (d == 12) || (d == 15) || (d == 16) || (d==32))
+
+
+#define PM3_WAIT(n) \
+do{ \
+	while(PM3_READ_REG(PM3InFIFOSpace)<(n)); \
+} while(0)
+
+#define PM3_DELAY(x) do { \
+        int delay = x; \
+        unsigned char tmp; \
+        while(delay--){tmp = PM3_READ_REG(PM3InFIFOSpace);}; \
+} while(0)
+
+#define PM3_SLOW_WRITE_REG(r,v)	\
+do{                             \
+    DASSERT((l_fb_info->vIOBase != (unsigned char*)(-1)), "l_fb_info->vIOBase mapped in slow write\n"); \
+	mb();                   \
+	PM3_WAIT(1);            \
+	mb();                   \
+    PM3_WRITE_REG(r,v);     \
+} while(0)
+
+#define PM3_SET_INDEX(index) \
+do{ \
+	PM3_SLOW_WRITE_REG(PM3RD_IndexHigh,(((index)>>8)&0xff)); \
+	PM3_SLOW_WRITE_REG(PM3RD_IndexLow,((index)&0xff)); \
+} while(0)
+
+#define PM3_WRITE_DAC_REG(r, v) \
+do { \
+     DASSERT((l_fb_info->vIOBase != (unsigned char*)(-1)), "l_fb_info->vIOBase mapped in write dac reg\n"); \
+     PM3_SET_INDEX(r); \
+     mb(); \
+     PM3_WRITE_REG(PM3RD_IndexedData, v); \
+} while (0)
+
+/* next one is really a function, added as a macro to be consistent */
+#define PM3_READ_DAC_REG(r) pm3fb_read_dac_reg(l_fb_info, r)
+
+
+#define PM3_COLOR(c) \
+do { \
+  if (l_fb_info->current_par->depth == 8) \
+    { \
+      c = (c & 0xFF); \
+      c = c | (c << 8); \
+    } \
+  if ((l_fb_info->current_par->depth == 8) || (depth2bpp(l_fb_info->current_par->depth) == 16)) \
+    { \
+      c = (c & 0xFFFF); \
+      c = c | (c << 16); \
+    } \
+} while (0)
+
+#endif PM3FB_H
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/tridentfb.c linux/drivers/video/tridentfb.c
--- tmp/linux/drivers/video/tridentfb.c	Mon Feb 25 20:28:50 2002
+++ linux/drivers/video/tridentfb.c	Mon Feb 25 20:09:41 2002
@@ -3,7 +3,7 @@
  *
  * Copyright 2001,2002 - Jani Monoses   <jani@astechnix.ro>
  *
- * $Id: tridentfb.c,v 1.2 2002/02/13 17:44:14 marcelo Exp $
+ * $Id: tridentfb.c,v 1.3 2002/02/25 20:09:41 marcelo Exp $
  *
  * CREDITS:(in order of appearance)
  * 	skeletonfb.c by Geert Uytterhoeven and other fb code in drivers/video
@@ -35,7 +35,7 @@
 
 #include "tridentfb.h"
 
-#define VERSION		"0.6.8"
+#define VERSION		"0.6.9"
 
 struct tridentfb_par {
 	struct fb_var_screeninfo var;
@@ -520,9 +520,8 @@
 	write3X4(CRTHiOrd, (read3X4(CRTHiOrd) & 0xF8) | (base & 0xE0000) >> 17);
 }
 
-
-#error "Floating point maths. This needs fixing before the driver is safe"
-#define calc_freq(n,m,k) ((NTSC * (n+8))/((m+2)*(1<<k)))
+/* Use 20.12 fixed-point for NTSC value and frequency calculation */
+#define calc_freq(n,m,k)  ( (unsigned long)0xE517 * (n+8) / (m+2)*(1<<k) )
 
 /* Set dotclock frequency */
 static void set_vclk(int freq)
@@ -1260,8 +1259,8 @@
 	char * opt;
 	if (!options || !*options)
 		return 0;
-	for(opt = strtok(options,",");opt;opt = strtok(NULL,",")){
-		if (!opt) continue;
+	while((opt = strsep(&options,",")) != NULL ) {
+		if (!*opt) continue;
 		if (!strncmp(opt,"noaccel",7))
 			noaccel = 1;
 		else if (!strncmp(opt,"accel",5))
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/drivers/video/virgefb.c linux/drivers/video/virgefb.c
--- tmp/linux/drivers/video/virgefb.c	Wed Nov 14 22:52:20 2001
+++ linux/drivers/video/virgefb.c	Mon Feb 25 20:17:46 2002
@@ -670,12 +670,9 @@
  */
 
 #define Cyber3D_WaitQueue(v) \
-{ \
 	 do { \
 		while ((rl_3d(0x8504) & 0x1f00) < (((v)+2) << 8)); \
-	 } \
-	while (0); \
-}
+	 } while (0)
 
 static inline void Cyber3D_WaitBusy(void)
 {
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/binfmt_elf.c linux/fs/binfmt_elf.c
--- tmp/linux/fs/binfmt_elf.c	Mon Feb 25 20:28:51 2002
+++ linux/fs/binfmt_elf.c	Mon Feb 25 19:41:00 2002
@@ -564,6 +564,9 @@
 			// printk(KERN_WARNING "ELF: Ambiguous type, using ELF\n");
 			interpreter_type = INTERPRETER_ELF;
 		}
+	} else {
+		/* Executables without an interpreter also need a personality  */
+		SET_PERSONALITY(elf_ex, ibcs2_interpreter);
 	}
 
 	/* OK, we are done with that, now set up the arg stuff,
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/cramfs/README linux/fs/cramfs/README
--- tmp/linux/fs/cramfs/README	Thu Jul 19 23:14:53 2001
+++ linux/fs/cramfs/README	Mon Feb 25 20:01:04 2002
@@ -6,8 +6,8 @@
 swapped around (though it does care that directory entries (inodes) in
 a given directory are contiguous, as this is used by readdir).
 
-All data is in host-endian format; neither mkcramfs nor the kernel
-ever do swabbing.  (See section `Block Size' below.)
+All data is currently in host-endian format; neither mkcramfs nor the
+kernel ever do swabbing.  (See section `Block Size' below.)
 
 <filesystem>:
 	<superblock>
@@ -29,6 +29,10 @@
 lines); put another way, the same order as `find -type d -exec
 ls -AU1 {} \;'.
 
+Beginning in 2.4.7, directory entries are sorted.  This optimization
+allows cramfs_lookup to return more quickly when a filename does not
+exist, speeds up user-space directory sorts, etc.
+
 <data>:
 	One <file_data> for each file that's either a symlink or a
 	 regular file of non-zero st_size.
@@ -63,17 +67,15 @@
 This kernel supports cramfs holes (i.e. [efficient representation of]
 blocks in uncompressed data consisting entirely of NUL bytes), but by
 default mkcramfs doesn't test for & create holes, since cramfs in
-kernels up to at least 2.3.39 didn't support holes.  Compile mkcramfs
-with -DDO_HOLES if you want it to create files that can have holes in
-them.
+kernels up to at least 2.3.39 didn't support holes.  Run mkcramfs
+with -z if you want it to create files that can have holes in them.
 
 
 Tools
 -----
 
-If you're hacking on cramfs, you might find useful some tools for
-testing cramfs at <http://cvs.bofh.asn.au/cramfs/>, including a
-rudimentary fsck for cramfs.
+The cramfs user-space tools, including mkcramfs and cramfsck, are
+located at <http://sourceforge.net/projects/cramfs/>.
 
 
 Future Development
@@ -103,8 +105,8 @@
 PAGE_CACHE_SIZE (4096)' to `#include <asm/page.h>'.  The disadvantage
 is that the generated cramfs cannot always be shared between different
 kernels, not even necessarily kernels of the same architecture if
-PAGE_CACHE_SIZE is subject to change between kernel versions.
-
+PAGE_CACHE_SIZE is subject to change between kernel versions
+(currently possible with arm and ia64).
 
 The remaining options try to make cramfs more sharable.
 
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/cramfs/inode.c linux/fs/cramfs/inode.c
--- tmp/linux/fs/cramfs/inode.c	Mon Feb 25 20:28:51 2002
+++ linux/fs/cramfs/inode.c	Mon Feb 25 20:01:04 2002
@@ -116,7 +116,7 @@
 	unsigned i, blocknr, buffer, unread;
 	unsigned long devsize;
 	int major, minor;
-	
+
 	char *data;
 
 	if (!len)
@@ -186,7 +186,7 @@
 	}
 	return read_buffers[buffer] + offset;
 }
-			
+
 
 static struct super_block * cramfs_read_super(struct super_block *sb, void *data, int silent)
 {
@@ -268,7 +268,7 @@
 	buf->f_bavail = 0;
 	buf->f_files = sb->CRAMFS_SB_FILES;
 	buf->f_ffree = 0;
-	buf->f_namelen = 255;
+	buf->f_namelen = CRAMFS_MAXPATHLEN;
 	return 0;
 }
 
@@ -461,4 +461,3 @@
 module_init(init_cramfs_fs)
 module_exit(exit_cramfs_fs)
 MODULE_LICENSE("GPL");
-
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/hpfs/super.c linux/fs/hpfs/super.c
--- tmp/linux/fs/hpfs/super.c	Mon Feb 25 20:28:51 2002
+++ linux/fs/hpfs/super.c	Mon Feb 25 19:54:50 2002
@@ -410,6 +410,8 @@
 	/*s->s_hpfs_mounting = 1;*/
 	dev = s->s_dev;
 	set_blocksize(dev, 512);
+	s->s_blocksize = 512;
+	s->s_blocksize_bits = 9;
 	s->s_hpfs_fs_size = -1;
 	if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1;
 	if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2;
@@ -436,8 +438,6 @@
 
 	/* Fill superblock stuff */
 	s->s_magic = HPFS_SUPER_MAGIC;
-	s->s_blocksize = 512;
-	s->s_blocksize_bits = 9;
 	s->s_op = &hpfs_sops;
 
 	s->s_hpfs_root = superblock->root;
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/dir.c linux/fs/jffs2/dir.c
--- tmp/linux/fs/jffs2/dir.c	Mon Feb 25 20:28:51 2002
+++ linux/fs/jffs2/dir.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: dir.c,v 1.45 2001/12/27 22:43:20 dwmw2 Exp $
+ * $Id: dir.c,v 1.45.2.5 2002/02/23 14:31:09 dwmw2 Exp $
  *
  */
 
@@ -177,11 +177,11 @@
 		}
 		D2(printk(KERN_DEBUG "Dirent %ld: \"%s\", ino #%u, type %d\n", offset, fd->name, fd->ino, fd->type));
 		if (filldir(dirent, fd->name, strlen(fd->name), offset, fd->ino, fd->type) < 0)
-			goto out;
+			break;
 		offset++;
 	}
- out:
 	up(&f->sem);
+ out:
 	filp->f_pos = offset;
 	return 0;
 }
@@ -293,7 +293,7 @@
 	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
 
 	rd->pino = dir_i->i_ino;
-	rd->version = dir_f->highest_version++;
+	rd->version = ++dir_f->highest_version;
 	rd->ino = inode->i_ino;
 	rd->mctime = CURRENT_TIME;
 	rd->nsize = namelen;
@@ -304,16 +304,20 @@
 	fd = jffs2_write_dirent(dir_i, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
 
 	jffs2_complete_reservation(c);
-	jffs2_free_raw_dirent(rd);
 	
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 
 		   as if it were the final unlink() */
+		jffs2_free_raw_dirent(rd);
 		up(&dir_f->sem);
 		jffs2_clear_inode(inode);
 		return PTR_ERR(fd);
 	}
 
+	dir_i->i_mtime = dir_i->i_ctime = rd->mctime;
+
+	jffs2_free_raw_dirent(rd);
+
 	/* Link the fd into the inode's list, obsoleting an old
 	   one if necessary. */
 	jffs2_add_fd_to_list(c, fd, &dir_f->dents);
@@ -359,7 +363,7 @@
 	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
 
 	rd->pino = dir_i->i_ino;
-	rd->version = dir_f->highest_version++;
+	rd->version = ++dir_f->highest_version;
 	rd->ino = 0;
 	rd->mctime = CURRENT_TIME;
 	rd->nsize = dentry->d_name.len;
@@ -446,7 +450,7 @@
 	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
 
 	rd->pino = dir_i->i_ino;
-	rd->version = dir_f->highest_version++;
+	rd->version = ++dir_f->highest_version;
 	rd->ino = old_dentry->d_inode->i_ino;
 	rd->mctime = CURRENT_TIME;
 	rd->nsize = dentry->d_name.len;
@@ -483,7 +487,12 @@
 
 static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct dentry *dentry)
 {
-	int ret = jffs2_do_link(old_dentry, dir_i, dentry, 0);
+	int ret;
+
+	if (S_ISDIR(old_dentry->d_inode->i_mode))
+		return -EPERM;
+
+	ret = jffs2_do_link(old_dentry, dir_i, dentry, 0);
 	if (!ret) {
 		d_instantiate(dentry, old_dentry->d_inode);
 		atomic_inc(&old_dentry->d_inode->i_count);
@@ -600,7 +609,7 @@
 	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
 
 	rd->pino = dir_i->i_ino;
-	rd->version = dir_f->highest_version++;
+	rd->version = ++dir_f->highest_version;
 	rd->ino = inode->i_ino;
 	rd->mctime = CURRENT_TIME;
 	rd->nsize = namelen;
@@ -611,16 +620,20 @@
 	fd = jffs2_write_dirent(dir_i, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
 	
 	jffs2_complete_reservation(c);
-	jffs2_free_raw_dirent(rd);
 	
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 
 		   as if it were the final unlink() */
+		jffs2_free_raw_dirent(rd);
 		up(&dir_f->sem);
 		jffs2_clear_inode(inode);
 		return PTR_ERR(fd);
 	}
 
+	dir_i->i_mtime = dir_i->i_ctime = rd->mctime;
+
+	jffs2_free_raw_dirent(rd);
+
 	/* Link the fd into the inode's list, obsoleting an old
 	   one if necessary. */
 	jffs2_add_fd_to_list(c, fd, &dir_f->dents);
@@ -730,7 +743,7 @@
 	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
 
 	rd->pino = dir_i->i_ino;
-	rd->version = dir_f->highest_version++;
+	rd->version = ++dir_f->highest_version;
 	rd->ino = inode->i_ino;
 	rd->mctime = CURRENT_TIME;
 	rd->nsize = namelen;
@@ -741,16 +754,20 @@
 	fd = jffs2_write_dirent(dir_i, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
 	
 	jffs2_complete_reservation(c);
-	jffs2_free_raw_dirent(rd);
 	
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 
 		   as if it were the final unlink() */
+		jffs2_free_raw_dirent(rd);
 		up(&dir_f->sem);
 		jffs2_clear_inode(inode);
 		return PTR_ERR(fd);
 	}
 
+	dir_i->i_mtime = dir_i->i_ctime = rd->mctime;
+
+	jffs2_free_raw_dirent(rd);
+
 	/* Link the fd into the inode's list, obsoleting an old
 	   one if necessary. */
 	jffs2_add_fd_to_list(c, fd, &dir_f->dents);
@@ -794,8 +811,7 @@
 	
 	c = JFFS2_SB_INFO(dir_i->i_sb);
 	
-	if ((mode & S_IFMT) == S_IFBLK ||
-	    (mode & S_IFMT) == S_IFCHR) {
+	if (S_ISBLK(mode) || S_ISCHR(mode)) {
 		dev = (MAJOR(to_kdev_t(rdev)) << 8) | MINOR(to_kdev_t(rdev));
 		devlen = sizeof(dev);
 	}
@@ -881,7 +897,7 @@
 	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
 
 	rd->pino = dir_i->i_ino;
-	rd->version = dir_f->highest_version++;
+	rd->version = ++dir_f->highest_version;
 	rd->ino = inode->i_ino;
 	rd->mctime = CURRENT_TIME;
 	rd->nsize = namelen;
@@ -895,22 +911,27 @@
 	fd = jffs2_write_dirent(dir_i, rd, dentry->d_name.name, namelen, phys_ofs, &writtenlen);
 	
 	jffs2_complete_reservation(c);
-	jffs2_free_raw_dirent(rd);
 	
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally 
 		   as if it were the final unlink() */
+		jffs2_free_raw_dirent(rd);
 		up(&dir_f->sem);
 		jffs2_clear_inode(inode);
 		return PTR_ERR(fd);
 	}
 
+	dir_i->i_mtime = dir_i->i_ctime = rd->mctime;
+
+	jffs2_free_raw_dirent(rd);
+
 	/* Link the fd into the inode's list, obsoleting an old
 	   one if necessary. */
 	jffs2_add_fd_to_list(c, fd, &dir_f->dents);
 	up(&dir_f->sem);
 
 	d_instantiate(dentry, inode);
+
 	return 0;
 }
 
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/erase.c linux/fs/jffs2/erase.c
--- tmp/linux/fs/jffs2/erase.c	Thu Oct  4 22:13:18 2001
+++ linux/fs/jffs2/erase.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: erase.c,v 1.23 2001/09/19 21:51:11 dwmw2 Exp $
+ * $Id: erase.c,v 1.24 2001/12/06 16:38:38 dwmw2 Exp $
  *
  */
 #include <linux/kernel.h>
@@ -215,8 +215,8 @@
 
 	D2({
 		int i=0;
-        struct jffs2_raw_node_ref *this;		
-        printk(KERN_DEBUG "After remove_node_refs_from_ino_list: \n" KERN_DEBUG);
+		struct jffs2_raw_node_ref *this;
+		printk(KERN_DEBUG "After remove_node_refs_from_ino_list: \n" KERN_DEBUG);
 
 		this = ic->nodes;
 	   
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/file.c linux/fs/jffs2/file.c
--- tmp/linux/fs/jffs2/file.c	Thu Oct  4 22:13:18 2001
+++ linux/fs/jffs2/file.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: file.c,v 1.58 2001/09/20 15:28:31 dwmw2 Exp $
+ * $Id: file.c,v 1.58.2.1 2002/02/23 14:25:36 dwmw2 Exp $
  *
  */
 
@@ -102,15 +102,14 @@
 	   must read the original data associated with the node
 	   (i.e. the device numbers or the target name) and write
 	   it out again with the appropriate data attached */
-	if ((inode->i_mode & S_IFMT) == S_IFBLK ||
-	    (inode->i_mode & S_IFMT) == S_IFCHR) {
+	if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
 		/* For these, we don't actually need to read the old node */
 		dev =  (MAJOR(to_kdev_t(dentry->d_inode->i_rdev)) << 8) | 
 			MINOR(to_kdev_t(dentry->d_inode->i_rdev));
 		mdata = (char *)&dev;
 		mdatalen = sizeof(dev);
 		D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen));
-	} else if ((inode->i_mode & S_IFMT) == S_IFLNK) {
+	} else if (S_ISLNK(inode->i_mode)) {
 		mdatalen = f->metadata->size;
 		mdata = kmalloc(f->metadata->size, GFP_USER);
 		if (!mdata)
@@ -125,7 +124,7 @@
 
 	ri = jffs2_alloc_raw_inode();
 	if (!ri) {
-		if ((inode->i_mode & S_IFMT) == S_IFLNK)
+		if (S_ISLNK(inode->i_mode))
 			kfree(mdata);
 		return -ENOMEM;
 	}
@@ -133,7 +132,7 @@
 	ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &phys_ofs, &alloclen, ALLOC_NORMAL);
 	if (ret) {
 		jffs2_free_raw_inode(ri);
-		if ((inode->i_mode & S_IFMT) == S_IFLNK)
+		if (S_ISLNK(inode->i_mode))
 			 kfree(mdata);
 		return ret;
 	}
@@ -177,7 +176,7 @@
 		ri->data_crc = 0;
 
 	new_metadata = jffs2_write_dnode(inode, ri, mdata, mdatalen, phys_ofs, NULL);
-	if ((inode->i_mode & S_IFMT) == S_IFLNK)
+	if (S_ISLNK(inode->i_mode))
 		kfree(mdata);
 
 	jffs2_complete_reservation(c);
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/gc.c linux/fs/jffs2/gc.c
--- tmp/linux/fs/jffs2/gc.c	Thu Oct  4 22:13:18 2001
+++ linux/fs/jffs2/gc.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: gc.c,v 1.52 2001/09/19 21:53:47 dwmw2 Exp $
+ * $Id: gc.c,v 1.52.2.2 2002/02/23 14:25:36 dwmw2 Exp $
  *
  */
 
@@ -266,15 +266,14 @@
 	__u32 alloclen, phys_ofs;
 	int ret;
 
-	if ((inode->i_mode & S_IFMT) == S_IFBLK ||
-	    (inode->i_mode & S_IFMT) == S_IFCHR) {
+	if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
 		/* For these, we don't actually need to read the old node */
 		dev =  (MAJOR(to_kdev_t(inode->i_rdev)) << 8) | 
 			MINOR(to_kdev_t(inode->i_rdev));
 		mdata = (char *)&dev;
 		mdatalen = sizeof(dev);
 		D1(printk(KERN_DEBUG "jffs2_garbage_collect_metadata(): Writing %d bytes of kdev_t\n", mdatalen));
-	} else if ((inode->i_mode & S_IFMT) == S_IFLNK) {
+	} else if (S_ISLNK(inode->i_mode)) {
 		mdatalen = fn->size;
 		mdata = kmalloc(fn->size, GFP_KERNEL);
 		if (!mdata) {
@@ -331,7 +330,7 @@
 	jffs2_free_full_dnode(fn);
 	f->metadata = new_fn;
  out:
-	if ((inode->i_mode & S_IFMT) == S_IFLNK)
+	if (S_ISLNK(inode->i_mode))
 		kfree(mdata);
 	return ret;
 }
@@ -466,8 +465,8 @@
 		ri.ino = inode->i_ino;
 		ri.version = ++f->highest_version;
 		ri.offset = start;
-		ri.csize = end - start;
-		ri.dsize = 0;
+		ri.dsize = end - start;
+		ri.csize = 0;
 		ri.compr = JFFS2_COMPR_ZERO;
 	}
 	ri.mode = inode->i_mode;
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/nodelist.c linux/fs/jffs2/nodelist.c
--- tmp/linux/fs/jffs2/nodelist.c	Wed Nov 14 16:19:40 2001
+++ linux/fs/jffs2/nodelist.c	Mon Feb 25 19:21:59 2002
@@ -1,7 +1,7 @@
 /*
  * JFFS2 -- Journalling Flash File System, Version 2.
  *
- * Copyright (C) 2001 Red Hat, Inc.
+ * Copyright (C) 2001, 2002 Red Hat, Inc.
  *
  * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
  *
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: nodelist.c,v 1.30 2001/11/14 10:35:21 dwmw2 Exp $
+ * $Id: nodelist.c,v 1.30.2.3 2002/02/23 14:04:44 dwmw2 Exp $
  *
  */
 
@@ -94,7 +94,8 @@
 
 int jffs2_get_inode_nodes(struct jffs2_sb_info *c, ino_t ino, struct jffs2_inode_info *f,
 			  struct jffs2_tmp_dnode_info **tnp, struct jffs2_full_dirent **fdp,
-			  __u32 *highest_version)
+			  __u32 *highest_version, __u32 *latest_mctime,
+			  __u32 *mctime_ver)
 {
 	struct jffs2_raw_node_ref *ref = f->inocache->nodes;
 	struct jffs2_tmp_dnode_info *tn, *ret_tn = NULL;
@@ -104,6 +105,8 @@
 	size_t retlen;
 	int err;
 
+	*mctime_ver = 0;
+
 	D1(printk(KERN_DEBUG "jffs2_get_inode_nodes(): ino #%lu\n", ino));
 	if (!f->inocache->nodes) {
 		printk(KERN_WARNING "Eep. no nodes for ino #%lu\n", ino);
@@ -115,7 +118,7 @@
 			D1(printk(KERN_DEBUG "node at 0x%08x is obsoleted. Ignoring.\n", ref->flash_offset &~3));
 			continue;
 		}
-		err = c->mtd->read(c->mtd, (ref->flash_offset & ~3), sizeof(node), &retlen, (void *)&node);
+		err = c->mtd->read(c->mtd, (ref->flash_offset & ~3), min(ref->totlen, sizeof(node)), &retlen, (void *)&node);
 		if (err) {
 			printk(KERN_WARNING "error %d reading node at 0x%08x in get_inode_nodes()\n", err, (ref->flash_offset) & ~3);
 			goto free_out;
@@ -123,7 +126,7 @@
 			
 
 			/* Check we've managed to read at least the common node header */
-		if (retlen < sizeof(node.u)) {
+		if (retlen < min(ref->totlen, sizeof(node.u))) {
 			printk(KERN_WARNING "short read in get_inode_nodes()\n");
 			err = -EIO;
 			goto free_out;
@@ -153,15 +156,22 @@
 			fd->version = node.d.version;
 			fd->ino = node.d.ino;
 			fd->type = node.d.type;
-				/* memcpy as much of the name as possible from the raw
-				   dirent we've already read from the flash
-				*/
+
+			/* Pick out the mctime of the latest dirent */
+			if(fd->version > *mctime_ver) {
+				*mctime_ver = fd->version;
+				*latest_mctime = node.d.mctime;
+			}
+
+			/* memcpy as much of the name as possible from the raw
+			   dirent we've already read from the flash
+			*/
 			if (retlen > sizeof(struct jffs2_raw_dirent))
 				memcpy(&fd->name[0], &node.d.name[0], min((__u32)node.d.nsize, (retlen-sizeof(struct jffs2_raw_dirent))));
 				
-				/* Do we need to copy any more of the name directly
-				   from the flash?
-				*/
+			/* Do we need to copy any more of the name directly
+			   from the flash?
+			*/
 			if (node.d.nsize + sizeof(struct jffs2_raw_dirent) > retlen) {
 				int already = retlen - sizeof(struct jffs2_raw_dirent);
 					
@@ -217,7 +227,12 @@
 			}
 			tn->version = node.i.version;
 			tn->fn->ofs = node.i.offset;
-			tn->fn->size = node.i.dsize;
+			/* There was a bug where we wrote hole nodes out with
+			   csize/dsize swapped. Deal with it */
+			if (node.i.compr == JFFS2_COMPR_ZERO && !node.i.dsize && node.i.csize)
+				tn->fn->size = node.i.csize;
+			else // normal case...
+				tn->fn->size = node.i.dsize;
 			tn->fn->raw = ref;
 			D1(printk(KERN_DEBUG "dnode @%08x: ver %u, offset %04x, dsize %04x\n", ref->flash_offset &~3, node.i.version, node.i.offset, node.i.dsize));
 			jffs2_add_tn_to_list(tn, &ret_tn);
@@ -242,6 +257,7 @@
 	}
 	*tnp = ret_tn;
 	*fdp = ret_fd;
+
 	return 0;
 
  free_out:
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/nodelist.h linux/fs/jffs2/nodelist.h
--- tmp/linux/fs/jffs2/nodelist.h	Thu Oct  4 22:13:18 2001
+++ linux/fs/jffs2/nodelist.h	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: nodelist.h,v 1.46 2001/09/18 23:43:05 dwmw2 Exp $
+ * $Id: nodelist.h,v 1.46.2.1 2002/02/23 14:04:44 dwmw2 Exp $
  *
  */
 
@@ -248,7 +248,8 @@
 void jffs2_add_tn_to_list(struct jffs2_tmp_dnode_info *tn, struct jffs2_tmp_dnode_info **list);
 int jffs2_get_inode_nodes(struct jffs2_sb_info *c, ino_t ino, struct jffs2_inode_info *f,
 			  struct jffs2_tmp_dnode_info **tnp, struct jffs2_full_dirent **fdp,
-			  __u32 *highest_version);
+			  __u32 *highest_version, __u32 *latest_mctime,
+			  __u32 *mctime_ver);
 struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, int ino);
 void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new);
 void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old);
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/nodemgmt.c linux/fs/jffs2/nodemgmt.c
--- tmp/linux/fs/jffs2/nodemgmt.c	Thu Oct  4 22:13:18 2001
+++ linux/fs/jffs2/nodemgmt.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: nodemgmt.c,v 1.45 2001/09/20 08:05:05 dwmw2 Exp $
+ * $Id: nodemgmt.c,v 1.45.2.1 2002/02/23 14:13:34 dwmw2 Exp $
  *
  */
 
@@ -319,6 +319,15 @@
 
 	ACCT_PARANOIA_CHECK(jeb);
 
+	if (c->flags & JFFS2_SB_FLAG_MOUNTING) {
+		/* Mount in progress. Don't muck about with the block
+		   lists because they're not ready yet, and don't actually
+		   obliterate nodes that look obsolete. If they weren't 
+		   marked obsolete on the flash at the time they _became_
+		   obsolete, there was probably a reason for that. */
+		spin_unlock_bh(&c->erase_completion_lock);
+		return;
+	}
 	if (jeb == c->nextblock) {
 		D2(printk(KERN_DEBUG "Not moving nextblock 0x%08x to dirty/erase_pending list\n", jeb->offset));
 	} else if (jeb == c->gcblock) {
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/read.c linux/fs/jffs2/read.c
--- tmp/linux/fs/jffs2/read.c	Fri Sep 14 21:04:07 2001
+++ linux/fs/jffs2/read.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: read.c,v 1.13 2001/05/01 16:24:44 dwmw2 Exp $
+ * $Id: read.c,v 1.13.2.1 2002/02/01 23:32:33 dwmw2 Exp $
  *
  */
 
@@ -74,6 +74,12 @@
 		printk(KERN_WARNING "Node CRC %08x != calculated CRC %08x for node at %08x\n", ri->node_crc, crc, fd->raw->flash_offset & ~3);
 		ret = -EIO;
 		goto out_ri;
+	}
+	/* There was a bug where we wrote hole nodes out with csize/dsize
+	   swapped. Deal with it */
+	if (ri->compr == JFFS2_COMPR_ZERO && !ri->dsize && ri->csize) {
+		ri->dsize = ri->csize;
+		ri->csize = 0;
 	}
 
 	D1(if(ofs + len > ri->dsize) {
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/readinode.c linux/fs/jffs2/readinode.c
--- tmp/linux/fs/jffs2/readinode.c	Mon Feb 25 20:28:51 2002
+++ linux/fs/jffs2/readinode.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: readinode.c,v 1.57 2001/12/27 22:49:46 dwmw2 Exp $
+ * $Id: readinode.c,v 1.58.2.2 2002/02/23 14:25:37 dwmw2 Exp $
  *
  */
 
@@ -173,12 +173,12 @@
 				jffs2_free_node_frag(newfrag);
 				return -ENOMEM;
 			}
-			printk(KERN_DEBUG "split old frag 0x%04x-0x%04x -->", this->ofs, this->ofs+this->size);
+			D1(printk(KERN_DEBUG "split old frag 0x%04x-0x%04x -->", this->ofs, this->ofs+this->size);
 			if (this->node)
 				printk("phys 0x%08x\n", this->node->raw->flash_offset &~3);
 			else 
 				printk("hole\n");
-
+			   )
 			newfrag2->ofs = fn->ofs + fn->size;
 			newfrag2->size = (this->ofs+this->size) - newfrag2->ofs;
 			newfrag2->next = this->next;
@@ -251,6 +251,7 @@
 	struct jffs2_full_dnode *fn = NULL;
 	struct jffs2_sb_info *c;
 	struct jffs2_raw_inode latest_node;
+	__u32 latest_mctime, mctime_ver;
 	int ret;
 	ssize_t retlen;
 
@@ -288,7 +289,7 @@
 	inode->i_nlink = f->inocache->nlink;
 
 	/* Grab all nodes relevant to this ino */
-	ret = jffs2_get_inode_nodes(c, inode->i_ino, f, &tn_list, &fd_list, &f->highest_version);
+	ret = jffs2_get_inode_nodes(c, inode->i_ino, f, &tn_list, &fd_list, &f->highest_version, &latest_mctime, &mctime_ver);
 
 	if (ret) {
 		printk(KERN_CRIT "jffs2_get_inode_nodes() for ino %lu returned %d\n", inode->i_ino, ret);
@@ -335,6 +336,7 @@
 			printk(KERN_WARNING "jffs2_read_inode(): But it has children so we fake some modes for it\n");
 		}
 		inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO;
+		latest_node.version = 0;
 		inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
 		inode->i_nlink = f->inocache->nlink;
 		inode->i_size = 0;
@@ -362,7 +364,7 @@
 		inode->i_uid = latest_node.uid;
 		inode->i_gid = latest_node.gid;
 		inode->i_size = latest_node.isize;
-		if ((inode->i_mode & S_IFMT) == S_IFREG)
+		if (S_ISREG(inode->i_mode))
 			jffs2_truncate_fraglist(c, &f->fraglist, latest_node.isize);
 		inode->i_atime = latest_node.atime;
 		inode->i_mtime = latest_node.mtime;
@@ -372,9 +374,8 @@
 	/* OK, now the special cases. Certain inode types should
 	   have only one data node, and it's kept as the metadata
 	   node */
-	if ((inode->i_mode & S_IFMT) == S_IFBLK ||
-	    (inode->i_mode & S_IFMT) == S_IFCHR ||
-	    (inode->i_mode & S_IFMT) == S_IFLNK) {
+	if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode) ||
+	    S_ISLNK(inode->i_mode)) {
 		if (f->metadata) {
 			printk(KERN_WARNING "Argh. Special inode #%lu with mode 0%o had metadata node\n", inode->i_ino, inode->i_mode);
 			jffs2_clear_inode(inode);
@@ -389,7 +390,8 @@
 		}
 		/* ASSERT: f->fraglist != NULL */
 		if (f->fraglist->next) {
-			printk(KERN_WARNING "Argh. Special inode #%lu had more than one node\n", inode->i_ino);
+			printk(KERN_WARNING "Argh. Special inode #%lu with mode 0%o had more than one node\n", inode->i_ino, inode->i_mode);
+			/* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */
 			jffs2_clear_inode(inode);
 			make_bad_inode(inode);
 			return;
@@ -417,6 +419,12 @@
 		break;
 		
 	case S_IFDIR:
+		if (mctime_ver > latest_node.version) {
+			/* The times in the latest_node are actually older than
+			   mctime in the latest dirent. Cheat. */
+			inode->i_mtime = inode->i_ctime = inode->i_atime = 
+				latest_mctime;
+		}
 		inode->i_op = &jffs2_dir_inode_operations;
 		inode->i_fop = &jffs2_dir_operations;
 		break;
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/scan.c linux/fs/jffs2/scan.c
--- tmp/linux/fs/jffs2/scan.c	Thu Oct  4 22:13:18 2001
+++ linux/fs/jffs2/scan.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: scan.c,v 1.51 2001/09/19 00:06:35 dwmw2 Exp $
+ * $Id: scan.c,v 1.51.2.2 2002/02/23 13:34:31 dwmw2 Exp $
  *
  */
 #include <linux/kernel.h>
@@ -62,6 +62,9 @@
 	} \
 } while(0)
 
+static uint32_t pseudo_random;
+static void jffs2_rotate_lists(struct jffs2_sb_info *c);
+
 static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
 
 /* These helper functions _must_ increase ofs and also do the dirty/used space accounting. 
@@ -142,6 +145,9 @@
 			c->nr_erasing_blocks++;
 		}
 	}
+	/* Rotate the lists by some number to ensure wear levelling */
+	jffs2_rotate_lists(c);
+
 	if (c->nr_erasing_blocks) {
 		if (!c->used_size && empty_blocks != c->nr_blocks) {
 			printk(KERN_NOTICE "Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n");
@@ -444,6 +450,12 @@
 		*ofs += 4;
 		return 0;
 	}
+	/* There was a bug where we wrote hole nodes out with csize/dsize
+	   swapped. Deal with it */
+	if (ri.compr == JFFS2_COMPR_ZERO && !ri.dsize && ri.csize) {
+		ri.dsize = ri.csize;
+		ri.csize = 0;
+	}
 
 	if (ri.csize) {
 		/* Check data CRC too */
@@ -474,7 +486,7 @@
 			       *ofs, ri.data_crc, crc);
 			DIRTY_SPACE(PAD(ri.totlen));
 			*ofs += PAD(ri.totlen);
-			return -0;
+			return 0;
 		}
 	}
 
@@ -518,6 +530,8 @@
 	D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n", 
 		  ri.ino, ri.version, ri.offset, ri.offset+ri.dsize));
 
+	pseudo_random += ri.version;
+
 	for (tn_list = &ic->scan->tmpnodes; *tn_list; tn_list = &((*tn_list)->next)) {
 		if ((*tn_list)->version < ri.version)
 			continue;
@@ -613,6 +627,8 @@
 		return 0;
 	}
 
+	pseudo_random += rd.version;
+
 	fd = jffs2_alloc_full_dirent(rd.nsize+1);
 	if (!fd) {
 		return -ENOMEM;
@@ -685,4 +701,46 @@
 	} 
 	*ofs += PAD(rd.totlen);
 	return 0;
+}
+
+static int count_list(struct list_head *l)
+{
+	uint32_t count = 0;
+	struct list_head *tmp;
+
+	list_for_each(tmp, l) {
+		count++;
+	}
+	return count;
+}
+
+/* Note: This breaks if list_empty(head). I don't care. You
+   might, if you copy this code and use it elsewhere :) */
+static void rotate_list(struct list_head *head, uint32_t count)
+{
+	struct list_head *n = head->next;
+
+	list_del(head);
+	while(count--)
+		n = n->next;
+	list_add(head, n);
+}
+
+static void jffs2_rotate_lists(struct jffs2_sb_info *c)
+{
+	uint32_t x;
+
+	x = count_list(&c->clean_list);
+	if (x)
+		rotate_list((&c->clean_list), pseudo_random % x);
+
+	x = count_list(&c->dirty_list);
+	if (x)
+		rotate_list((&c->dirty_list), pseudo_random % x);
+
+	if (c->nr_erasing_blocks)
+		rotate_list((&c->erase_pending_list), pseudo_random % c->nr_erasing_blocks);
+
+	if (c->nr_free_blocks) /* Not that it should ever be zero */
+		rotate_list((&c->free_list), pseudo_random % c->nr_free_blocks);
 }
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/super.c linux/fs/jffs2/super.c
--- tmp/linux/fs/jffs2/super.c	Thu Oct  4 22:14:35 2001
+++ linux/fs/jffs2/super.c	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: super.c,v 1.48 2001/10/02 09:16:23 dwmw2 Exp $
+ * $Id: super.c,v 1.48.2.1 2002/02/23 14:13:34 dwmw2 Exp $
  *
  */
 
@@ -245,10 +245,15 @@
 	INIT_LIST_HEAD(&c->bad_used_list);
 	c->highest_ino = 1;
 
+	c->flags |= JFFS2_SB_FLAG_MOUNTING;
+
 	if (jffs2_build_filesystem(c)) {
 		D1(printk(KERN_DEBUG "build_fs failed\n"));
 		goto out_nodes;
 	}
+
+	c->flags &= ~JFFS2_SB_FLAG_MOUNTING;
+
 	sb->s_op = &jffs2_super_operations;
 
 	D1(printk(KERN_DEBUG "jffs2_read_super(): Getting root inode\n"));
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/fs/jffs2/symlink.c linux/fs/jffs2/symlink.c
--- tmp/linux/fs/jffs2/symlink.c	Fri Sep 14 21:04:07 2001
+++ linux/fs/jffs2/symlink.c	Mon Feb 25 19:21:59 2002
@@ -1,7 +1,7 @@
 /*
  * JFFS2 -- Journalling Flash File System, Version 2.
  *
- * Copyright (C) 2001 Red Hat, Inc.
+ * Copyright (C) 2001, 2002 Red Hat, Inc.
  *
  * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
  *
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: symlink.c,v 1.5 2001/03/15 15:38:24 dwmw2 Exp $
+ * $Id: symlink.c,v 1.5.2.1 2002/01/15 10:39:06 dwmw2 Exp $
  *
  */
 
@@ -58,16 +58,21 @@
 	char *buf;
 	int ret;
 
+	down(&f->sem);
 	if (!f->metadata) {
+		up(&f->sem);
 		printk(KERN_NOTICE "No metadata for symlink inode #%lu\n", dentry->d_inode->i_ino);
 		return ERR_PTR(-EINVAL);
 	}
 	buf = kmalloc(f->metadata->size+1, GFP_USER);
-	if (!buf)
+	if (!buf) {
+		up(&f->sem);
 		return ERR_PTR(-ENOMEM);
+	}
 	buf[f->metadata->size]=0;
 
 	ret = jffs2_read_dnode(JFFS2_SB_INFO(dentry->d_inode->i_sb), f->metadata, buf, 0, f->metadata->size);
+	up(&f->sem);
 	if (ret) {
 		kfree(buf);
 		return ERR_PTR(ret);
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/asm-alpha/jensen.h linux/include/asm-alpha/jensen.h
--- tmp/linux/include/asm-alpha/jensen.h	Fri Nov  9 21:45:35 2001
+++ linux/include/asm-alpha/jensen.h	Mon Feb 25 19:44:21 2002
@@ -8,7 +8,7 @@
  */
 
 /* The Jensen is strange */
-#define AUX_IRQ (9)
+/* #define AUX_IRQ (9) *//* done in keyboard.h now */
 
 /*
  * NOTE! The memory operations do not set any memory barriers, as it's
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/asm-alpha/keyboard.h linux/include/asm-alpha/keyboard.h
--- tmp/linux/include/asm-alpha/keyboard.h	Thu Sep 13 22:21:32 2001
+++ linux/include/asm-alpha/keyboard.h	Mon Feb 25 19:44:21 2002
@@ -60,7 +60,7 @@
  * Machine specific bits for the PS/2 driver
  */
 
-#define AUX_IRQ 12
+#define AUX_IRQ ((RTC_PORT(0) == 0x170) ? 9 : 12) /* for JENSEN 9, others 12 */
 
 #define aux_request_irq(hand, dev_id)                                  \
        request_irq(AUX_IRQ, hand, SA_SHIRQ, "PS/2 Mouse", dev_id)
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/blkdev.h linux/include/linux/blkdev.h
--- tmp/linux/include/linux/blkdev.h	Mon Nov 26 13:29:17 2001
+++ linux/include/linux/blkdev.h	Mon Feb 25 19:55:43 2002
@@ -119,9 +119,9 @@
 	spinlock_t		queue_lock;
 
 	/*
-	 * Tasks wait here for free request
+	 * Tasks wait here for free read and write requests
 	 */
-	wait_queue_head_t	wait_for_request;
+	wait_queue_head_t	wait_for_requests[2];
 };
 
 struct blk_dev_struct {
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/cramfs_fs.h linux/include/linux/cramfs_fs.h
--- tmp/linux/include/linux/cramfs_fs.h	Thu Jul 19 23:14:53 2001
+++ linux/include/linux/cramfs_fs.h	Mon Feb 25 20:01:04 2002
@@ -24,6 +24,12 @@
 #define CRAMFS_OFFSET_WIDTH 26
 
 /*
+ * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
+ * path length is 63 << 2 = 252.
+ */
+#define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
+
+/*
  * Reasonably terse representation of the inode data.
  */
 struct cramfs_inode {
@@ -52,14 +58,14 @@
  * Superblock information at the beginning of the FS.
  */
 struct cramfs_super {
-	u32 magic;		/* 0x28cd3d45 - random number */
-	u32 size;		/* length in bytes */
-	u32 flags;		/* 0 */
-	u32 future;		/* 0 */
-	u8 signature[16];	/* "Compressed ROMFS" */
+	u32 magic;			/* 0x28cd3d45 - random number */
+	u32 size;			/* length in bytes */
+	u32 flags;			/* feature flags */
+	u32 future;			/* reserved for future use */
+	u8 signature[16];		/* "Compressed ROMFS" */
 	struct cramfs_info fsid;	/* unique filesystem info */
-	u8 name[16];		/* user-defined name */
-	struct cramfs_inode root;	/* Root inode data */
+	u8 name[16];			/* user-defined name */
+	struct cramfs_inode root;	/* root inode data */
 };
 
 /*
@@ -79,7 +85,10 @@
  * if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be
  * changed to test super.future instead.
  */
-#define CRAMFS_SUPPORTED_FLAGS (0x7ff)
+#define CRAMFS_SUPPORTED_FLAGS	( 0x000000ff \
+				| CRAMFS_FLAG_HOLES \
+				| CRAMFS_FLAG_WRONG_SIGNATURE \
+				| CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
 
 /* Uncompression interfaces to the underlying zlib */
 int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/fb.h linux/include/linux/fb.h
--- tmp/linux/include/linux/fb.h	Mon Dec 11 21:16:53 2000
+++ linux/include/linux/fb.h	Mon Feb 25 19:11:07 2002
@@ -93,6 +93,7 @@
 #define FB_ACCEL_IGS_CYBER2010	34	/* CyberPro 2010		*/
 #define FB_ACCEL_IGS_CYBER5000	35	/* CyberPro 5000		*/
 #define FB_ACCEL_SIS_GLAMOUR    36	/* SiS 300/630/540              */
+#define FB_ACCEL_3DLABS_PERMEDIA3 37	/* 3Dlabs Permedia 3		*/
 
 struct fb_fix_screeninfo {
 	char id[16];			/* identification string eg "TT Builtin" */
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/jffs2.h linux/include/linux/jffs2.h
--- tmp/linux/include/linux/jffs2.h	Fri Sep 14 21:04:07 2001
+++ linux/include/linux/jffs2.h	Mon Feb 25 19:21:59 2002
@@ -31,7 +31,7 @@
  * provisions above, a recipient may use your version of this file
  * under either the RHEPL or the GPL.
  *
- * $Id: jffs2.h,v 1.18 2001/03/25 22:36:12 dwmw2 Exp $
+ * $Id: jffs2.h,v 1.19 2001/10/09 13:20:23 dwmw2 Exp $
  *
  */
 
@@ -103,7 +103,7 @@
 	__u16 nodetype;
 	__u32 totlen; /* So we can skip over nodes we don't grok */
 	__u32 hdr_crc;
-};
+} __attribute__((packed));
 
 struct jffs2_raw_dirent
 {
@@ -121,7 +121,7 @@
 	__u32 node_crc;
 	__u32 name_crc;
 	__u8 name[0];
-};
+} __attribute__((packed));
 
 /* The JFFS2 raw inode structure: Used for storage on physical media.  */
 /* The uid, gid, atime, mtime and ctime members could be longer, but 
@@ -153,7 +153,7 @@
 	__u32 data_crc;   /* CRC for the (compressed) data.  */
 	__u32 node_crc;   /* CRC for the raw inode (excluding data)  */
 //	__u8 data[dsize];
-};
+} __attribute__((packed));
 
 union jffs2_node_union {
 	struct jffs2_raw_inode i;
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/jffs2_fs_sb.h linux/include/linux/jffs2_fs_sb.h
--- tmp/linux/include/linux/jffs2_fs_sb.h	Thu Nov 22 19:46:19 2001
+++ linux/include/linux/jffs2_fs_sb.h	Mon Feb 25 19:21:59 2002
@@ -1,4 +1,4 @@
-/* $Id: jffs2_fs_sb.h,v 1.16 2001/09/18 20:15:18 dwmw2 Exp $ */
+/* $Id: jffs2_fs_sb.h,v 1.16.2.1 2002/02/23 14:13:34 dwmw2 Exp $ */
 
 #ifndef _JFFS2_FS_SB
 #define _JFFS2_FS_SB
@@ -12,6 +12,7 @@
 #define INOCACHE_HASHSIZE 1
 
 #define JFFS2_SB_FLAG_RO 1
+#define JFFS2_SB_FLAG_MOUNTING 2
 
 /* A struct for the overall file system control.  Pointers to
    jffs2_sb_info structs are named `c' in the source code.  
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/nbd.h linux/include/linux/nbd.h
--- tmp/linux/include/linux/nbd.h	Tue Oct 16 02:29:05 2001
+++ linux/include/linux/nbd.h	Mon Feb 25 19:21:59 2002
@@ -68,8 +68,9 @@
 	struct socket * sock;
 	struct file * file; 		/* If == NULL, device is not ready, yet	*/
 	int magic;			/* FIXME: not if debugging is off	*/
+	spinlock_t queue_lock;
 	struct list_head queue_head;	/* Requests are added here...			*/
-	struct semaphore queue_lock;
+	struct semaphore tx_lock;
 };
 #endif
 
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/include/linux/pci_ids.h linux/include/linux/pci_ids.h
--- tmp/linux/include/linux/pci_ids.h	Mon Feb 25 20:28:51 2002
+++ linux/include/linux/pci_ids.h	Mon Feb 25 20:26:07 2002
@@ -535,10 +535,6 @@
 #define PCI_DEVICE_ID_ELSA_MICROLINK	0x1000
 #define PCI_DEVICE_ID_ELSA_QS3000	0x3000
 
-#define PCI_VENDOR_ID_ELSA		0x1048
-#define PCI_DEVICE_ID_ELSA_MICROLINK	0x1000
-#define PCI_DEVICE_ID_ELSA_QS3000	0x3000
-
 #define PCI_VENDOR_ID_SGS		0x104a
 #define PCI_DEVICE_ID_SGS_2000		0x0008
 #define PCI_DEVICE_ID_SGS_1764		0x0009
@@ -1287,11 +1283,6 @@
 #define PCI_VENDOR_ID_ITE		0x1283
 #define PCI_DEVICE_ID_ITE_IT8172G	0x8172
 #define PCI_DEVICE_ID_ITE_IT8172G_AUDIO 0x0801
-
-#define PCI_VENDOR_ID_ITE		0x1283
-#define PCI_DEVICE_ID_ITE_IT8172G	0x8172
-
-#define PCI_VENDOR_ID_ITE			0x1283
 #define PCI_DEVICE_ID_ITE_8872		0x8872
 
 
@@ -1631,16 +1622,6 @@
 #define PCI_DEVICE_ID_INTEL_82801BA_2	0x2443
 #define PCI_DEVICE_ID_INTEL_82801BA_3	0x2444
 #define PCI_DEVICE_ID_INTEL_82801BA_4	0x2445
-#define PCI_DEVICE_ID_INTEL_82801CA_0	0x2480
-#define PCI_DEVICE_ID_INTEL_82801CA_2	0x2482
-#define PCI_DEVICE_ID_INTEL_82801CA_3	0x2483
-#define PCI_DEVICE_ID_INTEL_82801CA_4	0x2484
-#define PCI_DEVICE_ID_INTEL_82801CA_5	0x2485
-#define PCI_DEVICE_ID_INTEL_82801CA_6	0x2486
-#define PCI_DEVICE_ID_INTEL_82801CA_7	0x2487
-#define PCI_DEVICE_ID_INTEL_82801CA_10	0x248a
-#define PCI_DEVICE_ID_INTEL_82801CA_11	0x248b
-#define PCI_DEVICE_ID_INTEL_82801CA_12	0x248c
 #define PCI_DEVICE_ID_INTEL_82801BA_5	0x2446
 #define PCI_DEVICE_ID_INTEL_82801BA_6	0x2448
 #define PCI_DEVICE_ID_INTEL_82801BA_7	0x2449
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/ipc/shm.c linux/ipc/shm.c
--- tmp/linux/ipc/shm.c	Fri Dec 21 17:42:04 2001
+++ linux/ipc/shm.c	Mon Feb 25 19:39:09 2002
@@ -672,6 +672,7 @@
 {
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *shmd, *shmdnext;
+	int retval = -EINVAL;
 
 	down_write(&mm->mmap_sem);
 	for (shmd = mm->mmap; shmd; shmd = shmdnext) {
@@ -679,9 +680,10 @@
 		if (shmd->vm_ops == &shm_vm_ops
 		    && shmd->vm_start - (shmd->vm_pgoff << PAGE_SHIFT) == (ulong) shmaddr)
 			do_munmap(mm, shmd->vm_start, shmd->vm_end - shmd->vm_start);
+			retval = 0;
 	}
 	up_write(&mm->mmap_sem);
-	return 0;
+	return retval;
 }
 
 #ifdef CONFIG_PROC_FS
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/mm/Makefile linux/mm/Makefile
--- tmp/linux/mm/Makefile	Wed Oct 24 22:21:18 2001
+++ linux/mm/Makefile	Mon Feb 25 20:04:48 2002
@@ -9,7 +9,7 @@
 
 O_TARGET := mm.o
 
-export-objs := shmem.o filemap.o
+export-objs := shmem.o filemap.o memory.o
 
 obj-y	 := memory.o mmap.o filemap.o mprotect.o mlock.o mremap.o \
 	    vmalloc.o slab.o bootmem.o swap.o vmscan.o page_io.o \
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/mm/memory.c linux/mm/memory.c
--- tmp/linux/mm/memory.c	Mon Feb 25 20:28:51 2002
+++ linux/mm/memory.c	Mon Feb 25 20:04:48 2002
@@ -44,6 +44,7 @@
 #include <linux/iobuf.h>
 #include <linux/highmem.h>
 #include <linux/pagemap.h>
+#include <linux/module.h>
 
 #include <asm/pgalloc.h>
 #include <asm/uaccess.h>
@@ -523,6 +524,8 @@
 	i = -EFAULT;
 	goto out;
 }
+
+EXPORT_SYMBOL(get_user_pages);
 
 /*
  * Force in an entire range of pages from the current process's user VA,
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/mm/shmem.c linux/mm/shmem.c
--- tmp/linux/mm/shmem.c	Mon Feb 25 20:28:51 2002
+++ linux/mm/shmem.c	Mon Feb 25 20:13:27 2002
@@ -1088,19 +1088,25 @@
  */
 static int shmem_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
 {
-	int error = -ENOTEMPTY;
+	struct inode *inode;
 
-	if (shmem_empty(new_dentry)) {
-		struct inode *inode = new_dentry->d_inode;
-		if (inode) {
-			inode->i_ctime = CURRENT_TIME;
-			inode->i_nlink--;
-			dput(new_dentry);
-		}
-		error = 0;
-		old_dentry->d_inode->i_ctime = old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
+	if (!shmem_empty(new_dentry)) 
+		return -ENOTEMPTY;
+
+	inode = new_dentry->d_inode;
+	if (inode) {
+		inode->i_ctime = CURRENT_TIME;
+		inode->i_nlink--;
+		dput(new_dentry);
+	}
+	inode = old_dentry->d_inode;
+	if (S_ISDIR(inode->i_mode)) {
+		old_dir->i_nlink--;
+		new_dir->i_nlink++;
 	}
-	return error;
+
+	inode->i_ctime = old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
+	return 0;
 }
 
 static int shmem_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/scripts/cramfs/GNUmakefile linux/scripts/cramfs/GNUmakefile
--- tmp/linux/scripts/cramfs/GNUmakefile	Thu Jul 19 23:14:53 2001
+++ linux/scripts/cramfs/GNUmakefile	Thu Jan  1 00:00:00 1970
@@ -1,12 +0,0 @@
-CC = gcc
-CFLAGS = -W -Wall -O2 -g
-CPPFLAGS = -I../../include
-LDLIBS = -lz
-PROGS = mkcramfs cramfsck
-
-all: $(PROGS)
-
-distclean clean:
-	rm -f $(PROGS)
-
-.PHONY: all clean
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/scripts/cramfs/cramfsck.c linux/scripts/cramfs/cramfsck.c
--- tmp/linux/scripts/cramfs/cramfsck.c	Thu Jul 19 23:14:53 2001
+++ linux/scripts/cramfs/cramfsck.c	Thu Jan  1 00:00:00 1970
@@ -1,588 +0,0 @@
-/*
- * cramfsck - check a cramfs file system
- *
- * Copyright (C) 2000-2001 Transmeta Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * 1999/12/03: Linus Torvalds (cramfs tester and unarchive program)
- * 2000/06/03: Daniel Quinlan (CRC and length checking program)
- * 2000/06/04: Daniel Quinlan (merged programs, added options, support
- *                            for special files, preserve permissions and
- *                            ownership, cramfs superblock v2, bogus mode
- *                            test, pathname length test, etc.)
- * 2000/06/06: Daniel Quinlan (support for holes, pretty-printing,
- *                            symlink size test)
- * 2000/07/11: Daniel Quinlan (file length tests, start at offset 0 or 512,
- *                            fsck-compatible exit codes)
- * 2000/07/15: Daniel Quinlan (initial support for block devices)
- */
-
-/* compile-time options */
-#define INCLUDE_FS_TESTS	/* include cramfs checking and extraction */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/fcntl.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <assert.h>
-#include <getopt.h>
-#include <sys/sysmacros.h>
-#include <utime.h>
-#include <sys/ioctl.h>
-#define _LINUX_STRING_H_
-#include <linux/fs.h>
-#include <linux/cramfs_fs.h>
-#include <zlib.h>
-
-static const char *progname = "cramfsck";
-
-static int fd;			/* ROM image file descriptor */
-static char *filename;		/* ROM image filename */
-struct cramfs_super *super;	/* just find the cramfs superblock once */
-static int opt_verbose = 0;	/* 1 = verbose (-v), 2+ = very verbose (-vv) */
-#ifdef INCLUDE_FS_TESTS
-static int opt_extract = 0;	/* extract cramfs (-x) */
-char *extract_dir = NULL;	/* extraction directory (-x) */
-
-unsigned long start_inode = 1 << 28;	/* start of first non-root inode */
-unsigned long end_inode = 0;		/* end of the directory structure */
-unsigned long start_data = 1 << 28;	/* start of the data (256 MB = max) */
-unsigned long end_data = 0;		/* end of the data */
-/* true?  cramfs_super < start_inode < end_inode <= start_data <= end_data */
-static uid_t euid;			/* effective UID */
-
-#define PAD_SIZE 512
-#define PAGE_CACHE_SIZE (4096)
-
-/* Guarantee access to at least 8kB at a time */
-#define ROMBUFFER_BITS	13
-#define ROMBUFFERSIZE	(1 << ROMBUFFER_BITS)
-#define ROMBUFFERMASK	(ROMBUFFERSIZE-1)
-static char read_buffer[ROMBUFFERSIZE * 2];
-static unsigned long read_buffer_block = ~0UL;
-
-/* Uncompressing data structures... */
-static char outbuffer[PAGE_CACHE_SIZE*2];
-z_stream stream;
-
-#endif /* INCLUDE_FS_TESTS */
-
-/* Input status of 0 to print help and exit without an error. */
-static void usage(int status)
-{
-	FILE *stream = status ? stderr : stdout;
-
-	fprintf(stream, "usage: %s [-hv] [-x dir] file\n"
-		" -h         print this help\n"
-		" -x dir     extract into dir\n"
-		" -v         be more verbose\n"
-		" file       file to test\n", progname);
-
-	exit(status);
-}
-
-#ifdef INCLUDE_FS_TESTS
-void print_node(char type, struct cramfs_inode *i, char *name)
-{
-	char info[10];
-
-	if (S_ISCHR(i->mode) || (S_ISBLK(i->mode))) {
-		/* major/minor numbers can be as high as 2^12 or 4096 */
-		snprintf(info, 10, "%4d,%4d", major(i->size), minor(i->size));
-	}
-	else {
-		/* size be as high as 2^24 or 16777216 */
-		snprintf(info, 10, "%9d", i->size);
-	}
-
-	printf("%c %04o %s %5d:%-3d %s\n",
-	       type, i->mode & ~S_IFMT, info, i->uid, i->gid, name);
-}
-
-/*
- * Create a fake "blocked" access
- */
-static void *romfs_read(unsigned long offset)
-{
-	unsigned int block = offset >> ROMBUFFER_BITS;
-	if (block != read_buffer_block) {
-		read_buffer_block = block;
-		lseek(fd, block << ROMBUFFER_BITS, SEEK_SET);
-		read(fd, read_buffer, ROMBUFFERSIZE * 2);
-	}
-	return read_buffer + (offset & ROMBUFFERMASK);
-}
-
-static struct cramfs_inode *cramfs_iget(struct cramfs_inode * i)
-{
-	struct cramfs_inode *inode = malloc(sizeof(struct cramfs_inode));
-	*inode = *i;
-	return inode;
-}
-
-static struct cramfs_inode *iget(unsigned int ino)
-{
-	return cramfs_iget(romfs_read(ino));
-}
-
-void iput(struct cramfs_inode *inode)
-{
-	free(inode);
-}
-
-/*
- * Return the offset of the root directory,
- * or 0 if none.
- */
-static struct cramfs_inode *read_super(void)
-{
-	unsigned long offset;
-
-	offset = super->root.offset << 2;
-	if (super->magic != CRAMFS_MAGIC)
-		return NULL;
-	if (memcmp(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature)) != 0)
-		return NULL;
-	if (offset < sizeof(super))
-		return NULL;
-	return cramfs_iget(&super->root);
-}
-
-static int uncompress_block(void *src, int len)
-{
-	int err;
-
-	stream.next_in = src;
-	stream.avail_in = len;
-
-	stream.next_out = (unsigned char *) outbuffer;
-	stream.avail_out = PAGE_CACHE_SIZE*2;
-
-	inflateReset(&stream);
-
-	err = inflate(&stream, Z_FINISH);
-	if (err != Z_STREAM_END) {
-		fprintf(stderr, "%s: error %d while decompressing! %p(%d)\n",
-			filename, err, src, len);
-		exit(4);
-	}
-	return stream.total_out;
-}
-
-static void change_file_status(char *path, struct cramfs_inode *i)
-{
-	struct utimbuf epoch = { 0, 0 };
-
-	if (euid == 0) {
-		if (lchown(path, i->uid, i->gid) < 0) {
-			perror(path);
-			exit(8);
-		}
-		if (S_ISLNK(i->mode))
-			return;
-		if ((S_ISUID | S_ISGID) & i->mode) {
-			if (chmod(path, i->mode) < 0) {
-				perror(path);
-				exit(8);
-			}
-		}
-	}
-	if (S_ISLNK(i->mode))
-		return;
-	if (utime(path, &epoch) < 0) {
-		perror(path);
-		exit(8);
-	}
-}
-
-static void do_symlink(char *path, struct cramfs_inode *i)
-{
-	unsigned long offset = i->offset << 2;
-	unsigned long curr = offset + 4;
-	unsigned long next = *(u32 *) romfs_read(offset);
-	unsigned long size;
-
-	if (next > end_data) {
-		end_data = next;
-	}
-
-	size = uncompress_block(romfs_read(curr), next - curr);
-	if (size != i->size) {
-		fprintf(stderr, "%s: size error in symlink `%s'\n",
-			filename, path);
-		exit(4);
-	}
-	outbuffer[size] = 0;
-	if (opt_verbose) {
-		char *str;
-
-		str = malloc(strlen(outbuffer) + strlen(path) + 5);
-		strcpy(str, path);
-		strncat(str, " -> ", 4);
-		strncat(str, outbuffer, size);
-
-		print_node('l', i, str);
-		if (opt_verbose > 1) {
-			printf("  uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
-		}
-	}
-	if (opt_extract) {
-		symlink(outbuffer, path);
-		change_file_status(path, i);
-	}
-}
-
-static void do_special_inode(char *path, struct cramfs_inode *i)
-{
-	dev_t devtype = 0;
-	char type;
-
-	if (S_ISCHR(i->mode)) {
-		devtype = i->size;
-		type = 'c';
-	}
-	else if (S_ISBLK(i->mode)) {
-		devtype = i->size;
-		type = 'b';
-	}
-	else if (S_ISFIFO(i->mode))
-		type = 'p';
-	else if (S_ISSOCK(i->mode))
-		type = 's';
-	else {
-		fprintf(stderr, "%s: bogus mode on `%s' (%o)\n", filename, path, i->mode);
-		exit(4);
-	}
-
-	if (opt_verbose) {
-		print_node(type, i, path);
-	}
-
-	if (opt_extract) {
-		if (mknod(path, i->mode, devtype) < 0) {
-			perror(path);
-			exit(8);
-		}
-		change_file_status(path, i);
-	}
-}
-
-static void do_uncompress(int fd, unsigned long offset, unsigned long size)
-{
-	unsigned long curr = offset + 4 * ((size + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);
-
-	do {
-		unsigned long out = PAGE_CACHE_SIZE;
-		unsigned long next = *(u32 *) romfs_read(offset);
-
-		if (next > end_data) {
-			end_data = next;
-		}
-
-		offset += 4;
-		if (curr == next) {
-			if (opt_verbose > 1) {
-				printf("  hole at %ld (%d)\n", curr, PAGE_CACHE_SIZE);
-			}
-			if (size < PAGE_CACHE_SIZE)
-				out = size;
-			memset(outbuffer, 0x00, out);
-		}
-		else {
-			if (opt_verbose > 1) {
-				printf("  uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
-			}
-			out = uncompress_block(romfs_read(curr), next - curr);
-		}
-		if (size >= PAGE_CACHE_SIZE) {
-			if (out != PAGE_CACHE_SIZE) {
-				fprintf(stderr, "%s: Non-block (%ld) bytes\n", filename, out);
-				exit(4);
-			}
-		} else {
-			if (out != size) {
-				fprintf(stderr, "%s: Non-size (%ld vs %ld) bytes\n", filename, out, size);
-				exit(4);
-			}
-		}
-		size -= out;
-		if (opt_extract) {
-			write(fd, outbuffer, out);
-		}
-		curr = next;
-	} while (size);
-}
-
-static void expand_fs(int pathlen, char *path, struct cramfs_inode *inode)
-{
-	if (S_ISDIR(inode->mode)) {
-		int count = inode->size;
-		unsigned long offset = inode->offset << 2;
-		char *newpath = malloc(pathlen + 256);
-
-		if (count > 0 && offset < start_inode) {
-			start_inode = offset;
-		}
-		/* XXX - need to check end_inode for empty case? */
-		memcpy(newpath, path, pathlen);
-		newpath[pathlen] = '/';
-		pathlen++;
-		if (opt_verbose) {
-			print_node('d', inode, path);
-		}
-		if (opt_extract) {
-			mkdir(path, inode->mode);
-			change_file_status(path, inode);
-		}
-		while (count > 0) {
-			struct cramfs_inode *child = iget(offset);
-			int size;
-			int newlen = child->namelen << 2;
-
-			size = sizeof(struct cramfs_inode) + newlen;
-			count -= size;
-
-			offset += sizeof(struct cramfs_inode);
-
-			memcpy(newpath + pathlen, romfs_read(offset), newlen);
-			newpath[pathlen + newlen] = 0;
-			if ((pathlen + newlen) - strlen(newpath) > 3) {
-				fprintf(stderr, "%s: invalid cramfs--bad path length\n", filename);
-				exit(4);
-			}
-			expand_fs(strlen(newpath), newpath, child);
-
-			offset += newlen;
-
-			if (offset > end_inode) {
-				end_inode = offset;
-			}
-		}
-		return;
-	}
-	if (S_ISREG(inode->mode)) {
-		int fd = 0;
-		unsigned long offset = inode->offset << 2;
-
-		if (offset > 0 && offset < start_data) {
-			start_data = offset;
-		}
-		if (opt_verbose) {
-			print_node('f', inode, path);
-		}
-		if (opt_extract) {
-			fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, inode->mode);
-		}
-		if (inode->size) {
-			do_uncompress(fd, offset, inode->size);
-		}
-		if (opt_extract) {
-			close(fd);
-			change_file_status(path, inode);
-		}
-		return;
-	}
-	if (S_ISLNK(inode->mode)) {
-		unsigned long offset = inode->offset << 2;
-
-		if (offset < start_data) {
-			start_data = offset;
-		}
-		do_symlink(path, inode);
-		return;
-	}
-	else {
-		do_special_inode(path, inode);
-		return;
-	}
-}
-#endif /* INCLUDE_FS_TESTS */
-
-int main(int argc, char **argv)
-{
-	void *buf;
-	size_t length;
-	struct stat st;
-	u32 crc_old, crc_new;
-#ifdef INCLUDE_FS_TESTS
-	struct cramfs_inode *root;
-#endif /* INCLUDE_FS_TESTS */
-	int c;			/* for getopt */
-	int start = 0;
-
-	if (argc)
-		progname = argv[0];
-
-	/* command line options */
-	while ((c = getopt(argc, argv, "hx:v")) != EOF) {
-		switch (c) {
-		case 'h':
-			usage(0);
-		case 'x':
-#ifdef INCLUDE_FS_TESTS
-			opt_extract = 1;
-			extract_dir = malloc(strlen(optarg) + 1);
-			strcpy(extract_dir, optarg);
-			break;
-#else /*  not INCLUDE_FS_TESTS */
-			fprintf(stderr, "%s: compiled without -x support\n",
-				progname);
-			exit(16);
-#endif /* not INCLUDE_FS_TESTS */
-		case 'v':
-			opt_verbose++;
-			break;
-		}
-	}
-
-	if ((argc - optind) != 1)
-		usage(16);
-	filename = argv[optind];
-
-	/* find the physical size of the file or block device */
-	if (lstat(filename, &st) < 0) {
-		perror(filename);
-		exit(8);
-	}
-	fd = open(filename, O_RDONLY);
-	if (fd < 0) {
-		perror(filename);
-		exit(8);
-	}
-	if (S_ISBLK(st.st_mode)) {
-		if (ioctl(fd, BLKGETSIZE, &length) < 0) {
-			fprintf(stderr, "%s: warning--unable to determine filesystem size \n", filename);
-			exit(4);
-		}
-		length = length * 512;
-	}
-	else if (S_ISREG(st.st_mode)) {
-		length = st.st_size;
-	}
-	else {
-		fprintf(stderr, "%s is not a block device or file\n", filename);
-		exit(8);
-	}
-
-	if (length < sizeof(struct cramfs_super)) {
-		fprintf(stderr, "%s: invalid cramfs--file length too short\n", filename);
-		exit(4);
-	}
-
-	if (S_ISBLK(st.st_mode)) {
-		/* nasty because mmap of block devices fails */
-		buf = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-		read(fd, buf, length);
-	}
-	else {
-		/* nice and easy */
-		buf = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
-	}
-
-	/* XXX - this could be cleaner... */
-	if (((struct cramfs_super *) buf)->magic == CRAMFS_MAGIC) {
-		start = 0;
-		super = (struct cramfs_super *) buf;
-	}
-	else if (length >= (PAD_SIZE + sizeof(struct cramfs_super)) &&
-		 ((((struct cramfs_super *) (buf + PAD_SIZE))->magic == CRAMFS_MAGIC)))
-	{
-		start = PAD_SIZE;
-		super = (struct cramfs_super *) (buf + PAD_SIZE);
-	}
-	else {
-		fprintf(stderr, "%s: invalid cramfs--wrong magic\n", filename);
-		exit(4);
-	}
-
-	if (super->flags & CRAMFS_FLAG_FSID_VERSION_2) {
-		/* length test */
-		if (length < super->size) {
-			fprintf(stderr, "%s: invalid cramfs--file length too short\n", filename);
-			exit(4);
-		}
-		else if (length > super->size) {
-			fprintf(stderr, "%s: warning--file length too long, padded image?\n", filename);
-		}
-
-		/* CRC test */
-		crc_old = super->fsid.crc;
-		super->fsid.crc = crc32(0L, Z_NULL, 0);
-		crc_new = crc32(0L, Z_NULL, 0);
-		crc_new = crc32(crc_new, (unsigned char *) buf+start, super->size - start);
-		if (crc_new != crc_old) {
-			fprintf(stderr, "%s: invalid cramfs--crc error\n", filename);
-			exit(4);
-		}
-	}
-	else {
-		fprintf(stderr, "%s: warning--old cramfs image, no CRC\n",
-			filename);
-	}
-
-#ifdef INCLUDE_FS_TESTS
-	super = (struct cramfs_super *) malloc(sizeof(struct cramfs_super));
-	if (((struct cramfs_super *) buf)->magic == CRAMFS_MAGIC) {
-		memcpy(super, buf, sizeof(struct cramfs_super));
-	}
-	else if (length >= (PAD_SIZE + sizeof(struct cramfs_super)) &&
-		 ((((struct cramfs_super *) (buf + PAD_SIZE))->magic == CRAMFS_MAGIC)))
-	{
-		memcpy(super, (buf + PAD_SIZE), sizeof(struct cramfs_super));
-	}
-
-	munmap(buf, length);
-
-	/* file format test, uses fake "blocked" accesses */
-	root = read_super();
-	umask(0);
-	euid = geteuid();
-	if (!root) {
-		fprintf(stderr, "%s: invalid cramfs--bad superblock\n",
-			filename);
-		exit(4);
-	}
-	stream.next_in = NULL;
-	stream.avail_in = 0;
-	inflateInit(&stream);
-
-	if (!extract_dir) {
-		extract_dir = "root";
-	}
-
-	expand_fs(strlen(extract_dir), extract_dir, root);
-	inflateEnd(&stream);
-
-	if (start_data != 1 << 28  && end_inode != start_data) {
-		fprintf(stderr, "%s: invalid cramfs--directory data end (%ld) != file data start (%ld)\n", filename, end_inode, start_data);
-		exit(4);
-	}
-	if (super->flags & CRAMFS_FLAG_FSID_VERSION_2) {
-		if (end_data > super->size) {
-			fprintf(stderr, "%s: invalid cramfs--invalid file data offset\n", filename);
-			exit(4);
-		}
-	}
-#endif /* INCLUDE_FS_TESTS */
-
-	exit(0);
-}
diff -Naur -X /home/marcelo/lib/dontdiff tmp/linux/scripts/cramfs/mkcramfs.c linux/scripts/cramfs/mkcramfs.c
--- tmp/linux/scripts/cramfs/mkcramfs.c	Thu Jul 19 23:14:53 2001
+++ linux/scripts/cramfs/mkcramfs.c	Thu Jan  1 00:00:00 1970
@@ -1,776 +0,0 @@
-/*
- * mkcramfs - make a cramfs file system
- *
- * Copyright (C) 1999-2001 Transmeta Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/fcntl.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <assert.h>
-#include <getopt.h>
-#include <linux/cramfs_fs.h>
-#include <zlib.h>
-
-#define PAD_SIZE 512		/* only 0 and 512 supported by kernel */
-
-static const char *progname = "mkcramfs";
-
-/* N.B. If you change the disk format of cramfs, please update fs/cramfs/README. */
-
-/* Input status of 0 to print help and exit without an error. */
-static void usage(int status)
-{
-	FILE *stream = status ? stderr : stdout;
-
-	fprintf(stream, "usage: %s [-h] [-e edition] [-i file] [-n name] dirname outfile\n"
-		" -h         print this help\n"
-		" -E         make all warnings errors (non-zero exit status)\n"
-		" -e edition set edition number (part of fsid)\n"
-		" -i file    insert a file image into the filesystem (requires >= 2.4.0)\n"
-		" -n name    set name of cramfs filesystem\n"
-		" -p         pad by %d bytes for boot code\n"
-		" -s         sort directory entries (old option, ignored)\n"
-		" -z         make explicit holes (requires >= 2.3.39)\n"
-		" dirname    root of the filesystem to be compressed\n"
-		" outfile    output file\n", progname, PAD_SIZE);
-
-	exit(status);
-}
-
-#define PAGE_CACHE_SIZE (4096)
-/* The kernel assumes PAGE_CACHE_SIZE as block size. */
-static unsigned int blksize = PAGE_CACHE_SIZE;
-static long total_blocks = 0, total_nodes = 1; /* pre-count the root node */
-static int image_length = 0;
-
-/*
- * If opt_holes is set, then mkcramfs can create explicit holes in the
- * data, which saves 26 bytes per hole (which is a lot smaller a
- * saving than most most filesystems).
- *
- * Note that kernels up to at least 2.3.39 don't support cramfs holes,
- * which is why this is turned off by default.
- */
-static int opt_edition = 0;
-static int opt_errors = 0;
-static int opt_holes = 0;
-static int opt_pad = 0;
-static char *opt_image = NULL;
-static char *opt_name = NULL;
-
-static int warn_dev, warn_gid, warn_namelen, warn_skip, warn_size, warn_uid;
-
-#ifndef MIN
-# define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
-#endif
-
-/* In-core version of inode / directory entry. */
-struct entry {
-	/* stats */
-	char *name;
-	unsigned int mode, size, uid, gid;
-
-	/* FS data */
-	void *uncompressed;
-        /* points to other identical file */
-        struct entry *same;
-        unsigned int offset;            /* pointer to compressed data in archive */
-	unsigned int dir_offset;	/* Where in the archive is the directory entry? */
-
-	/* organization */
-	struct entry *child; /* null for non-directories and empty directories */
-	struct entry *next;
-};
-
-/*
- * The longest file name component to allow for in the input directory tree.
- * Ext2fs (and many others) allow up to 255 bytes.  A couple of filesystems
- * allow longer (e.g. smbfs 1024), but there isn't much use in supporting
- * >255-byte names in the input directory tree given that such names get
- * truncated to 255 bytes when written to cramfs.
- */
-#define MAX_INPUT_NAMELEN 255
-
-static int find_identical_file(struct entry *orig,struct entry *newfile)
-{
-        if(orig==newfile) return 1;
-        if(!orig) return 0;
-        if(orig->size==newfile->size && orig->uncompressed && !memcmp(orig->uncompressed,newfile->uncompressed,orig->size)) {
-                newfile->same=orig;
-                return 1;
-        }
-        return find_identical_file(orig->child,newfile) ||
-                   find_identical_file(orig->next,newfile);
-}
-
-static void eliminate_doubles(struct entry *root,struct entry *orig) {
-        if(orig) {
-                if(orig->size && orig->uncompressed)
-			find_identical_file(root,orig);
-                eliminate_doubles(root,orig->child);
-                eliminate_doubles(root,orig->next);
-        }
-}
-
-/*
- * We define our own sorting function instead of using alphasort which
- * uses strcoll and changes ordering based on locale information.
- */
-static int cramsort (const void *a, const void *b)
-{
-	return strcmp ((*(const struct dirent **) a)->d_name,
-		       (*(const struct dirent **) b)->d_name);
-}
-
-static unsigned int parse_directory(struct entry *root_entry, const char *name, struct entry **prev, loff_t *fslen_ub)
-{
-	struct dirent **dirlist;
-	int totalsize = 0, dircount, dirindex;
-	char *path, *endpath;
-	size_t len = strlen(name);
-
-	/* Set up the path. */
-	/* TODO: Reuse the parent's buffer to save memcpy'ing and duplication. */
-	path = malloc(len + 1 + MAX_INPUT_NAMELEN + 1);
-	if (!path) {
-		perror(NULL);
-		exit(8);
-	}
-	memcpy(path, name, len);
-	endpath = path + len;
-	*endpath = '/';
-	endpath++;
-
-        /* read in the directory and sort */
-        dircount = scandir(name, &dirlist, 0, cramsort);
-
-	if (dircount < 0) {
-		perror(name);
-		exit(8);
-	}
-
-	/* process directory */
-	for (dirindex = 0; dirindex < dircount; dirindex++) {
-		struct dirent *dirent;
-		struct entry *entry;
-		struct stat st;
-		int size;
-		size_t namelen;
-
-		dirent = dirlist[dirindex];
-
-		/* Ignore "." and ".." - we won't be adding them to the archive */
-		if (dirent->d_name[0] == '.') {
-			if (dirent->d_name[1] == '\0')
-				continue;
-			if (dirent->d_name[1] == '.') {
-				if (dirent->d_name[2] == '\0')
-					continue;
-			}
-		}
-		namelen = strlen(dirent->d_name);
-		if (namelen > MAX_INPUT_NAMELEN) {
-			fprintf(stderr,
-				"Very long (%u bytes) filename `%s' found.\n"
-				" Please increase MAX_INPUT_NAMELEN in mkcramfs.c and recompile.  Exiting.\n",
-				namelen, dirent->d_name);
-			exit(8);
-		}
-		memcpy(endpath, dirent->d_name, namelen + 1);
-
-		if (lstat(path, &st) < 0) {
-			perror(endpath);
-			warn_skip = 1;
-			continue;
-		}
-		entry = calloc(1, sizeof(struct entry));
-		if (!entry) {
-			perror(NULL);
-			exit(8);
-		}
-		entry->name = strdup(dirent->d_name);
-		if (!entry->name) {
-			perror(NULL);
-			exit(8);
-		}
-		if (namelen > 255) {
-			/* Can't happen when reading from ext2fs. */
-
-			/* TODO: we ought to avoid chopping in half
-			   multi-byte UTF8 characters. */
-			entry->name[namelen = 255] = '\0';
-			warn_namelen = 1;
-		}
-		entry->mode = st.st_mode;
-		entry->size = st.st_size;
-		entry->uid = st.st_uid;
-		if (entry->uid >= 1 << CRAMFS_UID_WIDTH)
-			warn_uid = 1;
-		entry->gid = st.st_gid;
-		if (entry->gid >= 1 << CRAMFS_GID_WIDTH)
-			/* TODO: We ought to replace with a default
-                           gid instead of truncating; otherwise there
-                           are security problems.  Maybe mode should
-                           be &= ~070.  Same goes for uid once Linux
-                           supports >16-bit uids. */
-			warn_gid = 1;
-		size = sizeof(struct cramfs_inode) + ((namelen + 3) & ~3);
-		*fslen_ub += size;
-		if (S_ISDIR(st.st_mode)) {
-			entry->size = parse_directory(root_entry, path, &entry->child, fslen_ub);
-		} else if (S_ISREG(st.st_mode)) {
-			/* TODO: We ought to open files in do_compress, one
-			   at a time, instead of amassing all these memory
-			   maps during parse_directory (which don't get used
-			   until do_compress anyway).  As it is, we tend to
-			   get EMFILE errors (especially if mkcramfs is run
-			   by non-root).
-
-			   While we're at it, do analagously for symlinks
-			   (which would just save a little memory). */
-			int fd = open(path, O_RDONLY);
-			if (fd < 0) {
-				perror(path);
-				warn_skip = 1;
-				continue;
-			}
-			if (entry->size) {
-				if ((entry->size >= 1 << CRAMFS_SIZE_WIDTH)) {
-					warn_size = 1;
-					entry->size = (1 << CRAMFS_SIZE_WIDTH) - 1;
-				}
-
-				entry->uncompressed = mmap(NULL, entry->size, PROT_READ, MAP_PRIVATE, fd, 0);
-				if (-1 == (int) (long) entry->uncompressed) {
-					perror("mmap");
-					exit(8);
-				}
-			}
-			close(fd);
-		} else if (S_ISLNK(st.st_mode)) {
-			entry->uncompressed = malloc(entry->size);
-			if (!entry->uncompressed) {
-				perror(NULL);
-				exit(8);
-			}
-			if (readlink(path, entry->uncompressed, entry->size) < 0) {
-				perror(path);
-				warn_skip = 1;
-				continue;
-			}
-		} else if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
-			/* maybe we should skip sockets */
-			entry->size = 0;
-		} else {
-			entry->size = st.st_rdev;
-			if (entry->size & -(1<<CRAMFS_SIZE_WIDTH))
-				warn_dev = 1;
-		}
-
-		if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
-			int blocks = ((entry->size - 1) / blksize + 1);
-
-			/* block pointers & data expansion allowance + data */
-			if(entry->size)
-				*fslen_ub += (4+26)*blocks + entry->size + 3;
-                }
-
-		/* Link it into the list */
-		*prev = entry;
-		prev = &entry->next;
-		totalsize += size;
-	}
-	free(path);
-	free(dirlist);		/* allocated by scandir() with malloc() */
-	return totalsize;
-}
-
-/* Returns sizeof(struct cramfs_super), which includes the root inode. */
-static unsigned int write_superblock(struct entry *root, char *base, int size)
-{
-	struct cramfs_super *super = (struct cramfs_super *) base;
-	unsigned int offset = sizeof(struct cramfs_super) + image_length;
-
-	if (opt_pad) {
-		offset += opt_pad;
-	}
-
-	super->magic = CRAMFS_MAGIC;
-	super->flags = CRAMFS_FLAG_FSID_VERSION_2 | CRAMFS_FLAG_SORTED_DIRS;
-	if (opt_holes)
-		super->flags |= CRAMFS_FLAG_HOLES;
-	if (image_length > 0)
-		super->flags |= CRAMFS_FLAG_SHIFTED_ROOT_OFFSET;
-	super->size = size;
-	memcpy(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature));
-
-	super->fsid.crc = crc32(0L, Z_NULL, 0);
-	super->fsid.edition = opt_edition;
-	super->fsid.blocks = total_blocks;
-	super->fsid.files = total_nodes;
-
-	memset(super->name, 0x00, sizeof(super->name));
-	if (opt_name)
-		strncpy(super->name, opt_name, sizeof(super->name));
-	else
-		strncpy(super->name, "Compressed", sizeof(super->name));
-
-	super->root.mode = root->mode;
-	super->root.uid = root->uid;
-	super->root.gid = root->gid;
-	super->root.size = root->size;
-	super->root.offset = offset >> 2;
-
-	return offset;
-}
-
-static void set_data_offset(struct entry *entry, char *base, unsigned long offset)
-{
-	struct cramfs_inode *inode = (struct cramfs_inode *) (base + entry->dir_offset);
-#ifdef DEBUG
-	assert ((offset & 3) == 0);
-#endif /* DEBUG */
-	if (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH))) {
-		fprintf(stderr, "filesystem too big.  Exiting.\n");
-		exit(8);
-	}
-	inode->offset = (offset >> 2);
-}
-
-
-/*
- * We do a width-first printout of the directory
- * entries, using a stack to remember the directories
- * we've seen.
- */
-#define MAXENTRIES (100)
-static unsigned int write_directory_structure(struct entry *entry, char *base, unsigned int offset)
-{
-	int stack_entries = 0;
-	struct entry *entry_stack[MAXENTRIES];
-
-	for (;;) {
-		int dir_start = stack_entries;
-		while (entry) {
-			struct cramfs_inode *inode = (struct cramfs_inode *) (base + offset);
-			size_t len = strlen(entry->name);
-
-			entry->dir_offset = offset;
-
-			inode->mode = entry->mode;
-			inode->uid = entry->uid;
-			inode->gid = entry->gid;
-			inode->size = entry->size;
-			inode->offset = 0;
-			/* Non-empty directories, regfiles and symlinks will
-			   write over inode->offset later. */
-
-			offset += sizeof(struct cramfs_inode);
-			total_nodes++;	/* another node */
-			memcpy(base + offset, entry->name, len);
-			/* Pad up the name to a 4-byte boundary */
-			while (len & 3) {
-				*(base + offset + len) = '\0';
-				len++;
-			}
-			inode->namelen = len >> 2;
-			offset += len;
-
-			/* TODO: this may get it wrong for chars >= 0x80.
-			   Most filesystems use UTF8 encoding for filenames,
-			   whereas the console is a single-byte character
-			   set like iso-latin-1. */
-			printf("  %s\n", entry->name);
-			if (entry->child) {
-				if (stack_entries >= MAXENTRIES) {
-					fprintf(stderr, "Exceeded MAXENTRIES.  Raise this value in mkcramfs.c and recompile.  Exiting.\n");
-					exit(8);
-				}
-				entry_stack[stack_entries] = entry;
-				stack_entries++;
-			}
-			entry = entry->next;
-		}
-
-		/*
-		 * Reverse the order the stack entries pushed during
-                 * this directory, for a small optimization of disk
-                 * access in the created fs.  This change makes things
-                 * `ls -UR' order.
-		 */
-		{
-			struct entry **lo = entry_stack + dir_start;
-			struct entry **hi = entry_stack + stack_entries;
-			struct entry *tmp;
-
-			while (lo < --hi) {
-				tmp = *lo;
-				*lo++ = *hi;
-				*hi = tmp;
-			}
-		}
-
-		/* Pop a subdirectory entry from the stack, and recurse. */
-		if (!stack_entries)
-			break;
-		stack_entries--;
-		entry = entry_stack[stack_entries];
-
-		set_data_offset(entry, base, offset);
-		printf("'%s':\n", entry->name);
-		entry = entry->child;
-	}
-	return offset;
-}
-
-static int is_zero(char const *begin, unsigned len)
-{
-	if (opt_holes)
-		/* Returns non-zero iff the first LEN bytes from BEGIN are
-		   all NULs. */
-		return (len-- == 0 ||
-			(begin[0] == '\0' &&
-			 (len-- == 0 ||
-			  (begin[1] == '\0' &&
-			   (len-- == 0 ||
-			    (begin[2] == '\0' &&
-			     (len-- == 0 ||
-			      (begin[3] == '\0' &&
-			       memcmp(begin, begin + 4, len) == 0))))))));
-	else
-		/* Never create holes. */
-		return 0;
-}
-
-/*
- * One 4-byte pointer per block and then the actual blocked
- * output. The first block does not need an offset pointer,
- * as it will start immediately after the pointer block;
- * so the i'th pointer points to the end of the i'th block
- * (i.e. the start of the (i+1)'th block or past EOF).
- *
- * Note that size > 0, as a zero-sized file wouldn't ever
- * have gotten here in the first place.
- */
-static unsigned int do_compress(char *base, unsigned int offset, char const *name, char *uncompressed, unsigned int size)
-{
-	unsigned long original_size = size;
-	unsigned long original_offset = offset;
-	unsigned long new_size;
-	unsigned long blocks = (size - 1) / blksize + 1;
-	unsigned long curr = offset + 4 * blocks;
-	int change;
-
-	total_blocks += blocks;
-
-	do {
-		unsigned long len = 2 * blksize;
-		unsigned int input = size;
-		if (input > blksize)
-			input = blksize;
-		size -= input;
-		if (!is_zero (uncompressed, input)) {
-			compress(base + curr, &len, uncompressed, input);
-			curr += len;
-		}
-		uncompressed += input;
-
-		if (len > blksize*2) {
-			/* (I don't think this can happen with zlib.) */
-			printf("AIEEE: block \"compressed\" to > 2*blocklength (%ld)\n", len);
-			exit(8);
-		}
-
-		*(u32 *) (base + offset) = curr;
-		offset += 4;
-	} while (size);
-
-	curr = (curr + 3) & ~3;
-	new_size = curr - original_offset;
-	/* TODO: Arguably, original_size in these 2 lines should be
-	   st_blocks * 512.  But if you say that then perhaps
-	   administrative data should also be included in both. */
-	change = new_size - original_size;
-	printf("%6.2f%% (%+d bytes)\t%s\n",
-	       (change * 100) / (double) original_size, change, name);
-
-	return curr;
-}
-
-
-/*
- * Traverse the entry tree, writing data for every item that has
- * non-null entry->compressed (i.e. every symlink and non-empty
- * regfile).
- */
-static unsigned int write_data(struct entry *entry, char *base, unsigned int offset)
-{
-	do {
-		if (entry->uncompressed) {
-                        if(entry->same) {
-                                set_data_offset(entry, base, entry->same->offset);
-                                entry->offset=entry->same->offset;
-                        } else {
-                                set_data_offset(entry, base, offset);
-                                entry->offset=offset;
-                                offset = do_compress(base, offset, entry->name, entry->uncompressed, entry->size);
-                        }
-		}
-		else if (entry->child)
-			offset = write_data(entry->child, base, offset);
-                entry=entry->next;
-	} while (entry);
-	return offset;
-}
-
-static unsigned int write_file(char *file, char *base, unsigned int offset)
-{
-	int fd;
-	char *buf;
-
-	fd = open(file, O_RDONLY);
-	if (fd < 0) {
-		perror(file);
-		exit(8);
-	}
-	buf = mmap(NULL, image_length, PROT_READ, MAP_PRIVATE, fd, 0);
-	memcpy(base + offset, buf, image_length);
-	munmap(buf, image_length);
-	close (fd);
-	/* Pad up the image_length to a 4-byte boundary */
-	while (image_length & 3) {
-		*(base + offset + image_length) = '\0';
-		image_length++;
-	}
-	return (offset + image_length);
-}
-
-/*
- * Maximum size fs you can create is roughly 256MB.  (The last file's
- * data must begin within 256MB boundary but can extend beyond that.)
- *
- * Note that if you want it to fit in a ROM then you're limited to what the
- * hardware and kernel can support (64MB?).
- */
-#define MAXFSLEN ((((1 << CRAMFS_OFFSET_WIDTH) - 1) << 2) /* offset */ \
-		  + (1 << CRAMFS_SIZE_WIDTH) - 1 /* filesize */ \
-		  + (1 << CRAMFS_SIZE_WIDTH) * 4 / PAGE_CACHE_SIZE /* block pointers */ )
-
-
-/*
- * Usage:
- *
- *      mkcramfs directory-name outfile
- *
- * where "directory-name" is simply the root of the directory
- * tree that we want to generate a compressed filesystem out
- * of.
- */
-int main(int argc, char **argv)
-{
-	struct stat st;		/* used twice... */
-	struct entry *root_entry;
-	char *rom_image;
-	ssize_t offset, written;
-	int fd;
-	/* initial guess (upper-bound) of required filesystem size */
-	loff_t fslen_ub = sizeof(struct cramfs_super);
-	char const *dirname, *outfile;
-	u32 crc = crc32(0L, Z_NULL, 0);
-	int c;			/* for getopt */
-
-	total_blocks = 0;
-
-	if (argc)
-		progname = argv[0];
-
-	/* command line options */
-	while ((c = getopt(argc, argv, "hEe:i:n:psz")) != EOF) {
-		switch (c) {
-		case 'h':
-			usage(0);
-		case 'E':
-			opt_errors = 1;
-			break;
-		case 'e':
-			opt_edition = atoi(optarg);
-			break;
-		case 'i':
-			opt_image = optarg;
-			if (lstat(opt_image, &st) < 0) {
-				perror(opt_image);
-				exit(16);
-			}
-			image_length = st.st_size; /* may be padded later */
-			fslen_ub += (image_length + 3); /* 3 is for padding */
-			break;
-		case 'n':
-			opt_name = optarg;
-			break;
-		case 'p':
-			opt_pad = PAD_SIZE;
-			fslen_ub += PAD_SIZE;
-			break;
-		case 's':
-			/* old option, ignored */
-			break;
-		case 'z':
-			opt_holes = 1;
-			break;
-		}
-	}
-
-	if ((argc - optind) != 2)
-		usage(16);
-	dirname = argv[optind];
-	outfile = argv[optind + 1];
-
-	if (stat(dirname, &st) < 0) {
-		perror(dirname);
-		exit(16);
-	}
-	fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-
-	root_entry = calloc(1, sizeof(struct entry));
-	if (!root_entry) {
-		perror(NULL);
-		exit(8);
-	}
-	root_entry->mode = st.st_mode;
-	root_entry->uid = st.st_uid;
-	root_entry->gid = st.st_gid;
-
-	root_entry->size = parse_directory(root_entry, dirname, &root_entry->child, &fslen_ub);
-
-	/* always allocate a multiple of blksize bytes because that's
-           what we're going to write later on */
-	fslen_ub = ((fslen_ub - 1) | (blksize - 1)) + 1;
-
-	if (fslen_ub > MAXFSLEN) {
-		fprintf(stderr,
-			"warning: guestimate of required size (upper bound) is %LdMB, but maximum image size is %uMB.  We might die prematurely.\n",
-			fslen_ub >> 20,
-			MAXFSLEN >> 20);
-		fslen_ub = MAXFSLEN;
-	}
-
-        /* find duplicate files. TODO: uses the most inefficient algorithm
-           possible. */
-        eliminate_doubles(root_entry,root_entry);
-
-	/* TODO: Why do we use a private/anonymous mapping here
-           followed by a write below, instead of just a shared mapping
-           and a couple of ftruncate calls?  Is it just to save us
-           having to deal with removing the file afterwards?  If we
-           really need this huge anonymous mapping, we ought to mmap
-           in smaller chunks, so that the user doesn't need nn MB of
-           RAM free.  If the reason is to be able to write to
-           un-mmappable block devices, then we could try shared mmap
-           and revert to anonymous mmap if the shared mmap fails. */
-	rom_image = mmap(NULL, fslen_ub?fslen_ub:1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-
-	if (-1 == (int) (long) rom_image) {
-		perror("ROM image map");
-		exit(8);
-	}
-
-	/* Skip the first opt_pad bytes for boot loader code */
-	offset = opt_pad;
-	memset(rom_image, 0x00, opt_pad);
-
-	/* Skip the superblock and come back to write it later. */
-	offset += sizeof(struct cramfs_super);
-
-	/* Insert a file image. */
-	if (opt_image) {
-		printf("Including: %s\n", opt_image);
-		offset = write_file(opt_image, rom_image, offset);
-	}
-
-	offset = write_directory_structure(root_entry->child, rom_image, offset);
-	printf("Directory data: %d bytes\n", offset);
-
-	offset = write_data(root_entry, rom_image, offset);
-
-	/* We always write a multiple of blksize bytes, so that
-           losetup works. */
-	offset = ((offset - 1) | (blksize - 1)) + 1;
-	printf("Everything: %d kilobytes\n", offset >> 10);
-
-	/* Write the superblock now that we can fill in all of the fields. */
-	write_superblock(root_entry, rom_image+opt_pad, offset);
-	printf("Super block: %d bytes\n", sizeof(struct cramfs_super));
-
-	/* Put the checksum in. */
-	crc = crc32(crc, (rom_image+opt_pad), (offset-opt_pad));
-	((struct cramfs_super *) (rom_image+opt_pad))->fsid.crc = crc;
-	printf("CRC: %x\n", crc);
-
-	/* Check to make sure we allocated enough space. */
-	if (fslen_ub < offset) {
-		fprintf(stderr, "not enough space allocated for ROM image (%Ld allocated, %d used)\n",
-			fslen_ub, offset);
-		exit(8);
-	}
-
-	written = write(fd, rom_image, offset);
-	if (written < 0) {
-		perror("ROM image");
-		exit(8);
-	}
-	if (offset != written) {
-		fprintf(stderr, "ROM image write failed (%d %d)\n", written, offset);
-		exit(8);
-	}
-
-	/* (These warnings used to come at the start, but they scroll off the
-           screen too quickly.) */
-	if (warn_namelen) /* (can't happen when reading from ext2fs) */
-		fprintf(stderr, /* bytes, not chars: think UTF8. */
-			"warning: filenames truncated to 255 bytes.\n");
-	if (warn_skip)
-		fprintf(stderr, "warning: files were skipped due to errors.\n");
-	if (warn_size)
-		fprintf(stderr,
-			"warning: file sizes truncated to %luMB (minus 1 byte).\n",
-			1L << (CRAMFS_SIZE_WIDTH - 20));
-	if (warn_uid) /* (not possible with current Linux versions) */
-		fprintf(stderr,
-			"warning: uids truncated to %u bits.  (This may be a security concern.)\n",
-			CRAMFS_UID_WIDTH);
-	if (warn_gid)
-		fprintf(stderr,
-			"warning: gids truncated to %u bits.  (This may be a security concern.)\n",
-			CRAMFS_GID_WIDTH);
-	if (warn_dev)
-		fprintf(stderr,
-			"WARNING: device numbers truncated to %u bits.  This almost certainly means\n"
-			"that some device files will be wrong.\n",
-			CRAMFS_OFFSET_WIDTH);
-	if (opt_errors &&
-	    (warn_namelen||warn_skip||warn_size||warn_uid||warn_gid||warn_dev))
-		exit(8);
-	return 0;
-}
